예제 #1
0
    def test_get_created_before_and_after(self):
        user = UserF.create()
        project = ProjectF.create()
        category_1 = CategoryFactory(**{'project': project})

        UserGroupF.create(
            add_users=[user],
            **{
                'project': project,
                'filters': {
                    category_1.id: {
                        'min_date': '2013-01-01 00:00:00',
                        'max_date': '2013-10-01 00:00:00'}
                }
            }
        )

        obs = ObservationFactory.create_batch(5, **{
            'project': project,
            'category': category_1
        })

        for o in obs:
            o.created_at = datetime(2014, 7, 23, 10, 34, 1, tzinfo=pytz.utc)
            o.save()

        obs = ObservationFactory.create_batch(5, **{
            'project': project,
            'category': category_1
        })

        for o in obs:
            o.created_at = datetime(2013, 7, 23, 10, 34, 1, tzinfo=pytz.utc)
            o.save()

        obs = ObservationFactory.create_batch(5, **{
            'project': project,
            'category': category_1
        })

        for o in obs:
            o.created_at = datetime(2012, 7, 23, 10, 34, 1, tzinfo=pytz.utc)
            o.save()

        self.assertEqual(project.get_all_contributions(user).count(), 5)
예제 #2
0
 def test_create_observation_active_default(self):
     creator = UserFactory()
     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)
예제 #3
0
 def test_validate_full_inactive_field(self):
     category = CategoryFactory()
     TextFieldFactory(**{'key': 'text', 'category': category, 'order': 2})
     TextFieldFactory(
         **{
             'key': 'inactive_text',
             'category': category,
             'status': 'inactive',
             'required': True,
             'order': 0
         })
     NumericFieldFactory(**{
         'key': 'number',
         'category': category,
         'order': 1
     })
     data = {'text': 'Text', 'number': 12}
     Observation.validate_full(category=category, data=data)
예제 #4
0
    def test_update_expiry_field_no_expiry_field(self):
        category = CategoryFactory()
        DateTimeFieldFactory(**{
            'key': 'expires_at',
            'category': category
        })
        observation = ObservationFactory(**{
            'project': category.project,
            'category': category,
            'expiry_field': None,
            'properties': None
        })

        observation.update_expiry_field()
        observation.save()

        ref = Observation.objects.get(pk=observation.id)
        self.assertIsNone(ref.expiry_field)
예제 #5
0
    def test_update_display_field_no_display_field(self):
        category = CategoryFactory()
        TextFieldFactory(**{
            'key': 'text',
            'category': category,
            'order': 0
        })
        observation = ObservationFactory(**{
            'project': category.project,
            'category': category,
            'display_field': None,
            'properties': None
        })

        observation.update_display_field()
        observation.save()

        ref = Observation.objects.get(pk=observation.id)
        self.assertIsNone(ref.display_field)
예제 #6
0
    def test_get_with_search(self):
        category = CategoryFactory(**{'project': self.project})
        TextFieldFactory.create(**{'key': 'text', 'category': category})

        for x in range(0, 2):
            ObservationFactory.create(**{
                'project': self.project,
                'category': category,
                'properties': {'text': 'blah'}}
            )

            ObservationFactory.create(**{
                'project': self.project,
                'category': category,
                'properties': {'text': 'blub'}}
            )

        response = self.get(self.admin, search='blah')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(json.loads(response.content).get('features')), 2)
예제 #7
0
    def test_get_created_before_and_after(self):
        user = UserF.create()
        project = ProjectF.create(add_admins=[user])
        category_1 = CategoryFactory(**{'project': project})

        obs = ObservationFactory.create_batch(5, **{
            'project': project,
            'category': category_1
        })

        for o in obs:
            o.created_at = datetime(2014, 7, 23, 10, 34, 1, tzinfo=pytz.utc)
            o.save()

        obs = ObservationFactory.create_batch(5, **{
            'project': project,
            'category': category_1
        })

        for o in obs:
            o.created_at = datetime(2013, 7, 23, 10, 34, 1, tzinfo=pytz.utc)
            o.save()

        obs = ObservationFactory.create_batch(5, **{
            'project': project,
            'category': category_1
        })

        for o in obs:
            o.created_at = datetime(2012, 7, 23, 10, 34, 1, tzinfo=pytz.utc)
            o.save()

        view = GroupingFactory(**{'project': project})
        RuleFactory(**{
            'grouping': view,
            'category': category_1,
            'min_date': datetime(2013, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
            'max_date': datetime(2013, 10, 1, 0, 0, 0, tzinfo=pytz.utc)
        })

        self.assertEqual(view.data(user).count(), 5)
예제 #8
0
    def test_update_expiry_field_empty_properties(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': None
        })

        observation.update_expiry_field()
        observation.save()

        ref = Observation.objects.get(pk=observation.id)
        self.assertEqual(ref.expiry_field, None)
예제 #9
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)
예제 #10
0
    def test_get_with_wrong_bbox(self):
        category = CategoryFactory(**{'project': self.project})
        TextFieldFactory.create(**{'key': 'text', 'category': category})
        geom1 = 'POINT (-55.555 -66.666)'
        geom2 = 'POINT (44.0010 33)'

        loc1 = LocationFactory.create()
        loc1.geometry = geom1
        loc1.save()

        loc2 = LocationFactory.create()
        loc2.geometry = geom2
        loc2.save()

        for x in range(0, 1):
            ObservationFactory.create(
                **{
                    'project': self.project,
                    'category': category,
                    'properties': {
                        'text': 'blah'
                    },
                    'location': loc1
                })

            ObservationFactory.create(
                **{
                    'project': self.project,
                    'category': category,
                    'properties': {
                        'text': 'blub'
                    },
                    'location': loc2
                })

        response = self.get(self.admin, bbox='text_only')
        error = ''
        if 'error' in response.content:
            error = True
        self.assertEqual(error, True)
예제 #11
0
    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,
            'order': 0
        })
        NumericFieldFactory.create(**{
            'key': 'key_2',
            'category': self.category,
            'order': 1
        })

        location = LocationFactory()

        self.observation = ObservationFactory.create(
            **{
                'properties': {
                    "key_1": "value 1",
                    "key_2": 12,
                },
                'category': self.category,
                'project': self.project,
                'location': location,
                'creator': self.admin,
                'status': 'active'
            })

        self.update_data = {"properties": {"version": 1, "key_2": 15}}
예제 #12
0
    def test_update_display_field_empty_properties(self):
        category = CategoryFactory()
        field = TextFieldFactory(**{
            'key': 'text',
            'category': category,
            'order': 0
        })
        category.display_field = field
        category.save()

        observation = ObservationFactory(**{
            'project': category.project,
            'category': category,
            'display_field': None,
            'properties': None
        })

        observation.update_display_field()
        observation.save()

        ref = Observation.objects.get(pk=observation.id)
        self.assertEqual(ref.display_field, 'text:None')
예제 #13
0
    def setUp(self):
        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,
            'order': 0
        })
        NumericFieldFactory.create(**{
            'key': 'key_2',
            'category': self.category,
            'order': 1
        })
예제 #14
0
    def test_get_updated_data(self):
        user = UserF.create()
        project = ProjectF.create(add_admins=[user])
        category_1 = CategoryFactory(**{'project': project})
        TextFieldFactory(**{
            'key': 'text',
            'category': category_1
        })

        observation = ObservationFactory.create(**{
            'project': project,
            'category': category_1,
            'properties': {'text': 'yes to update'}
        })

        for x in range(0, 5):
            ObservationFactory.create(**{
                'project': project,
                'category': category_1,
                'properties': {'text': 'yes ' + str(x)}
            })

            ObservationFactory.create(**{
                'project': project,
                'category': category_1,
                'properties': {'text': 'no ' + str(x)}
            })

        view = GroupingFactory(**{'project': project})
        RuleFactory(**{
            'grouping': view,
            'category': category_1,
            'constraints': {'text': 'yes'}
        })

        updater = UserF()
        update = {'text': 'yes, this has been updated', 'version': 1}
        observation.update(properties=update, updator=updater)
        self.assertEqual(view.data(user).count(), 6)
예제 #15
0
    def test_get_with_bbox_and_search(self):
        category = CategoryFactory(**{'project': self.project})
        TextFieldFactory.create(**{'key': 'text', 'category': category})
        geom1 = 'POINT (-55.555 -66.666)'
        geom2 = 'POINT (44.0010 33)'

        loc1 = LocationFactory.create()
        loc1.geometry = geom1
        loc1.save()

        loc2 = LocationFactory.create()
        loc2.geometry = geom2
        loc2.save()

        for x in range(0, 1):
            ObservationFactory.create(
                **{
                    'project': self.project,
                    'category': category,
                    'properties': {
                        'text': 'blah'
                    },
                    'location': loc1
                })

            ObservationFactory.create(
                **{
                    'project': self.project,
                    'category': category,
                    'properties': {
                        'text': 'blub'
                    },
                    'location': loc2
                })

        response = self.get(self.admin, bbox='41,32,45,35', search='blah')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(json.loads(response.content).get('features')), 1)
예제 #16
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 = UserFactory()
        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)
예제 #17
0
    def test_get_data_multiple_lookup_filter(self):
        user = UserF.create()
        project = ProjectF.create()
        category_1 = CategoryFactory(**{'project': project})
        lookup_field = MultipleLookupFieldFactory(**{
            'key': 'lookup',
            'category': category_1
        })
        lookup_1 = MultipleLookupValueFactory(**{
            'name': 'Ms. Piggy',
            'field': lookup_field
        })
        lookup_2 = MultipleLookupValueFactory(**{
            'name': 'Kermit',
            'field': lookup_field
        })
        lookup_3 = MultipleLookupValueFactory(**{
            'name': 'Gonzo',
            'field': lookup_field
        })
        category_2 = CategoryFactory(**{'project': project})
        lookup_field_2 = MultipleLookupFieldFactory(**{
            'key': 'bla',
            'category': category_2
        })
        lookup_4 = MultipleLookupValueFactory(**{
            'name': 'Gonzo',
            'field': lookup_field_2
        })

        UserGroupF.create(
            add_users=[user],
            **{
                'project': project,
                'filters': {
                    category_1.id: {
                        'lookup': [str(lookup_1.id), str(lookup_2.id)]}
                }
            }
        )

        for x in range(0, 5):
            ObservationFactory.create(**{
                'project': project,
                'category': category_1,
                'properties': {'lookup': [lookup_1.id, lookup_3.id]}
            })

            ObservationFactory.create(**{
                'project': project,
                'category': category_1,
                'properties': {'lookup': [lookup_2.id, lookup_3.id]}
            })

            ObservationFactory.create(**{
                'project': project,
                'category': category_2,
                'properties': {'bla': [lookup_4.id]}
            })

        self.assertEqual(project.get_all_contributions(user).count(), 10)