本文整理汇总了Python中geokey.users.tests.model_factories.UserF类的典型用法代码示例。如果您正苦于以下问题:Python UserF类的具体用法?Python UserF怎么用?Python UserF使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserF类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
self.factory = APIRequestFactory()
self.admin = UserF.create()
self.contributor = UserF.create()
self.non_member = UserF.create()
self.public_project = ProjectF.create(
add_admins=[self.admin],
add_contributors=[self.contributor],
**{
'isprivate': False
}
)
self.private_project = ProjectF.create(
add_admins=[self.admin],
add_contributors=[self.contributor]
)
self.inactive_project = ProjectF.create(
add_admins=[self.admin],
add_contributors=[self.contributor],
**{
'status': 'inactive'
}
)
self.deleted_project = ProjectF.create(
add_admins=[self.admin],
add_contributors=[self.contributor],
**{'isprivate': False}
)
self.deleted_project.delete()
示例2: test
def test(self):
admin = UserF.create()
project = ProjectF.create(add_admins=[admin])
category_1 = CategoryFactory(**{'project': project})
TextFieldFactory(**{
'key': 'text',
'category': category_1
})
category_2 = CategoryFactory(**{'project': project})
TextFieldFactory(**{
'key': 'bla',
'category': category_2
})
ObservationFactory.create_batch(5, **{
'project': project,
'category': category_1,
'properties': {'text': 'yes'}}
)
viewer = UserF.create()
view = GroupingFactory(add_viewers=[viewer], **{'project': project})
RuleFactory(**{
'grouping': view,
'category': category_1,
'constraints': {'text': 'yes'}
})
serializer = GroupingSerializer(view, context={'user': admin})
self.assertEqual(len(serializer.get_data(view).get('features')), 5)
self.assertEqual(serializer.get_num_contributions(view), 5)
示例3: test_post_image_file_save
def test_post_image_file_save(self):
observation = ObservationFactory()
video_file = VideoFile.objects.create(
name='Test name',
description='Test Description',
contribution=observation,
creator=UserF.create(),
video=get_image(),
youtube_link='http://example.com/1122323',
swf_link='http://example.com/1122323.swf'
)
VideoFile.objects.create(
status='deleted',
name='Test name',
description='Test Description',
contribution=observation,
creator=UserF.create(),
video=get_image(),
youtube_link='http://example.com/1122323',
swf_link='http://example.com/1122323.swf'
)
post_save_media_file_update(VideoFile, instance=video_file)
self.assertEqual(video_file.contribution.num_media, 1)
self.assertEqual(video_file.contribution.num_comments, 0)
示例4: test_with_inactive_project
def test_with_inactive_project(self):
admin = UserF.create()
email_user = UserF.create()
project = ProjectF.create(
add_admins=[admin],
**{'status': 'inactive'}
)
view = ProjectContactAdmins.as_view()
url = reverse(
'api:project_contact_admins',
kwargs={
'project_id': project.id
}
)
request = APIRequestFactory().post(
url,
json.dumps({'email_text': 'Blah Blah'}),
content_type='application/json'
)
force_authenticate(request, user=email_user)
response = view(request, project_id=project.id).render()
self.assertEqual(response.status_code, 404)
self.assertEquals(len(mail.outbox), 0)
示例5: test_all_contacts
def test_all_contacts(self):
admin = UserF.create()
contributor = UserF.create()
email_user = UserF.create()
project = ProjectF.create(
add_admins=[admin],
add_contributors=[contributor]
)
project.contact_admins(email_user, 'Test email')
# Should be 2 because project creator is admin too
self.assertEquals(len(mail.outbox), 2)
示例6: test_post_with_user
def test_post_with_user(self):
factory = APIRequestFactory()
user = UserF.create(**{'is_superuser': False})
user_to_add = UserF.create(**{'is_superuser': False})
request = factory.post(
reverse('ajax:superusers_adduser'),
{'userId': user_to_add.id}
)
force_authenticate(request, user=user)
view = AddSuperUsersAjaxView.as_view()
response = view(request).render()
self.assertEqual(response.status_code, 403)
self.assertEqual(len(User.objects.filter(is_superuser=True)), 0)
示例7: test_get_data_text_filter
def test_get_data_text_filter(self):
admin = UserF.create()
project = ProjectF.create(add_admins=[admin])
category_1 = CategoryFactory(**{'project': project})
TextFieldFactory(**{
'key': 'text',
'category': category_1
})
category_2 = CategoryFactory(**{'project': project})
TextFieldFactory(**{
'key': 'bla',
'category': category_2
})
for x in range(0, 5):
ObservationFactory.create(**{
'project': project,
'category': category_1,
'properties': {'text': 'yes ' + str(x)}}
)
ObservationFactory.create(**{
'project': project,
'category': category_1,
'status': 'pending',
'properties': {'text': 'yes ' + str(x)}}
)
ObservationFactory.create(**{
'project': project,
'category': category_1,
'properties': {'text': 'no ' + str(x)}}
)
ObservationFactory.create(**{
'project': project,
'category': category_2,
'properties': {'bla': 'yes ' + str(x)}}
)
viewer = UserF.create()
view = GroupingFactory(add_viewers=[viewer], **{'project': project})
RuleFactory(**{
'grouping': view,
'category': category_1,
'constraints': {'text': 'yes'}
})
self.assertEqual(view.data(admin).count(), 10)
self.assertEqual(view.data(viewer).count(), 5)
示例8: test_delete_with_user
def test_delete_with_user(self):
factory = APIRequestFactory()
user = UserF.create(**{'is_superuser': False})
user_to_remove = UserF.create(**{'is_superuser': True})
request = factory.delete(
reverse('ajax:superusers_deleteuser', kwargs={
'user_id': user_to_remove.id
})
)
force_authenticate(request, user=user)
view = DeleteSuperUsersAjaxView.as_view()
response = view(request, user_id=user_to_remove.id).render()
self.assertEqual(response.status_code, 403)
self.assertEqual(len(User.objects.filter(is_superuser=True)), 1)
示例9: test_get_role
def test_get_role(self):
admin = UserF.create()
moderator = UserF.create()
contributor = UserF.create()
other = UserF.create()
project = ProjectF.create(
add_admins=[admin],
add_moderators=[moderator],
add_contributors=[contributor]
)
self.assertEqual('administrator', project.get_role(admin))
self.assertEqual('moderator', project.get_role(moderator))
self.assertEqual('contributor', project.get_role(contributor))
self.assertEqual('watcher', project.get_role(other))
示例10: test_get_data_with_none_rule
def test_get_data_with_none_rule(self):
user = UserF.create()
project = ProjectF.create()
category_1 = CategoryFactory(**{'project': project})
category_2 = CategoryFactory(**{'project': project})
category_3 = CategoryFactory(**{'project': project})
UserGroupF.create(
add_users=[user],
**{'project': project, 'filters': None}
)
ObservationFactory.create_batch(5, **{
'project': project,
'category': category_1}
)
ObservationFactory.create_batch(5, **{
'project': project,
'category': category_2}
)
ObservationFactory.create_batch(5, **{
'project': project,
'category': category_3}
)
self.assertEqual(project.get_all_contributions(user).count(), 15)
示例11: test_post_with_user
def test_post_with_user(self):
"""
Posting with normal user should render with an error message and not
update the filter
"""
subset = SubsetFactory.create()
user = UserF.create()
category = CategoryFactory.create(**{'project': subset.project})
self.request.user = user
self.request.method = 'POST'
self.request.POST = {
'filters': '{ "%s": { } }' % category.id
}
response = self.view(
self.request,
project_id=subset.project.id,
subset_id=subset.id).render()
reference_subset = Subset.objects.get(pk=subset.id)
self.assertIsNone(reference_subset.filters)
rendered = render_to_string(
'subsets/subsets_data.html',
{
'error_description': 'Project matching query does not exist.',
'error': 'Not found.',
'user': user,
'PLATFORM_NAME': get_current_site(self.request).name,
'GEOKEY_VERSION': version.get_version()
}
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content.decode('utf-8'), rendered)
示例12: test_get_with_user
def test_get_with_user(self):
"""
Accessing the view with normal user should render the page with an
error message
"""
subset = SubsetFactory.create()
user = UserF.create()
self.request.user = user
response = self.view(
self.request,
project_id=subset.project.id,
subset_id=subset.id).render()
rendered = render_to_string(
'base.html',
{
'error_description': 'Project matching query does not exist.',
'error': 'Not found.',
'user': user,
'PLATFORM_NAME': get_current_site(self.request).name,
'GEOKEY_VERSION': version.get_version()
}
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content.decode('utf-8'), rendered)
self.assertEqual(Subset.objects.count(), 1)
示例13: test_get_with_superuser
def test_get_with_superuser(self):
view = PlatformSettings.as_view()
url = reverse('admin:superuser_index')
request = APIRequestFactory().get(url)
request.user = UserF.create(**{'is_superuser': True})
response = view(request).render()
self.assertEqual(response.status_code, 200)
示例14: test_post_with_superuser
def test_post_with_superuser(self):
user = UserF.create(**{'is_superuser': True})
self.create_inactive()
self.request.POST = QueryDict(
'activate_users=%s&activate_users=%s' % (
self.inactive_1.id, self.inactive_2.id))
self.request.method = 'POST'
self.request.user = user
response = self.view(self.request).render()
rendered = render_to_string(
'superusertools/manage_inactiveusers.html',
{
'inactive_users': [self.inactive_3],
'user': user,
'PLATFORM_NAME': get_current_site(self.request).name,
'GEOKEY_VERSION': version.get_version(),
'messages': get_messages(self.request)
}
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content.decode('utf-8'), rendered)
self.assertEqual(
User.objects.filter(is_active=False).count(), 1
)
self.assertEqual(
EmailAddress.objects.filter(verified=False).count(), 1
)
示例15: test_get_context_data
def test_get_context_data(self):
user = UserF.create(**{'is_superuser': True})
ProjectF.create_batch(5, add_admins=[user])
ProjectF.create_batch(5)
view = ProjectsList()
context = view.get_context_data()
self.assertEqual(len(context.get('projects')), 10)