本文整理汇总了Python中geokey.projects.tests.model_factories.ProjectFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectFactory.create方法的具体用法?Python ProjectFactory.create怎么用?Python ProjectFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geokey.projects.tests.model_factories.ProjectFactory
的用法示例。
在下文中一共展示了ProjectFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_with_user
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def test_post_with_user(self):
user = UserFactory.create()
project = ProjectFactory.create(
**{'isprivate': False, 'creator': user})
to_enable = ProjectFactory.create(
**{'isprivate': False, 'creator': user})
EpiCollectProjectModel.objects.create(
project=project, enabled=True
)
self.request.method = 'POST'
self.request.POST = QueryDict('epicollect_project=%s' % to_enable.id)
self.request.user = user
response = self.view(self.request).render()
self.assertEqual(response.status_code, 200)
self.assertEqual(EpiCollectProjectModel.objects.count(), 1)
rendered = render_to_string(
'epicollect_index.html',
{
'projects': [
Project.objects.get(pk=project.id),
Project.objects.get(pk=to_enable.id)
],
'epicollect': [],
'protocol': self.request.scheme,
'host': self.request.get_host(),
'user': project.creator,
'PLATFORM_NAME': get_current_site(self.request).name,
'GEOKEY_VERSION': version.get_version
}
)
response = render_helpers.remove_csrf(response.content.decode('utf-8'))
self.assertEqual(response, rendered)
示例2: test_get_context_data
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def test_get_context_data(self):
"""Test getting context data."""
user = UserFactory.create(**{'is_superuser': True})
# 1 contribution, 1 comment
project_1 = ProjectFactory.create()
category_1 = CategoryFactory.create(project=project_1)
contribution_1 = ObservationFactory.create(
project=project_1,
category=category_1)
CommentFactory.create(commentto=contribution_1)
# 2 contributions (1 deleted), 2 comments
project_2 = ProjectFactory.create(add_admins=[user])
category_2 = CategoryFactory.create(project=project_2)
contribution_2 = ObservationFactory.create(
project=project_2,
category=category_2)
CommentFactory.create(commentto=contribution_2)
contribution_3 = ObservationFactory.create(
project=project_2,
category=category_2)
CommentFactory.create(commentto=contribution_3)
contribution_3.delete()
# 2 contributions (1 deleted), 3 comments (1 deleted)
project_3 = ProjectFactory.create(add_moderators=[user])
category_3 = CategoryFactory.create(project=project_3)
contribution_4 = ObservationFactory.create(
project=project_3,
category=category_3)
CommentFactory.create(commentto=contribution_4)
comment_to_delete = CommentFactory.create(commentto=contribution_4)
comment_to_delete.delete()
contribution_5 = ObservationFactory.create(
project=project_3,
category=category_3)
CommentFactory.create(commentto=contribution_5)
contribution_5.delete()
# 1 contribution, 2 comments (1 deleted)
project_4 = ProjectFactory.create(add_contributors=[user])
category_4 = CategoryFactory.create(project=project_4)
contribution_6 = ObservationFactory.create(
project=project_4,
category=category_4)
CommentFactory.create(commentto=contribution_6)
comment_to_delete = CommentFactory.create(commentto=contribution_6)
comment_to_delete.delete()
view = ManageProjects()
context = view.get_context_data()
self.assertEqual(len(context.get('projects')), 4)
for project in context.get('projects'):
project.refresh_from_db()
self.assertEqual(project.contributions_count, 1)
self.assertEqual(project.comments_count, 1)
self.assertEqual(project.media_count, 0)
示例3: test_upload_checkboxes
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def test_upload_checkboxes(self):
project = ProjectFactory.create(
**{'isprivate': False, 'everyone_contributes': True}
)
EpiCollectProjectModel.objects.create(project=project, enabled=True)
type1 = CategoryFactory.create(**{'project': project})
field = MultipleLookupFieldFactory(**{'category': type1})
val_1 = MultipleLookupValueFactory(**{'field': field})
val_2 = MultipleLookupValueFactory(**{'field': field})
data = ('location_lat=51.5175205&location_lon=-0.1729205&location_acc='
'20&location_alt=&location_bearing=&category={category}&'
'{field_key}_{category}={checkbox_1}%2c+{checkbox_2}'.format(
category=type1.id,
field_key=field.key,
checkbox_1=val_1.id,
checkbox_2=val_2.id
))
factory = APIRequestFactory()
url = reverse('geokey_epicollect:upload', kwargs={
'project_id': project.id
})
request = factory.post(
url + '?type=data',
data,
content_type='application/x-www-form-urlencoded'
)
view = EpiCollectUploadView.as_view()
response = view(request, project_id=project.id)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, '1')
示例4: test_upload_data_without_location
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def test_upload_data_without_location(self):
project = ProjectFactory.create(
**{'isprivate': False, 'everyone_contributes': True}
)
EpiCollectProjectModel.objects.create(project=project, enabled=True)
type1 = CategoryFactory.create(**{'project': project})
field = TextFieldFactory(**{'category': type1})
data = ('category={category}&{field_key}_{category}=Westbourne+'
'Park'.format(
category=type1.id,
field_key=field.key)
)
factory = APIRequestFactory()
url = reverse('geokey_epicollect:upload', kwargs={
'project_id': project.id
})
request = factory.post(
url + '?type=data',
data,
content_type='application/x-www-form-urlencoded'
)
view = EpiCollectUploadView.as_view()
response = view(request, project_id=project.id)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, '0')
示例5: test_upload_data_with_media
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def test_upload_data_with_media(self):
project = ProjectFactory.create(
**{'isprivate': False, 'everyone_contributes': True}
)
EpiCollectProjectModel.objects.create(project=project, enabled=True)
type1 = CategoryFactory.create(**{'project': project})
field = TextFieldFactory(**{'category': type1})
data = ('location_lat=51.5175205&location_lon=-0.1729205&location_acc='
'20&location_alt=&location_bearing=&category={category}&'
'{field_key}_{category}=Westbourne+Park&photo=abc&'
'video=def'.format(
category=type1.id,
field_key=field.key)
)
factory = APIRequestFactory()
url = reverse('geokey_epicollect:upload', kwargs={
'project_id': project.id
})
request = factory.post(
url + '?type=data',
data,
content_type='application/x-www-form-urlencoded'
)
view = EpiCollectUploadView.as_view()
response = view(request, project_id=project.id)
self.assertEqual(response.status_code, 200)
self.assertEqual(EpiCollectMedia.objects.count(), 2)
self.assertEqual(response.content, '1')
示例6: setUp
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def setUp(self):
"""Set up test method 'create_new_observation'."""
self.admin = UserFactory.create()
self.project = ProjectFactory.create(creator=self.admin)
self.socialaccount = SocialAccount.objects.create(
user=self.admin, provider='facebook', uid='1')
self.category = CategoryFactory.create(
name='Tweets',
creator=self.admin,
project=self.project
)
self.field_text = TextFieldFactory.create(
key='tweet',
category=self.category
)
self.tweet_id_field = NumericFieldFactory.create(
key='tweet-id',
category=self.category
)
self.si_pull = SocialInteractionPullFactory.create(
socialaccount=self.socialaccount,
project=self.project,
creator=self.admin)
self.geo_tweet = {
'geometry': u'POINT (-0.1350858 51.5246635)',
'text': u'#Project2 scorpion @adeuonce',
'created_at': datetime(2017, 5, 23, 14, 43, 1),
'id': 867028097530572801,
'user': u'Pepito Grillo'}
示例7: setUp
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory 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
})
示例8: test_upload_data_to_private_project
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def test_upload_data_to_private_project(self):
project = ProjectFactory.create()
type1 = CategoryFactory.create(**{'project': project})
field = TextFieldFactory(**{'category': type1})
data = ('location_lat=51.5175205&location_lon=-0.1729205&location_acc='
'20&location_alt=&location_bearing=&category={category}&'
'{field_key}_{category}=Westbourne+Park'.format(
category=type1.id,
field_key=field.key)
)
factory = APIRequestFactory()
url = reverse('geokey_epicollect:upload', kwargs={
'project_id': project.id
})
request = factory.post(
url + '?type=data',
data,
content_type='application/x-www-form-urlencoded'
)
view = EpiCollectUploadView.as_view()
response = view(request, project_id=project.id)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, '0')
示例9: test_get_with_admin
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def test_get_with_admin(self):
"""
Accessing the view with project admin.
It should render the page.
"""
project = ProjectFactory.create()
user = project.creator
logs = LoggerHistory.objects.filter(
project__contains={'id': str(project.id)})
logger_list = LoggerList()
self.request.user = user
response = self.view(self.request, project_id=project.id).render()
rendered = render_to_string(
'logger/logger_list.html',
{
'project': project,
'user': user,
'PLATFORM_NAME': get_current_site(self.request).name,
'GEOKEY_VERSION': version.get_version(),
'logs': logger_list.paginate_logs(
logs[::-1],
self.request.GET.get('page'))
}
)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content.decode('utf-8'), rendered)
示例10: test_single_lookup
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def test_single_lookup(self):
project = ProjectFactory.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)
示例11: setUp
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def setUp(self):
"""Set up tests."""
self.anonymous_user = AnonymousUser()
self.regular_user = UserFactory.create()
self.admin_user = UserFactory.create()
self.project = ProjectFactory.create(creator=self.admin_user)
self.socialaccount_2 = SocialAccount.objects.create(
user=self.admin_user, provider='facebook', uid='2')
self.socialaccount_1 = SocialAccount.objects.create(
user=self.admin_user, provider='twitter', uid='1')
self.socialaccount_3 = SocialAccount.objects.create(
user=self.admin_user, provider='twitter', uid='3')
self.si_pull = SocialInteractionPullFactory.create(
socialaccount=self.socialaccount_1,
project=self.project,
creator=self.admin_user
)
self.view = SocialInteractionPullSettings.as_view()
self.request = HttpRequest()
self.request.method = 'GET'
self.request.user = self.anonymous_user
self.freq = freq_dic.keys()
refund_dict = {value: key for key, value in STATUS}
self.status_types = refund_dict.keys()
setattr(self.request, 'session', 'session')
messages = FallbackStorage(self.request)
setattr(self.request, '_messages', messages)
示例12: test_pre_delete_project_when_no_aq_project
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def test_pre_delete_project_when_no_aq_project(self):
project = ProjectFactory.create(status='active')
pre_delete_project(Project, instance=project)
self.assertEquals(len(mail.outbox), 0)
示例13: test_update_where_clause
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def test_update_where_clause(self):
project = ProjectFactory.create()
cat_1 = CategoryFactory.create(**{'project': project})
cat_2 = CategoryFactory.create(**{'project': project})
usergroup = UserGroupFactory.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'
)
示例14: test_pre_delete_project
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def test_pre_delete_project(self):
geokey_project = ProjectFactory.create(status='active')
sapelli_project = SapelliProjectFactory.create(geokey_project=geokey_project)
pre_delete_project(Project, instance=geokey_project)
self.assertFalse(SapelliProject.objects.filter(pk=sapelli_project.pk).exists())
示例15: setUp
# 需要导入模块: from geokey.projects.tests.model_factories import ProjectFactory [as 别名]
# 或者: from geokey.projects.tests.model_factories.ProjectFactory import create [as 别名]
def setUp(self):
"""Set up test."""
self.user = UserFactory.create()
self.project = ProjectFactory.create(**{
'creator': self.user})
self.usergroup = UserGroupFactory.create(**{
'project': self.project})