예제 #1
0
    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)
예제 #2
0
    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)
예제 #3
0
    def test_update_observation(self):
        category = CategoryFactory()
        TextFieldFactory(**{
            'key': 'text',
            'category': category,
            'order': 0
        })
        NumericFieldFactory(**{
            'key': 'number',
            'category': category,
            'order': 1
        })

        observation = ObservationFactory.create(**{
            'properties': {'text': 'Text', 'number': 12},
            'category': category,
            'project': category.project
        })

        updater = UserF()
        update = {'text': 'Udpated Text', 'number': 13}
        observation.update(properties=update, updator=updater)

        # ref_observation = Observation.objects.get(pk=observation.id)
        self.assertEqual(
            observation.properties,
            {'text': 'Udpated Text', 'number': 13}
        )
        self.assertEqual(observation.version, 2)
예제 #4
0
 def test_create_observation_active_default(self):
     creator = UserF()
     location = LocationFactory()
     category = CategoryFactory(**{'default_status': 'active'})
     TextFieldFactory(**{'key': 'text', 'category': category, 'order': 0})
     NumericFieldFactory(**{
         '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')
     self.assertEqual(observation.properties, data)
예제 #5
0
 def test_create_observation_with_polish_chars(self):
     creator = UserF()
     location = LocationFactory()
     category = CategoryFactory()
     TextFieldFactory(**{
         'key': 'text',
         'category': category,
         'required': True,
         'order': 0
     })
     NumericFieldFactory(**{
         'key': 'number',
         'category': category,
         'order': 1
     })
     data = {'text': u'śmietnik', 'number': 12}
     observation = Observation.create(
         properties=data, creator=creator, location=location,
         category=category, project=category.project, status='active'
     )
     self.assertEqual(observation.properties, data)
예제 #6
0
    def test_validate_full_with_inactive_field(self):
        category = CategoryFactory()
        TextFieldFactory(**{'key': 'text', 'category': category, 'order': 0})
        TextFieldFactory(
            **{
                'key': 'inactive_text',
                'category': category,
                'status': 'inactive',
                'required': True,
                'order': 1
            })
        NumericFieldFactory(**{
            'key': 'number',
            'category': category,
            'order': 2
        })

        observation = ObservationFactory.create(
            **{
                'properties': {
                    'text': 'Text',
                    'number': 12
                },
                'category': category,
                'project': category.project
            })

        updater = UserF()
        update = {'text': 'Udpated Text', 'number': 13}
        Observation.validate_full(category=category, data=update)
        observation.update(properties=update, updator=updater)

        self.assertEqual(observation.properties, {
            'text': 'Udpated Text',
            'number': 13
        })
        self.assertEqual(observation.version, 2)