本文整理汇总了Python中geokey.contributions.tests.model_factories.ObservationFactory类的典型用法代码示例。如果您正苦于以下问题:Python ObservationFactory类的具体用法?Python ObservationFactory怎么用?Python ObservationFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ObservationFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_save_document_file_count_update
def test_post_save_document_file_count_update(self):
observation = ObservationFactory()
document_file = DocumentFile.objects.create(
name='Test name',
description='Test Description',
contribution=observation,
creator=UserFactory.create(),
document=get_pdf_document()
)
DocumentFile.objects.create(
status='deleted',
name='Test name',
description='Test Description',
contribution=observation,
creator=UserFactory.create(),
document=get_pdf_document()
)
post_save_count_update(
DocumentFile,
instance=document_file,
created=True)
observation.refresh_from_db()
self.assertEqual(observation.num_media, 1)
self.assertEqual(observation.num_comments, 0)
示例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_save_video_file_count_update
def test_post_save_video_file_count_update(self):
observation = ObservationFactory()
video_file = VideoFile.objects.create(
name='Test name',
description='Test Description',
contribution=observation,
creator=UserFactory.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=UserFactory.create(),
video=get_image(),
youtube_link='http://example.com/1122323',
swf_link='http://example.com/1122323.swf'
)
post_save_count_update(
VideoFile,
instance=video_file,
created=True)
observation.refresh_from_db()
self.assertEqual(observation.num_media, 1)
self.assertEqual(observation.num_comments, 0)
示例4: test_post_save_audio_file_count_update
def test_post_save_audio_file_count_update(self):
observation = ObservationFactory()
audio_file = AudioFile.objects.create(
name='Test name',
description='Test Description',
contribution=observation,
creator=UserFactory.create(),
audio=get_image()
)
AudioFile.objects.create(
status='deleted',
name='Test name',
description='Test Description',
contribution=observation,
creator=UserFactory.create(),
audio=get_image()
)
post_save_count_update(
AudioFile,
instance=audio_file,
created=True)
observation.refresh_from_db()
self.assertEqual(observation.num_media, 1)
self.assertEqual(observation.num_comments, 0)
示例5: test_get_data_min_max_number_filter
def test_get_data_min_max_number_filter(self):
user = UserFactory.create()
project = ProjectFactory.create()
category_1 = CategoryFactory(**{'project': project})
NumericFieldFactory.create(**{
'key': 'number',
'category': category_1
})
category_2 = CategoryFactory(**{'project': project})
NumericFieldFactory.create(**{
'key': 'bla',
'category': category_2
})
UserGroupFactory.create(
add_users=[user],
**{
'project': project,
'filters': {
category_1.id: {'number': {
'minval': '10',
'maxval': '22'
}}
}
}
)
for x in range(0, 5):
ObservationFactory.create(**{
'project': project,
'category': category_1,
'properties': {'number': 5}}
)
ObservationFactory.create(**{
'project': project,
'category': category_1,
'properties': {'number': 12}}
)
ObservationFactory.create(**{
'project': project,
'category': category_1,
'properties': {'number': 20}}
)
ObservationFactory.create(**{
'project': project,
'category': category_1,
'properties': {'number': 25}}
)
ObservationFactory.create(**{
'project': project,
'category': category_2,
'properties': {'number': 12}}
)
self.assertEqual(project.get_all_contributions(user).count(), 10)
示例6: setUp
def setUp(self):
"""Setup for test."""
self.user = UserFactory.create()
self.category_tweet = CategoryFactory.create(
name="Tweets")
self.observation = ObservationFactory.create()
self.observation_tweet = ObservationFactory.create(
category=self.category_tweet)
示例7: test_log_create_draft
def test_log_create_draft(self):
"""Test when observation gets created as a draft."""
log_count_init = LoggerHistory.objects.count()
ObservationFactory.create(**{
'status': 'draft',
'creator': self.user,
'location': self.location,
'project': self.project,
'category': self.category})
self.assertEqual(LoggerHistory.objects.count(), log_count_init)
示例8: test_daily_digest
def test_daily_digest(self):
do_not_notify = UserF.create()
moderator = UserF.create()
contributor = UserF.create()
UserF.create()
project = ProjectF.create(
add_admins=[moderator],
add_contributors=[contributor]
)
AdminsFactory.create(**{
'project': project,
'user': do_not_notify,
'contact': False
})
suspended = ObservationFactory.create(
created_at=(datetime.utcnow() - timedelta(2)).replace(tzinfo=utc),
project=project,
creator=contributor,
status='active'
)
updated = ObservationFactory.create(
project=project,
creator=contributor
)
approved = ObservationFactory.create(
project=project,
creator=contributor,
status='pending'
)
yesterday = datetime.utcnow().replace(tzinfo=utc)
suspended.update(
properties=None,
status='pending',
updator=UserF.create()
)
updated.update(properties={'key': 'value'}, updator=UserF.create())
approved.update(properties=None, status='active', updator=moderator)
for user in [moderator, contributor]:
ObservationFactory.create(
project=project,
creator=user,
status='pending'
)
command = Command()
command.send_daily_digest(yesterday)
self.assertEquals(len(mail.outbox), 3)
示例9: test_get_user_contributions
def test_get_user_contributions(self):
user = UserFactory.create()
project = ProjectFactory.create()
ObservationFactory.create_batch(
5,
**{'creator': user, 'project': project}
)
serializer = ProjectSerializer(project, context={'user': user})
self.assertEqual(5, serializer.get_user_contributions(project))
serializer = ProjectSerializer(
project, context={'user': AnonymousUser()}
)
self.assertEqual(0, serializer.get_user_contributions(project))
示例10: test_download_data_as_tsv
def test_download_data_as_tsv(self):
project = ProjectFactory.create(**{'isprivate': False})
EpiCollectProjectModel.objects.create(project=project, enabled=True)
ObservationFactory.create_batch(
20, **{'project': project, 'properties': {'key': 'value'}})
factory = APIRequestFactory()
url = reverse('geokey_epicollect:download', kwargs={
'project_id': project.id
}) + '?xml=false'
request = factory.get(url)
view = EpiCollectDownloadView.as_view()
response = view(request, project_id=project.id)
self.assertEqual(response.status_code, 200)
示例11: test_delete_with_observation
def test_delete_with_observation(self):
category = CategoryFactory.create()
observation = ObservationFactory.create(**{"category": category})
category.delete()
Category.objects.get(pk=category.id)
Observation.objects.get(pk=observation.id)
示例12: test_get_created_before_and_after
def test_get_created_before_and_after(self):
user = UserFactory.create()
project = ProjectFactory.create()
category_1 = CategoryFactory(**{'project': project})
UserGroupFactory.create(
add_users=[user],
**{
'project': project,
'filters': {
category_1.id: {
'min_date': '2013-01-01 00:00:00',
'max_date': '2013-10-01 00:00:00'}
}
}
)
obs = ObservationFactory.create_batch(5, **{
'project': project,
'category': category_1
})
for o in obs:
o.created_at = datetime(2014, 7, 23, 10, 34, 1, tzinfo=pytz.utc)
o.save()
obs = ObservationFactory.create_batch(5, **{
'project': project,
'category': category_1
})
for o in obs:
o.created_at = datetime(2013, 7, 23, 10, 34, 1, tzinfo=pytz.utc)
o.save()
obs = ObservationFactory.create_batch(5, **{
'project': project,
'category': category_1
})
for o in obs:
o.created_at = datetime(2012, 7, 23, 10, 34, 1, tzinfo=pytz.utc)
o.save()
self.assertEqual(project.get_all_contributions(user).count(), 5)
示例13: test_get_type_name
def test_get_type_name(self):
audio_file = AudioFile.objects.create(
name='Test name',
description='Test Description',
contribution=ObservationFactory.create(),
creator=UserFactory.create(),
audio=get_image()
)
self.assertEqual(audio_file.type_name, 'AudioFile')
示例14: test_get_type_name
def test_get_type_name(self):
document_file = DocumentFile.objects.create(
name='Test name',
description='Test Description',
contribution=ObservationFactory.create(),
creator=UserFactory.create(),
document=get_pdf_document()
)
self.assertEqual(document_file.type_name, 'DocumentFile')
示例15: test_delete_file
def test_delete_file(self):
image_file = ImageFile.objects.create(
name='Test name',
description='Test Description',
contribution=ObservationFactory.create(),
creator=UserFactory.create(),
image=get_image()
)
image_file.delete()
self.assertEquals(image_file.status, 'deleted')