本文整理汇总了Python中geokey.projects.tests.model_factories.ProjectF.create方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectF.create方法的具体用法?Python ProjectF.create怎么用?Python ProjectF.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geokey.projects.tests.model_factories.ProjectF
的用法示例。
在下文中一共展示了ProjectF.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_with_admin
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_post_with_admin(self):
user = UserF.create()
project_1 = ProjectF.create(**{'creator': user})
project_2 = ProjectF.create(**{'creator': user})
data = {
str(project_1.id): 'on'
}
view = UserNotifications.as_view()
url = reverse('admin:notifications')
request = APIRequestFactory().post(url, data)
request.user = user
from django.contrib.messages.storage.fallback import FallbackStorage
setattr(request, 'session', 'session')
messages = FallbackStorage(request)
setattr(request, '_messages', messages)
response = view(request).render()
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertTrue(
Admins.objects.get(project=project_1, user=user).contact
)
self.assertFalse(
Admins.objects.get(project=project_2, user=user).contact
)
示例2: setUp
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def setUp(self):
self.creator = UserF.create()
self.admin = UserF.create()
self.view_member = UserF.create()
self.contributor = UserF.create()
ProjectF.create(
add_admins=[self.admin],
add_contributors=[self.contributor]
)
ProjectF.create(
add_admins=[self.admin, self.contributor]
)
示例3: test_post_non_existing_with_admin
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_post_non_existing_with_admin(self):
"""
Update the view with project admin should render an error message
"""
project = ProjectF.create()
user = project.creator
self.request.user = user
self.request.method = 'POST'
self.request.POST = {
'name': 'Name',
'description': 'Description',
}
response = self.view(
self.request,
project_id=project.id,
subset_id=634842156456).render()
rendered = render_to_string(
'subsets/subsets_settings.html',
{
'error_description': 'Subset 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)
示例4: test_post_with_admin
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_post_with_admin(self):
"""
Updating with project admin should create the subset and redirect to
the subset data page.
"""
self.request.method = 'POST'
self.request.POST = {
'name': 'Name',
'description': 'Description',
}
project = ProjectF.create()
user = project.creator
self.request.user = user
response = self.view(self.request, project_id=project.id)
self.assertEqual(1, Subset.objects.count())
subset = Subset.objects.first()
self.assertEqual(subset.name, 'Name')
self.assertEqual(subset.description, 'Description')
self.assertEqual(subset.project, project)
self.assertEqual(subset.creator, user)
self.assertEqual(response.status_code, 302)
self.assertIn(
'/admin/projects/%s/subsets/%s/' % (project.id, subset.id),
response['location']
)
示例5: test_post_with_user
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_post_with_user(self):
"""
Updating with normal user should render the page with an
error message
"""
self.request.method = 'POST'
self.request.POST = {
'name': 'Name',
'description': 'Description',
}
user = UserF.create()
project = ProjectF.create()
self.request.user = user
response = self.view(self.request, project_id=project.id).render()
rendered = render_to_string(
'subsets/subsets_create.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(0, Subset.objects.count())
示例6: test_post_with_admin_no_rules
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_post_with_admin_no_rules(self):
view = RuleSettings.as_view()
project = ProjectF.create()
category = CategoryFactory.create(**{'project': project})
grouping = GroupingFactory.create(**{'project': project})
rule = RuleFactory.create(**{'grouping': grouping})
data = {
'category': category.id
}
url = reverse(
'admin:rule_settings',
kwargs={
'project_id': project.id,
'grouping_id': grouping.id,
'rule_id': rule.id
}
)
request = APIRequestFactory().post(url, data)
request.user = project.creator
from django.contrib.messages.storage.fallback import FallbackStorage
setattr(request, 'session', 'session')
messages = FallbackStorage(request)
setattr(request, '_messages', messages)
response = view(
request,
project_id=project.id,
grouping_id=grouping.id,
rule_id=rule.id)
self.assertEqual(response.status_code, 302)
示例7: test_post_with_admin
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_post_with_admin(self):
data = {
'name': 'Grouping',
'description': ''
}
view = GroupingSettings.as_view()
project = ProjectF.create()
grouping = GroupingFactory.create(**{'project': project})
url = reverse(
'admin:grouping_settings',
kwargs={'project_id': project.id, 'grouping_id': grouping.id}
)
request = APIRequestFactory().post(url, data)
request.user = project.creator
from django.contrib.messages.storage.fallback import FallbackStorage
setattr(request, 'session', 'session')
messages = FallbackStorage(request)
setattr(request, '_messages', messages)
response = view(
request,
project_id=project.id,
grouping_id=grouping.id)
self.assertEqual(response.status_code, 200)
示例8: setUp
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def setUp(self):
self.factory = APIRequestFactory()
self.admin = UserF.create()
self.contributor = UserF.create()
self.view_member = UserF.create()
self.non_member = UserF.create()
self.project = ProjectF(
add_admins=[self.admin],
add_contributors=[self.contributor],
add_viewers=[self.view_member]
)
self.other_project = ProjectF.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
})
示例9: test_delete_with_user
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_delete_with_user(self):
user = UserF.create()
view = RuleDelete.as_view()
project = ProjectF.create(add_contributors=[user])
grouping = GroupingFactory.create(**{'project': project})
rule = RuleFactory.create(**{'grouping': grouping})
url = reverse(
'admin:rule_delete',
kwargs={
'project_id': project.id,
'grouping_id': grouping.id,
'rule_id': rule.id
}
)
request = APIRequestFactory().get(url)
request.user = user
response = view(
request,
project_id=project.id,
grouping_id=grouping.id,
rule_id=rule.id).render()
self.assertEqual(response.status_code, 200)
self.assertEqual(Rule.objects.count(), 1)
self.assertContains(
response,
'You are not member of the administrators group of this project '
'and therefore not allowed to alter the settings of the project'
)
示例10: test_get_data_combined
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_get_data_combined(self):
user = UserF.create()
project = ProjectF.create(add_admins=[user])
category_1 = CategoryFactory(**{'project': project})
category_2 = CategoryFactory(**{'project': project})
category_3 = CategoryFactory(**{'project': project})
view = GroupingFactory(**{'project': project})
for x in range(0, 5):
ObservationFactory.create(**{
'project': project,
'category': category_1}
)
ObservationFactory.create(**{
'project': project,
'category': category_2}
)
ObservationFactory.create(**{
'project': project,
'category': category_3}
)
RuleFactory(**{
'grouping': view,
'category': category_1
})
RuleFactory(**{
'grouping': view,
'category': category_2
})
self.assertEqual(view.data(user).count(), 10)
for observation in view.data(user):
self.assertNotEqual(
observation.category, category_3)
示例11: test
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
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)
示例12: test_delete_with_admin
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_delete_with_admin(self):
view = RuleDelete.as_view()
project = ProjectF.create()
grouping = GroupingFactory.create(**{'project': project})
rule = RuleFactory.create(**{'grouping': grouping})
url = reverse(
'admin:rule_delete',
kwargs={
'project_id': project.id,
'grouping_id': grouping.id,
'rule_id': rule.id
}
)
request = APIRequestFactory().get(url)
request.user = project.creator
from django.contrib.messages.storage.fallback import FallbackStorage
setattr(request, 'session', 'session')
messages = FallbackStorage(request)
setattr(request, '_messages', messages)
response = view(
request,
project_id=project.id,
grouping_id=grouping.id,
rule_id=rule.id)
self.assertEqual(response.status_code, 302)
self.assertEqual(Rule.objects.count(), 0)
示例13: test_single_lookup
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_single_lookup(self):
project = ProjectF.create()
category = CategoryFactory.create(**{'project': project})
lookup = LookupFieldFactory.create(
**{'category': category, 'key': 'lookup'}
)
kermit = LookupValueFactory.create(**{
'field': lookup,
'name': 'Kermit'
})
gonzo = LookupValueFactory.create(**{
'field': lookup,
'name': 'Gonzo'
})
ObservationFactory.create_batch(3, **{
'project': project,
'category': category,
'properties': {'lookup': kermit.id}
})
ObservationFactory.create_batch(3, **{
'project': project,
'category': category,
'properties': {'lookup': gonzo.id}
})
result = project.observations.all().search('kermit')
self.assertEqual(len(result), 3)
for o in result:
self.assertEqual(o.properties.get('lookup'), kermit.id)
示例14: test_update_where_clause
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_update_where_clause(self):
project = ProjectF.create()
cat_1 = CategoryFactory.create(**{'project': project})
cat_2 = CategoryFactory.create(**{'project': project})
usergroup = UserGroupF.create(**{'project': project})
usergroup.filters = {
cat_1.id: {},
cat_2.id: {}
}
usergroup.save()
self.assertIn(
UserGroup.objects.get(pk=usergroup.id).where_clause,
[
'((category_id = %s)) OR ((category_id = %s))' % (
cat_2.id, cat_1.id
),
'((category_id = %s)) OR ((category_id = %s))' % (
cat_1.id, cat_2.id
)
]
)
usergroup.filters = {}
usergroup.save()
self.assertEqual(
UserGroup.objects.get(pk=usergroup.id).where_clause,
'FALSE'
)
示例15: test_get_with_admin
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectF [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectF import create [as 别名]
def test_get_with_admin(self):
view = RuleSettings.as_view()
project = ProjectF.create()
grouping = GroupingFactory.create(**{'project': project})
rule = RuleFactory.create(**{'grouping': grouping})
url = reverse(
'admin:rule_settings',
kwargs={
'project_id': project.id,
'grouping_id': grouping.id,
'rule_id': rule.id
}
)
request = APIRequestFactory().get(url)
request.user = project.creator
response = view(
request,
project_id=project.id,
grouping_id=grouping.id,
rule_id=rule.id).render()
self.assertEqual(response.status_code, 200)
self.assertNotContains(
response,
'You are not member of the administrators group of this project '
'and therefore not allowed to alter the settings of the project'
)