本文整理汇总了Python中geokey.projects.tests.model_factories.ProjectFactory类的典型用法代码示例。如果您正苦于以下问题:Python ProjectFactory类的具体用法?Python ProjectFactory怎么用?Python ProjectFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ProjectFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_with_user
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
def test_get_context_data(self):
user = UserFactory.create(**{'is_superuser': True})
ProjectFactory.create_batch(5, add_admins=[user])
ProjectFactory.create_batch(5)
view = ProjectsList()
context = view.get_context_data()
self.assertEqual(len(context.get('projects')), 10)
示例3: test_get_context_data
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)
示例4: test_post_save_project_when_only_changing_status
def test_post_save_project_when_only_changing_status(self):
project = ProjectFactory(**{'status': 'active'})
ExportFactory.create(**{'project': project})
project.status = 'pending'
project.save
post_save_project(Project, instance=project)
self.assertEqual(
Export.objects.filter(project=project).exists(),
True
)
示例5: test_post_save_project_when_deleting
def test_post_save_project_when_deleting(self):
project = ProjectFactory(**{'status': 'active'})
ExportFactory.create(**{'project': project})
project.status = 'deleted'
project.save
post_save_project(Project, instance=project)
self.assertEqual(
Export.objects.filter(project=project).exists(),
False
)
示例6: setUp
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)
示例7: test_upload_data_to_private_project
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')
示例8: test_upload_checkboxes
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')
示例9: test_upload_data_without_location
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')
示例10: test_upload_data_with_media
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')
示例11: setUp
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'}
示例12: setUp
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
})
示例13: test_post_save_when_category_made_inactive
def test_post_save_when_category_made_inactive(self):
project = ProjectFactory.create(status='active')
category = CategoryFactory.create(project=project)
aq_project = AirQualityProjectFactory.create(
status='active',
project=project
)
aq_category = AirQualityCategoryFactory.create(
category=category,
project=aq_project
)
category.status = 'inactive'
category.save
post_save_category(Category, instance=category)
reference = AirQualityProject.objects.get(pk=aq_project.id)
self.assertEqual(reference.status, 'inactive')
self.assertEqual(
AirQualityCategory.objects.filter(pk=aq_category.id).exists(),
False
)
self.assertEquals(len(mail.outbox), 1)
示例14: test_single_lookup
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)
示例15: test_get_with_admin
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)