本文整理汇总了Python中projects.tests.model_factories.ProjectF.create方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectF.create方法的具体用法?Python ProjectF.create怎么用?Python ProjectF.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类projects.tests.model_factories.ProjectF
的用法示例。
在下文中一共展示了ProjectF.create方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_post_with_admin
# 需要导入模块: from projects.tests.model_factories import ProjectF [as 别名]
# 或者: from 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 projects.tests.model_factories import ProjectF [as 别名]
# 或者: from 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_single_lookup
# 需要导入模块: from projects.tests.model_factories import ProjectF [as 别名]
# 或者: from 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,
'attributes': {'lookup': kermit.id}
})
ObservationFactory.create_batch(3, **{
'project': project,
'category': category,
'attributes': {'lookup': gonzo.id}
})
result = project.observations.all().search('kermit')
self.assertEqual(len(result), 3)
for o in result:
self.assertEqual(o.attributes.get('lookup'), str(kermit.id))
示例4: setUp
# 需要导入模块: from projects.tests.model_factories import ProjectF [as 别名]
# 或者: from 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
})
示例5: setUp
# 需要导入模块: from projects.tests.model_factories import ProjectF [as 别名]
# 或者: from projects.tests.model_factories.ProjectF import create [as 别名]
def setUp(self):
self.factory = RequestFactory()
self.admin = UserF.create()
self.contributor = UserF.create()
self.non_member = UserF.create()
self.project = ProjectF.create(
add_admins=[self.admin],
add_contributors=[self.contributor]
)
示例6: test_admin
# 需要导入模块: from projects.tests.model_factories import ProjectF [as 别名]
# 或者: from projects.tests.model_factories.ProjectF import create [as 别名]
def test_admin(self):
user = UserF.create()
project = ProjectF.create(add_admins=[user])
view = GroupingFactory.create(**{
'project': project,
'isprivate': False
})
self.assertTrue(view.can_view(user))
self.assertTrue(view.can_read(user))
self.assertTrue(view.can_moderate(user))
示例7: test_get_update_projects
# 需要导入模块: from projects.tests.model_factories import ProjectF [as 别名]
# 或者: from projects.tests.model_factories.ProjectF import create [as 别名]
def test_get_update_projects(self):
# Setup everything
updated_project_1 = ProjectF.create()
updated_project_2 = ProjectF.create()
not_updated_project = ProjectF.create()
for x in range(0, 2):
for project in [
updated_project_1, updated_project_2, not_updated_project]:
ObservationFactory.create(project=project)
updated = ObservationFactory.create(project=updated_project_2)
yesterday = datetime.utcnow().replace(tzinfo=utc)
ObservationFactory.create(project=updated_project_1)
updated.update(attributes={'key': 'value'}, updator=UserF.create())
# the tests
command = Command()
updated_projects = command.get_updated_projects(yesterday)
self.assertIn(updated_project_1, updated_projects)
self.assertIn(updated_project_2, updated_projects)
self.assertNotIn(not_updated_project, updated_projects)
示例8: test_daily_digest
# 需要导入模块: from projects.tests.model_factories import ProjectF [as 别名]
# 或者: from projects.tests.model_factories.ProjectF import create [as 别名]
def test_daily_digest(self):
moderator = UserF.create()
contributor = UserF.create()
UserF.create()
project = ProjectF.create(
add_admins=[moderator],
add_contributors=[contributor]
)
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(
attributes=None,
status='pending',
updator=UserF.create()
)
updated.update(attributes={'key': 'value'}, updator=UserF.create())
approved.update(attributes=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_multiple_lookup
# 需要导入模块: from projects.tests.model_factories import ProjectF [as 别名]
# 或者: from projects.tests.model_factories.ProjectF import create [as 别名]
def test_multiple_lookup(self):
project = ProjectF.create()
category = CategoryFactory.create(**{'project': project})
lookup = MultipleLookupFieldFactory.create(
**{'category': category, 'key': 'lookup'}
)
kermit = MultipleLookupValueFactory.create(**{
'field': lookup,
'name': 'Kermit'
})
gonzo = MultipleLookupValueFactory.create(**{
'field': lookup,
'name': 'Gonzo'
})
piggy = MultipleLookupValueFactory.create(**{
'field': lookup,
'name': 'Ms Piggy'
})
ObservationFactory.create_batch(3, **{
'project': project,
'category': category,
'attributes': {'lookup': [piggy.id, kermit.id]}
})
ObservationFactory.create_batch(3, **{
'project': project,
'category': category,
'attributes': {'lookup': [gonzo.id]}
})
result = project.observations.all().search('kermit')
self.assertEqual(len(result), 3)
for o in result:
self.assertIn(kermit.id, json.loads(o.attributes.get('lookup')))
result = project.observations.all().search('piggy')
self.assertEqual(len(result), 3)
for o in result:
self.assertIn(kermit.id, json.loads(o.attributes.get('lookup')))
示例10: test_get_update_stats
# 需要导入模块: from projects.tests.model_factories import ProjectF [as 别名]
# 或者: from projects.tests.model_factories.ProjectF import create [as 别名]
def test_get_update_stats(self):
moderator = UserF.create()
contributor = UserF.create()
some_dude = UserF.create()
project = ProjectF.create(
add_admins=[moderator],
add_contributors=[contributor]
)
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(
attributes=None,
status='pending',
updator=UserF.create()
)
updated.update(attributes={'key': 'value'}, updator=UserF.create())
approved.update(attributes=None, status='active', updator=moderator)
for user in [moderator, contributor]:
ObservationFactory.create(
project=project,
creator=user,
status='pending'
)
command = Command()
report = command.get_updated_items(project, moderator, yesterday)
to_moderate = report.get('to_moderate')
self.assertEqual(len(to_moderate.get('new')), 2)
self.assertEqual(len(to_moderate.get('suspended')), 1)
self.assertIsNone(report.get('yours'))
report = command.get_updated_items(project, contributor, yesterday)
yours = report.get('yours')
self.assertEqual(len(yours.get('changed')), 3)
self.assertEqual(len(yours.get('approved')), 1)
self.assertEqual(len(yours.get('suspended')), 1)
report = command.get_updated_items(project, some_dude, yesterday)
self.assertEqual(report, None)