def test_create_invalid_observation(self): creator = UserF() location = LocationFactory() category = CategoryFactory() TextFieldFactory(**{'key': 'text', 'category': category}) NumericFieldFactory(**{'key': 'number', 'category': category}) data = {'text': 'Text', 'number': 'abc'} Observation.create(attributes=data, creator=creator, location=location, category=category, project=category.project)
def test_create_invalid_observation_with_empty_number(self): creator = UserF() location = LocationFactory() category = CategoryFactory() TextFieldFactory(**{'key': 'text', 'category': category}) NumericFieldFactory(**{ 'key': 'number', 'required': True, 'category': category }) data = {'text': 'bla'} Observation.create(attributes=data, creator=creator, location=location, category=category, project=category.project)
def test_create_observation_active_default(self): creator = UserF() location = LocationFactory() category = CategoryFactory(**{'default_status': 'active'}) TextFieldFactory(**{'key': 'text', 'category': category}) NumericFieldFactory(**{'key': 'number', 'category': category}) data = {'text': 'Text', 'number': 12} observation = Observation.create(attributes=data, creator=creator, location=location, category=category, project=category.project) self.assertEqual(observation.attributes, data) self.assertEqual(observation.status, 'active')
def test_update_invalid_observation(self): creator = UserF() location = LocationFactory() category = CategoryFactory() TextFieldFactory.create(**{'key': 'text', 'category': category}) NumericFieldFactory.create(**{'key': 'number', 'category': category}) data = {'text': 'Text', 'number': 12} observation = Observation.create(attributes=data, creator=creator, location=location, category=category, project=category.project) updater = UserF() update = {'text': 'Udpated Text', 'number': 'abc', 'version': 1} observation.update(attributes=update, updator=updater) self.assertEqual(observation.attributes, data) self.assertEqual(observation.version, 1)
def test_create_observation_with_inactive_field(self): creator = UserF() location = LocationFactory() category = CategoryFactory() TextFieldFactory(**{'key': 'text', 'category': category}) TextFieldFactory( **{ 'key': 'inactive_text', 'category': category, 'status': 'inactive', 'required': True }) NumericFieldFactory(**{'key': 'number', 'category': category}) data = {'text': 'Text', 'number': 12} observation = Observation.create(attributes=data, creator=creator, location=location, category=category, project=category.project) self.assertEqual(observation.attributes, data)
def test_update_draft_observation(self): creator = UserF() location = LocationFactory() category = CategoryFactory() TextFieldFactory.create(**{ 'key': 'text', 'category': category, 'required': True }) NumericFieldFactory.create(**{'key': 'number', 'category': category}) data = {'number': 12} observation = Observation.create(attributes=data, creator=creator, location=location, category=category, project=category.project, status='draft') updater = UserF() update = {'number': 13} observation.update(attributes=update, updator=updater) self.assertEqual(observation.attributes.get('number'), '13') self.assertEqual(observation.version, 1)