本文整理汇总了Python中geokey.categories.tests.model_factories.NumericFieldFactory.create方法的典型用法代码示例。如果您正苦于以下问题:Python NumericFieldFactory.create方法的具体用法?Python NumericFieldFactory.create怎么用?Python NumericFieldFactory.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类geokey.categories.tests.model_factories.NumericFieldFactory
的用法示例。
在下文中一共展示了NumericFieldFactory.create方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_import_csv_last
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
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)
示例2: test_import_geomtry_inbetween
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
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)
示例3: test_update_draft_observation
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
def test_update_draft_observation(self):
creator = UserF()
location = LocationFactory()
category = CategoryFactory()
TextFieldFactory.create(**{
'key': 'text',
'category': category,
'required': True,
'order': 0
})
NumericFieldFactory.create(**{
'key': 'number',
'category': category,
'order': 1
})
data = {'number': 12}
observation = Observation.create(
properties=data, creator=creator, location=location,
category=category, project=category.project,
status='draft'
)
updater = UserF()
update = {'number': 13}
observation.update(properties=update, updator=updater, status='draft')
self.assertEqual(observation.properties.get('number'), 13)
self.assertEqual(observation.version, 1)
示例4: setUp
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
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
})
示例5: test_filters
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
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)
示例6: test_validate_full_invalid
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
def test_validate_full_invalid(self):
creator = UserF()
location = LocationFactory()
category = CategoryFactory()
TextFieldFactory.create(**{
'key': 'text',
'category': category,
'order': 0
})
NumericFieldFactory.create(**{
'key': 'number',
'category': category,
'order': 1
})
data = {'text': 'Text', 'number': 12}
observation = Observation.create(
properties=data, creator=creator, location=location,
category=category, project=category.project, status='active'
)
updater = UserF()
update = {'text': 'Udpated Text', 'number': 'abc', 'version': 1}
Observation.validate_full(category=category, data=update)
observation.update(properties=update, updator=updater)
self.assertEqual(observation.properties, data)
self.assertEqual(observation.version, 1)
示例7: test_get_data_min_max_number_filter
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory 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)
示例8: setUp
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
def setUp(self):
self.factory = APIRequestFactory()
self.admin = UserF.create()
self.contributor = UserF.create()
self.non_member = UserF.create()
self.project = ProjectF(
add_admins=[self.admin],
add_contributors=[self.contributor]
)
self.category = CategoryFactory(**{
'status': 'active',
'project': self.project
})
TextFieldFactory.create(**{
'key': 'key_1',
'category': self.category,
'required': True,
'order': 1
})
NumericFieldFactory.create(**{
'key': 'key_2',
'category': self.category,
'minval': 0,
'maxval': 1000,
'order': 2
})
self.data = {
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [
-0.13404607772827148,
51.52439200896907
]
},
"properties": {
"key_1": "value 1",
"key_2": 12
},
"meta": {
"category": self.category.id,
},
"location": {
"name": "UCL",
"description": "UCL's main quad",
"private": True
}
}
示例9: test_log_create
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
def test_log_create(self):
"""Test when numeric field gets created."""
log_count_init = LoggerHistory.objects.count()
field = NumericFieldFactory.create(**{
'category': self.category})
log = LoggerHistory.objects.last()
log_count = LoggerHistory.objects.count()
self.assertNotEqual(log.user, {
'id': str(self.user.id),
'display_name': self.user.display_name})
self.assertEqual(log.project, {
'id': str(self.project.id),
'name': self.project.name})
self.assertEqual(log.usergroup, None)
self.assertEqual(log.category, {
'id': str(self.category.id),
'name': self.category.name})
self.assertEqual(log.field, {
'id': str(field.id),
'name': field.name,
'type': 'NumericField'})
self.assertEqual(log.location, None)
self.assertEqual(log.observation, None)
self.assertEqual(log.comment, None)
self.assertEqual(log.subset, None)
self.assertEqual(log.action, {
'id': 'created',
'class': 'Field'})
self.assertEqual(log_count, log_count_init + 1)
self.assertEqual(log.historical, None)
示例10: setUp
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
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'}
示例11: test_serialize_invalid_update
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
def test_serialize_invalid_update(self):
observation = ObservationFactory.create(
**{'properties': {'number': 12}})
NumericFieldFactory.create(**{
'key': 'number',
'category': observation.category})
serializer = ContributionSerializer(
observation,
data={
'properties': {
'number': "blah"
}
},
context={'user': self.contributor, 'project': self.project}
)
serializer.is_valid(raise_exception=True)
o = Observation.objects.get(pk=observation.id)
self.assertEqual(o.attributes.get('number'), 12)
示例12: setUp
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
def setUp(self):
"""Set up test."""
self.user = UserFactory.create()
self.project = ProjectFactory.create(**{
'creator': self.user})
self.category = CategoryFactory.create(**{
'creator': self.user,
'project': self.project})
self.numericfield = NumericFieldFactory.create(**{
'category': self.category})
示例13: test_serialize_update
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
def test_serialize_update(self):
observation = ObservationFactory.create(
**{'properties': {'number': 12}})
NumericFieldFactory.create(**{
'key': 'number',
'category': observation.category})
serializer = ContributionSerializer(
observation,
data={
'properties': {
'number': 15
}
},
context={'user': self.contributor, 'project': self.project}
)
serializer.is_valid()
serializer.save()
result = serializer.data
self.assertEqual(
result.get('properties').get('number'),
15
)
示例14: test_get_numericfield_filter
# 需要导入模块: from geokey.categories.tests.model_factories import NumericFieldFactory [as 别名]
# 或者: from geokey.categories.tests.model_factories.NumericFieldFactory import create [as 别名]
def test_get_numericfield_filter(self):
field = NumericFieldFactory.create(**{'name': 'Field'})
self.assertEqual(
get_numericfield_filter(field, {"minval": 5}),
'<li>Field is greater than 5</li>'
)
self.assertEqual(
get_numericfield_filter(field, {"maxval": 5}),
'<li>Field is lower than 5</li>'
)
self.assertEqual(
get_numericfield_filter(field, {"minval": 1, "maxval": 5}),
'<li>Field is greater than 1 and lower than 5</li>'
)