本文整理汇总了Python中geokey.projects.tests.model_factories.UserFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python UserFactory.create方法的具体用法?Python UserFactory.create怎么用?Python UserFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geokey.projects.tests.model_factories.UserFactory
的用法示例。
在下文中一共展示了UserFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def setUp(self):
self.factory = APIRequestFactory()
self.admin = UserFactory.create()
self.contributor = UserFactory.create()
self.non_member = UserFactory.create()
self.project = ProjectFactory(
add_admins=[self.admin],
add_contributors=[self.contributor]
)
self.other_project = ProjectFactory.create()
# Create 20 locations, 10 should be accessible for the project
for x in range(0, 5):
LocationFactory()
LocationFactory(**{
'private': True,
'private_for_project': self.other_project
})
LocationFactory(**{
'private': True,
'private_for_project': self.project
})
LocationFactory(**{
'private': True
})
示例2: setUp
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def setUp(self):
self.contributor = UserFactory.create()
self.admin = UserFactory.create()
self.non_member = UserFactory.create()
self.project = ProjectFactory(
add_admins=[self.admin],
add_contributors=[self.contributor]
)
self.contribution = ObservationFactory.create(**{
'project': self.project,
'creator': self.contributor
})
comment = CommentFactory.create(**{
'commentto': self.contribution
})
response = CommentFactory.create(**{
'commentto': self.contribution,
'respondsto': comment
})
CommentFactory.create(**{
'commentto': self.contribution,
'respondsto': response
})
CommentFactory.create(**{
'commentto': self.contribution,
'respondsto': comment
})
CommentFactory.create(**{
'commentto': self.contribution
})
示例3: post
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def post(self, user, data=None):
if user.is_anonymous and not User.objects.filter(
display_name='AnonymousUser').exists():
UserFactory.create(display_name='AnonymousUser')
if data is None:
data = {
'name': 'A test image',
'description': 'Test image description',
'file': get_image()
}
url = reverse(
'api:project_media',
kwargs={
'project_id': self.project.id,
'contribution_id': self.contribution.id
}
)
request = self.factory.post(url, data)
force_authenticate(request, user)
view = AllContributionsMediaAPIView.as_view()
return view(
request,
project_id=self.project.id,
contribution_id=self.contribution.id
).render()
示例4: setUp
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def setUp(self):
"""Set up test."""
self.superuser = UserFactory.create(**{'is_superuser': True})
self.admin = UserFactory.create(**{'is_superuser': False})
self.contributor = UserFactory.create(**{'is_superuser': False})
self.regular_user = UserFactory.create(**{'is_superuser': False})
self.project = ProjectFactory.create(
add_admins=[self.admin],
add_contributors=[self.contributor],
**{'isprivate': True})
示例5: get_response
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def get_response(self, user):
if user.is_anonymous and not User.objects.filter(display_name="AnonymousUser").exists():
UserFactory.create(display_name="AnonymousUser")
factory = APIRequestFactory()
request = factory.post(
"/api/projects/%s/maps/all-contributions/%s/comments/" % (self.project.id, self.contribution.id),
{"text": "A comment to the contribution."},
)
force_authenticate(request, user=user)
view = CommentsAPIView.as_view()
return view(request, project_id=self.project.id, contribution_id=self.contribution.id).render()
示例6: test_get_isowner
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def test_get_isowner(self):
user = UserFactory.create()
comment = CommentFactory.create(**{'creator': user})
serializer = CommentSerializer(comment, context={'user': user})
self.assertTrue(serializer.get_isowner(comment))
serializer = CommentSerializer(
comment, context={'user': UserFactory.create()})
self.assertFalse(serializer.get_isowner(comment))
serializer = CommentSerializer(
comment, context={'user': AnonymousUser()})
self.assertFalse(serializer.get_isowner(comment))
示例7: setUp
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def setUp(self):
self.user1 = UserFactory.create()
self.user2 = UserFactory.create()
self.app1 = ApplicationFactory(**{
'user': self.user1
})
self.app2 = ApplicationFactory(**{
'user': self.user1
})
self.app3 = ApplicationFactory(**{
'user': self.user2
})
self.deleted_app = ApplicationFactory(**{
'user': self.user1,
'status': 'deleted'
})
示例8: test
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def test(self):
admin = UserFactory.create()
project = ProjectFactory(add_admins=[admin])
observation = ObservationFactory.create(**{
'project': project
})
comment = CommentFactory.create(**{
'commentto': observation
})
factory = APIRequestFactory()
request = factory.post(
'/api/projects/%s/observations/%s/comments/' %
(project.id, observation.id),
{
'text': 'Response to a comment',
'respondsto': comment.id
}
)
force_authenticate(request, user=admin)
view = AllContributionsCommentsAPIView.as_view()
response = view(
request,
project_id=project.id,
observation_id=observation.id
).render()
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
self.assertEqual(
json.loads(response.content).get('respondsto'),
comment.id
)
示例9: test_get_with_unconnected_user
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def test_get_with_unconnected_user(self):
view = ApplicationDisconnect.as_view()
url = reverse('admin:app_disconnect', kwargs={'app_id': self.app.id})
request = APIRequestFactory().get(url)
request.user = UserFactory.create()
response = view(request, app_id=self.app.id)
self.assertTrue(isinstance(response, HttpResponseRedirect))
示例10: test_post_with_user
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def test_post_with_user(self):
data = {
'name': 'test app',
'description': '',
'download_url': 'http://example.com/download',
'redirect_uris': 'http://example.com/redirect',
'authorization_grant_type': 'password'
}
view = ApplicationSettings.as_view()
url = reverse('admin:app_settings', kwargs={'app_id': self.app.id})
request = APIRequestFactory().post(url, data)
request.user = UserFactory.create()
response = view(request, app_id=self.app.id).render()
self.assertEqual(response.status_code, 200)
self.assertContains(
response,
'You are not the owner of this application and therefore not '
'allowed to access this app.'
)
ref = Application.objects.get(pk=self.app.id)
self.assertNotEqual(ref.name, data.get('name'))
self.assertNotEqual(ref.description, data.get('description'))
self.assertNotEqual(ref.download_url, data.get('download_url'))
self.assertNotEqual(ref.redirect_uris, data.get('redirect_uris'))
self.assertNotEqual(
ref.authorization_grant_type,
data.get('authorization_grant_type')
)
示例11: test
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def test(self):
admin = UserFactory.create()
project = ProjectFactory(add_admins=[admin])
contribution = ObservationFactory.create(**{
'project': project
})
comment = CommentFactory.create()
factory = APIRequestFactory()
request = factory.post(
'/api/projects/%s/contributions/%s/comments/' %
(project.id, contribution.id),
{
'text': 'Response to a comment',
'respondsto': comment.id
}
)
force_authenticate(request, user=admin)
view = CommentsAPIView.as_view()
response = view(
request,
project_id=project.id,
contribution_id=contribution.id
).render()
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(
json.loads(response.content).get('error'),
'The comment you try to respond to is not a comment to the '
'contribution.'
)
示例12: test_get_with_user
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def test_get_with_user(self):
view = ApplicationOverview.as_view()
url = reverse('admin:app_overview')
request = APIRequestFactory().get(url)
request.user = UserFactory.create()
response = view(request).render()
self.assertEqual(response.status_code, 200)
示例13: test_get_contribution_with_some_dude
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def test_get_contribution_with_some_dude(self):
some_dude = UserFactory.create()
view = SingleCommentAPIView()
view.get_contribution(
some_dude,
self.project.id,
self.contribution.id
)
示例14: get_response
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def get_response(self, user):
if user.is_anonymous and not User.objects.filter(
display_name='AnonymousUser').exists():
UserFactory.create(display_name='AnonymousUser')
factory = APIRequestFactory()
request = factory.post(
'/api/projects/%s/maps/all-contributions/%s/comments/' %
(self.project.id, self.observation.id),
{'text': 'A comment to the observation'}
)
force_authenticate(request, user=user)
view = AllContributionsCommentsAPIView.as_view()
return view(
request,
project_id=self.project.id,
observation_id=self.observation.id
).render()
示例15: test_for_viewer
# 需要导入模块: from geokey.projects.tests.model_factories import UserFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.UserFactory import create [as 别名]
def test_for_viewer(self):
observations = Observation.objects.all().for_viewer(
UserFactory.create())
self.assertEqual(len(observations), 5)
for observation in observations:
self.assertNotIn(
observation.status,
['draft', 'pending', 'deleted']
)