本文整理汇总了Python中factories.BlogpostFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python BlogpostFactory.create方法的具体用法?Python BlogpostFactory.create怎么用?Python BlogpostFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类factories.BlogpostFactory
的用法示例。
在下文中一共展示了BlogpostFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_delete_blogpost
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_delete_blogpost(self, mock_delete):
"""Test API Blogpost delete post (DEL)."""
mock_delete.return_value = True
admin = UserFactory.create()
owner = UserFactory.create()
user = UserFactory.create()
project = ProjectFactory.create(owner=owner)
blogpost = BlogpostFactory.create(project=project)
blogpost2 = BlogpostFactory.create(project=project)
# As anon
url = '/api/blogpost/%s' % blogpost.id
res = self.app.delete(url)
data = json.loads(res.data)
assert res.status_code == 401, res.status_code
# As user
url = '/api/blogpost/%s?api_key=%s' % (blogpost.id, user.api_key)
res = self.app.delete(url)
assert res.status_code == 403, res.status_code
# As owner
url = '/api/blogpost/%s?api_key=%s' % (blogpost.id, owner.api_key)
res = self.app.delete(url)
assert res.status_code == 204, res.status_code
assert mock_delete.called_with(blogpost.info['file_name'],
blogpost.info['container'])
# As admin
url = '/api/blogpost/%s?api_key=%s' % (blogpost2.id, admin.api_key)
res = self.app.delete(url)
assert res.status_code == 204, res.status_code
示例2: test_blogposts_get_all
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_blogposts_get_all(self):
"""Test blogpost GET all blogposts"""
user = self.create_users()[1]
project = ProjectFactory.create(owner=user)
blogpost_1 = BlogpostFactory.create(owner=user, project=project,
title='titleone', published=True)
blogpost_2 = BlogpostFactory.create(owner=user, project=project,
title='titletwo',
published=True)
blogpost_3 = BlogpostFactory.create(owner=user, project=project,
title='titlethree',
published=False)
url = "/project/%s/blog" % project.short_name
# As anonymous
res = self.app.get(url, follow_redirects=True)
assert res.status_code == 200, res.status_code
assert 'titleone' in res.data
assert 'titletwo' in res.data
# As authenticated
self.register()
res = self.app.get(url, follow_redirects=True)
assert res.status_code == 200, res.status_code
assert 'titleone' in res.data
assert 'titletwo' in res.data
assert 'titlethree' not in res.data
示例3: test_get_by_returns_none_if_no_blogpost
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_get_by_returns_none_if_no_blogpost(self):
"""Test get_by returns None if no blogpost matches the query"""
BlogpostFactory.create(title='My blog', body='myblogpost')
blogpost = self.blog_repo.get_by(title='notitle')
assert blogpost is None, blogpost
示例4: test_filter_by_no_matches
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_filter_by_no_matches(self):
"""Test filter_by returns an empty list if no blogposts match the query"""
BlogpostFactory.create(title='My blog', body='myblogpost')
retrieved_blogposts = self.blog_repo.filter_by(title='no title')
assert isinstance(retrieved_blogposts, list)
assert len(retrieved_blogposts) == 0, retrieved_blogposts
示例5: test_json_blogposts_get_all
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_json_blogposts_get_all(self):
"""Test JSON blogpost GET all blogposts"""
user = self.create_users()[1]
project = ProjectFactory.create(owner=user)
blogpost_1 = BlogpostFactory.create(owner=user, project=project,
title='titleone', published=True)
blogpost_2 = BlogpostFactory.create(owner=user, project=project,
title='titletwo', published=True)
blogpost_3 = BlogpostFactory.create(owner=user, project=project,
title='titlethree', published=False)
url = "/project/%s/blog" % project.short_name
# As anonymous
res = self.app_get_json(url)
assert res.status_code == 200, res.status_code
data = json.loads(res.data)
assert 'api_key' not in data['owner'].keys()
assert 'email_addr' not in data['owner'].keys()
assert 'google_user_id' not in data['owner'].keys()
assert 'facebook_user_id' not in data['owner'].keys()
assert 'twitter_user_id' not in data['owner'].keys()
assert len(data['blogposts']) == 2
for blogpost in data['blogposts']:
assert blogpost['title'] in ['titleone', 'titletwo']
# As authenticated
self.register()
res = self.app_get_json(url, follow_redirects=True)
assert res.status_code == 200, res.status_code
data = json.loads(res.data)
assert 'api_key' not in data['owner'].keys()
assert 'email_addr' not in data['owner'].keys()
assert 'google_user_id' not in data['owner'].keys()
assert 'facebook_user_id' not in data['owner'].keys()
assert 'twitter_user_id' not in data['owner'].keys()
assert len(data['blogposts']) == 2
for blogpost in data['blogposts']:
assert blogpost['title'] in ['titleone', 'titletwo']
self.signout()
# As owner
self.signin(email=user.email_addr, password=self.password)
res = self.app_get_json(url, follow_redirects=True)
assert res.status_code == 200, res.status_code
data = json.loads(res.data)
assert 'api_key' in data['owner'].keys()
assert 'email_addr' in data['owner'].keys()
assert 'google_user_id' in data['owner'].keys()
assert 'facebook_user_id' in data['owner'].keys()
assert 'twitter_user_id' in data['owner'].keys()
assert len(data['blogposts']) == 3
for blogpost in data['blogposts']:
assert blogpost['title'] in ['titleone', 'titletwo', 'titlethree']
self.signout()
示例6: test_filter_by_multiple_conditions
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_filter_by_multiple_conditions(self):
"""Test filter_by supports multiple-condition queries"""
BlogpostFactory.create(title='my blogpost', body='body')
blogpost = BlogpostFactory.create(title='my blogpost', body='other body')
retrieved_blogposts = self.blog_repo.filter_by(title='my blogpost',
body='other body')
assert len(retrieved_blogposts) == 1, retrieved_blogposts
assert blogpost in retrieved_blogposts, retrieved_blogposts
示例7: test_anonymous_user_read_given_blogpost_hidden_app
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_anonymous_user_read_given_blogpost_hidden_app(self):
"""Test anonymous users cannot read a given blogpost of a hidden project"""
app = AppFactory.create(hidden=1)
blogpost = BlogpostFactory.create(app=app)
assert_raises(Unauthorized, getattr(require, 'blogpost').read, blogpost)
示例8: test_anonymous_user_read_given_blogpost
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_anonymous_user_read_given_blogpost(self):
"""Test anonymous users can read a given blogpost"""
app = AppFactory.create()
blogpost = BlogpostFactory.create(app=app)
assert_not_raises(Exception, getattr(require, 'blogpost').read, blogpost)
示例9: test_anonymous_user_read_given_blogpost_draft_project
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_anonymous_user_read_given_blogpost_draft_project(self):
"""Test anonymous users cannot read a given blogpost of a draft project"""
project = ProjectFactory.create(published=False)
blogpost = BlogpostFactory.create(project=project)
assert_raises(Unauthorized, ensure_authorized_to, 'read', blogpost)
示例10: test_anonymous_user_read_given_blogpost
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_anonymous_user_read_given_blogpost(self):
"""Test anonymous users can read a given blogpost"""
project = ProjectFactory.create(published=True)
blogpost = BlogpostFactory.create(project=project)
assert_not_raises(Exception, ensure_authorized_to, 'read', blogpost)
示例11: test_anonymous_user_read_given_blogpost_hidden_project
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_anonymous_user_read_given_blogpost_hidden_project(self):
"""Test anonymous users cannot read a given blogpost of a hidden project"""
project = ProjectFactory.create(hidden=1)
blogpost = BlogpostFactory.create(project=project)
assert_raises(Unauthorized, ensure_authorized_to, 'read', blogpost)
示例12: test_anonymous_user_delete_blogpost
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_anonymous_user_delete_blogpost(self):
"""Test anonymous users cannot delete blogposts"""
with self.flask_app.test_request_context('/'):
blogpost = BlogpostFactory.create()
assert_raises(Unauthorized, getattr(require, 'blogpost').delete, blogpost)
示例13: test_blogpost_update_errors
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_blogpost_update_errors(self):
"""Test blogposts update for non existing apps raises errors"""
self.register()
user = db.session.query(User).get(1)
app1 = AppFactory.create(owner=user)
app2 = AppFactory.create(owner=user)
blogpost = BlogpostFactory.create(owner=user, app=app1, body='body')
# To a non-existing app
url = "/app/non-existing-app/%s/update" % blogpost.id
res = self.app.post(url, data={'title':'new title', 'body':'body'},
follow_redirects=True)
assert res.status_code == 404, res.status_code
# To a non-existing post
url = "/app/%s/999999/update" % app1.short_name
res = self.app.post(url, data={'title':'new title', 'body':'body'},
follow_redirects=True)
assert res.status_code == 404, res.status_code
# To an existing post but with a project in the URL it does not belong to
url = "/app/%s/%s/update" % (app2.short_name, blogpost.id)
res = self.app.post(url, data={'title':'new title', 'body':'body'},
follow_redirects=True)
assert res.status_code == 404, res.status_code
示例14: test_endpoints_with_password_protection
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_endpoints_with_password_protection(self):
"""Test all the endpoints for "reading" a project use password protection """
endpoints_requiring_password = (
'/', '/tutorial', '/1/results.json',
'/tasks/', '/tasks/browse', '/tasks/export',
'/stats', '/blog', '/1', '/task/1')
project = ProjectFactory.create()
TaskFactory.create(project=project)
BlogpostFactory.create(project=project)
project.set_password('mysecret')
project_repo.update(project)
for endpoint in endpoints_requiring_password:
res = self.app.get('/project/%s%s' % (project.short_name, endpoint),
follow_redirects=True)
assert 'Enter the password to contribute' in res.data, endpoint
示例15: test_blogpost_update_errors
# 需要导入模块: from factories import BlogpostFactory [as 别名]
# 或者: from factories.BlogpostFactory import create [as 别名]
def test_blogpost_update_errors(self):
"""Test blogposts update for non existing projects raises errors"""
self.register()
user = user_repo.get(1)
project1 = ProjectFactory.create(owner=user)
project2 = ProjectFactory.create(owner=user)
blogpost = BlogpostFactory.create(project=project1, body='body')
# To a non-existing project
url = "/project/non-existing-project/%s/update" % blogpost.id
res = self.app.post(url, data={'title':'new title', 'body':'body'},
follow_redirects=True)
assert res.status_code == 404, res.status_code
# To a non-existing post
url = "/project/%s/999999/update" % project1.short_name
res = self.app.post(url, data={'title':'new title', 'body':'body'},
follow_redirects=True)
assert res.status_code == 404, res.status_code
# To an existing post but with a project in the URL it does not belong to
url = "/project/%s/%s/update" % (project2.short_name, blogpost.id)
res = self.app.post(url, data={'title':'new title', 'body':'body'},
follow_redirects=True)
assert res.status_code == 404, res.status_code