本文整理汇总了Python中geokey.contributions.tests.model_factories.ObservationFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python ObservationFactory.create方法的具体用法?Python ObservationFactory.create怎么用?Python ObservationFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geokey.contributions.tests.model_factories.ObservationFactory
的用法示例。
在下文中一共展示了ObservationFactory.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_data_min_max_number_filter
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
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)
示例2: setUp
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
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)
示例3: test_log_create_draft
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
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)
示例4: test_daily_digest
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
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)
示例5: test_delete_with_observation
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
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)
示例6: test_get_type_name
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
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')
示例7: test_get_type_name
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
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')
示例8: test_delete_file
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
def test_delete_file(self):
audio_file = AudioFile.objects.create(
name='Test name',
description='Test Description',
contribution=ObservationFactory.create(),
creator=UserFactory.create(),
audio=get_image()
)
audio_file.delete()
self.assertEqual(audio_file.status, 'deleted')
示例9: test_delete_file
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
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')
示例10: test_create_image
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
def test_create_image(self):
image_file = MediaFile.objects.create(
name='Test name',
description='Test Description',
contribution=ObservationFactory.create(),
creator=UserF.create(),
the_file=get_image()
)
self.assertIsNotNone(image_file.image)
self.assertEqual(image_file.type_name, 'ImageFile')
示例11: test_get_data_text_filter
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
def test_get_data_text_filter(self):
user = UserFactory.create()
project = ProjectFactory.create()
category_1 = CategoryFactory(**{'project': project})
TextFieldFactory(**{
'key': 'text',
'category': category_1
})
category_2 = CategoryFactory(**{'project': project})
TextFieldFactory(**{
'key': 'bla',
'category': category_2
})
UserGroupFactory.create(
add_users=[user],
**{
'project': project,
'filters': {category_1.id: {'text': 'yes'}}
}
)
for x in range(0, 5):
ObservationFactory.create(**{
'project': project,
'category': category_1,
'properties': {'text': 'yes %s' % x}}
)
ObservationFactory.create(**{
'project': project,
'category': category_1,
'status': 'pending',
'properties': {'text': 'yes %s' % x}}
)
ObservationFactory.create(**{
'project': project,
'category': category_1,
'properties': {'text': 'no %s' % x}}
)
ObservationFactory.create(**{
'project': project,
'category': category_2,
'properties': {'bla': 'yes %s' % x}}
)
self.assertEqual(project.get_all_contributions(user).count(), 5)
示例12: test_get_data_combined
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory 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)
示例13: test_get_updated_data
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
def test_get_updated_data(self):
user = UserF.create()
project = ProjectF.create(add_admins=[user])
category_1 = CategoryFactory(**{'project': project})
TextFieldFactory(**{
'key': 'text',
'category': category_1
})
observation = ObservationFactory.create(**{
'project': project,
'category': category_1,
'properties': {'text': 'yes to update'}
})
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,
'properties': {'text': 'no ' + str(x)}
})
view = GroupingFactory(**{'project': project})
RuleFactory(**{
'grouping': view,
'category': category_1,
'constraints': {'text': 'yes'}
})
updater = UserF()
update = {'text': 'yes, this has been updated', 'version': 1}
observation.update(properties=update, updator=updater)
self.assertEqual(view.data(user).count(), 6)
示例14: test_get_context_data
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory 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)
示例15: test_get_data_text_filter
# 需要导入模块: from geokey.contributions.tests.model_factories import ObservationFactory [as 别名]
# 或者: from geokey.contributions.tests.model_factories.ObservationFactory import create [as 别名]
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)