本文整理汇总了Python中geokey.categories.tests.model_factories.CategoryFactory类的典型用法代码示例。如果您正苦于以下问题:Python CategoryFactory类的具体用法?Python CategoryFactory怎么用?Python CategoryFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CategoryFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_expiry_field
def test_update_expiry_field(self):
category = CategoryFactory()
field = DateTimeFieldFactory(**{
'key': 'expires_at',
'category': category
})
category.expiry_field = field
category.save()
observation = ObservationFactory(**{
'project': category.project,
'category': category,
'expiry_field': None,
'properties': {
'expires_at': '2016-09-19T15:51:32.804Z'
}
})
observation.update_expiry_field()
observation.save()
ref = Observation.objects.get(pk=observation.id)
self.assertEqual(
ref.expiry_field,
datetime.datetime(2016, 9, 19, 15, 51, 32, 804000, tzinfo=pytz.utc)
)
示例2: test_update_where_clause
def test_update_where_clause(self):
project = ProjectF.create()
cat_1 = CategoryFactory.create(**{'project': project})
cat_2 = CategoryFactory.create(**{'project': project})
usergroup = UserGroupF.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'
)
示例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: setUp
def setUp(self):
self.factory = APIRequestFactory()
self.project = ProjectFactory.create()
self.category_0 = CategoryFactory.create(**{'project': self.project})
self.category_1 = CategoryFactory.create(**{'project': self.project})
self.category_2 = CategoryFactory.create(**{'project': self.project})
self.category_3 = CategoryFactory.create(**{'project': self.project})
self.category_4 = CategoryFactory.create(**{'project': self.project})
示例5: 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')
示例6: 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')
示例7: test_pre_delete_field
def test_pre_delete_field(self):
project = ProjectFactory.create(status='active')
category = CategoryFactory.create(project=project)
field = TextFieldFactory.create(category=category)
aq_project = AirQualityProjectFactory.create(
status='active',
project=project
)
aq_category = AirQualityCategoryFactory.create(
category=category,
project=aq_project
)
aq_field = AirQualityFieldFactory.create(
field=field,
category=aq_category
)
pre_delete_field(TextField, instance=field)
reference = AirQualityProject.objects.get(pk=aq_project.id)
self.assertEqual(reference.status, 'inactive')
self.assertEqual(
AirQualityField.objects.filter(pk=aq_field.id).exists(),
False
)
self.assertEquals(len(mail.outbox), 1)
示例8: test_filters
def test_filters(self):
category = CategoryFactory.create()
TextFieldFactory.create(**{'category': category, 'key': 'text'})
NumericFieldFactory.create(**{'category': category, 'key': 'number'})
DateFieldFactory.create(**{'category': category, 'key': 'date'})
DateTimeFieldFactory.create(
**{'category': category, 'key': 'datetime'})
TimeFieldFactory.create(**{'category': category, 'key': 'time'})
lookup = LookupFieldFactory.create(
**{'category': category, 'key': 'lookup'})
val_1 = LookupValueFactory.create(**{'field': lookup})
multiple = MultipleLookupFieldFactory.create(
**{'category': category, 'key': 'multiple'})
mul_1 = MultipleLookupValueFactory.create(**{'field': multiple})
rule = RuleFactory.create(**{
'category': category,
'min_date': datetime.datetime(2007, 12, 5, 12, 00),
'max_date': datetime.datetime(2012, 12, 5, 15, 00),
'constraints': {
'text': 'blah',
'number': {'minval': 0, 'maxval': 10},
'date': {'minval': 0, 'maxval': 10},
'datetime': {'minval': 0, 'maxval': 10},
'time': {'minval': 0, 'maxval': 10},
'lookup': [val_1.id],
'multiple': [mul_1.id]
}
})
result = filters(rule)
self.assertEqual(result.count('<li>'), 8)
示例9: test_import_csv_last
def test_import_csv_last(self):
category = CategoryFactory.create()
NumericFieldFactory.create(**{
'name': 'ID',
'key': 'id',
'category': category
})
TextFieldFactory.create(**{
'name': 'Name',
'key': 'name',
'category': category
})
TextFieldFactory.create(**{
'name': 'Description',
'key': 'description',
'category': category
})
data_import = DataImportFactory.create(**{
'fields': ['id', 'name', 'description'],
'category': category,
'project': category.project,
'geom_field': 'geom'
})
data_import.import_csv(UserFactory.create())
self.assertEqual(Observation.objects.count(), 2)
示例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: test_create_search_index
def test_create_search_index(self):
category = CategoryFactory.create()
TextFieldFactory.create(
**{'key': 'text_1', 'category': category, 'order': 0}
)
TextFieldFactory.create(
**{'key': 'text_2', 'category': category, 'order': 0}
)
TextFieldFactory.create(
**{'key': 'text_3', 'category': category, 'order': 0}
)
o = ObservationFactory.create(**{
'properties': {
'text_1': 'Blah, abc',
'text_2': 'blubb blah'
},
'category': category
})
o.create_search_index()
o.save()
reference = Observation.objects.get(pk=o.id)
self.assertEqual(
reference.search_index.split(',').sort(),
'blah,abc,blubb'.split(',').sort()
)
示例12: setUp
def setUp(self):
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.category = CategoryFactory(**{
'status': 'active',
'project': self.project
})
TextFieldFactory.create(**{
'key': 'key_1',
'category': self.category,
'order': 0
})
NumericFieldFactory.create(**{
'key': 'key_2',
'category': self.category,
'order': 1
})
示例13: 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'}
示例14: test_single_lookup
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,
'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_import_geomtry_inbetween
def test_import_geomtry_inbetween(self):
the_file = get_csv_file(['id', 'name', 'geom', 'description'])
category = CategoryFactory.create()
NumericFieldFactory.create(**{
'name': 'ID',
'key': 'id',
'category': category
})
TextFieldFactory.create(**{
'name': 'Name',
'key': 'name',
'category': category
})
TextFieldFactory.create(**{
'name': 'Description',
'key': 'description',
'category': category
})
data_import = DataImportFactory.create(**{
'fields': ['id', 'name', 'description'],
'category': category,
'project': category.project,
'csv_file': File(open(the_file.name))
})
data_import.import_csv(UserFactory.create())
self.assertEqual(Observation.objects.count(), 2)