Exemple #1
0
    def test_get_data_with_none_rule(self):
        user = UserF.create()
        project = ProjectF.create()
        category_1 = CategoryFactory(**{'project': project})
        category_2 = CategoryFactory(**{'project': project})
        category_3 = CategoryFactory(**{'project': project})

        UserGroupF.create(
            add_users=[user],
            **{'project': project, 'filters': None}
        )

        ObservationFactory.create_batch(5, **{
            'project': project,
            'category': category_1}
        )
        ObservationFactory.create_batch(5, **{
            'project': project,
            'category': category_2}
        )
        ObservationFactory.create_batch(5, **{
            'project': project,
            'category': category_3}
        )

        self.assertEqual(project.get_all_contributions(user).count(), 15)
Exemple #2
0
    def test_get_data_min_max_number_filter(self):
            user = UserF.create()
            project = ProjectF.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
            })

            UserGroupF.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)
Exemple #3
0
    def test_get_data_lookup_filter(self):
        user = UserF.create()
        project = ProjectF.create()
        category_1 = CategoryFactory(**{'project': project})

        lookup_field = LookupFieldFactory(**{
            'key': 'lookup',
            'category': category_1
        })
        lookup_1 = LookupValueFactory(**{
            'name': 'Ms. Piggy',
            'field': lookup_field
        })
        lookup_2 = LookupValueFactory(**{
            'name': 'Kermit',
            'field': lookup_field
        })
        category_2 = CategoryFactory(**{'project': project})
        lookup_field_2 = LookupFieldFactory(**{
            'key': 'bla',
            'category': category_2
        })
        lookup_3 = LookupValueFactory(**{
            'name': 'Gonzo',
            'field': lookup_field_2
        })

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

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

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

            ObservationFactory.create(**{
                'project': project,
                'category': category_2,
                'properties': {'bla': lookup_3.id}
            })
        self.assertEqual(project.get_all_contributions(user).count(), 10)
Exemple #4
0
    def test_get_data_text_filter(self):
        user = UserF.create()
        project = ProjectF.create()

        category_1 = CategoryFactory(**{'project': project})
        TextFieldFactory(**{
            'key': 'text',
            'category': category_1
        })
        category_2 = CategoryFactory(**{'project': project})
        TextFieldFactory(**{
            'key': 'bla',
            'category': category_2
        })

        UserGroupF.create(
            add_users=[user],
            **{
                'project': project,
                'filters': {category_1.id: {'text': 'yes'}}
            }
        )

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

            ObservationFactory.create(**{
                'project': project,
                'category': category_1,
                'status': 'pending',
                'properties': {'text': 'yes %s' % x}}
            )

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

            ObservationFactory.create(**{
                'project': project,
                'category': category_2,
                'properties': {'bla': 'yes %s' % x}}
            )

        self.assertEqual(project.get_all_contributions(user).count(), 5)
Exemple #5
0
    def test_get_data_min_max_date_filter(self):
        user = UserF.create()
        project = ProjectF.create()
        category_1 = CategoryFactory(**{'project': project})
        DateFieldFactory(**{
            'key': 'date',
            'category': category_1
        })
        category_2 = CategoryFactory(**{'project': project})
        DateFieldFactory(**{
            'key': 'bla',
            'category': category_2
        })

        UserGroupF.create(
            add_users=[user],
            **{
                'project': project,
                'filters': {
                    category_1.id: {'date': {
                        'minval': '2014-01-01', 'maxval': '2014-06-09'}
                    }
                }
            }
        )

        for x in range(0, 5):
            ObservationFactory.create(**{
                'project': project,
                'category': category_1,
                'properties': {'date': '2014-04-09'}
            })

            ObservationFactory.create(**{
                'project': project,
                'category': category_1,
                'properties': {'date': '2013-04-09'}
            })

            ObservationFactory.create(**{
                'project': project,
                'category': category_2,
                'properties': {'bla': '2014-04-09'}
            })

        self.assertEqual(project.get_all_contributions(user).count(), 5)
Exemple #6
0
    def test_get_data_subset_user_group_filter(self):
        user = UserF.create()
        project = ProjectF.create()

        category_1 = CategoryFactory(**{'project': project})
        TextFieldFactory.create(**{'key': 'text', 'category': category_1})
        category_2 = CategoryFactory(**{'project': project})

        UserGroupF.create(
            add_users=[user],
            **{
                'project': project,
                'filters': {category_2.id: {}}
            }
        )

        subset = SubsetFactory.create(**{
            'project': project,
            'filters': {category_1.id: {}}
        })

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

            ObservationFactory.create(**{
                'project': project,
                'category': category_1}
            )

            ObservationFactory.create(**{
                'project': project,
                'category': category_1,
                'status': 'pending'}
            )

            ObservationFactory.create(**{
                'project': project,
                'category': category_2}
            )
        self.assertEqual(
            project.get_all_contributions(user, subset=subset.id).count(),
            0
        )
Exemple #7
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)
Exemple #8
0
    def test_delete_with_category_filter(self):
        project = ProjectF.create()
        category = CategoryFactory.create(**{"project": project})
        category_2 = CategoryFactory.create(**{"project": project})

        group = UserGroupF.create(**{"project": project, "filters": {category.id: {}, category_2.id: {}}})

        category.delete()

        ref = UserGroup.objects.get(pk=group.id)
        self.assertEqual(ref.filters, {str(category_2.id): {}})
Exemple #9
0
    def test_delete_with_field_filter(self):
        project = ProjectF.create()
        category = CategoryFactory.create(**{"project": project})
        field = Field.create("name", "key", "description", False, category, "TextField")

        group = UserGroupF.create(**{"project": project, "filters": {category.id: {field.key: "blah"}}})

        field.delete()

        ref = UserGroup.objects.get(pk=group.id)
        self.assertEqual(ref.filters, {str(category.id): {}})
Exemple #10
0
    def test_moderator(self):
        user = UserF.create()

        view = GroupingFactory.create()
        group = UserGroupF.create(
            add_users=[user],
            **{'project': view.project, 'can_moderate': True}
        )
        GroupingUserGroupFactory.create(
            **{'grouping': view, 'usergroup': group,
                'can_view': True, 'can_read': True}
        )

        self.assertTrue(view.can_view(user))
        self.assertTrue(view.can_read(user))
        self.assertTrue(view.can_moderate(user))
Exemple #11
0
    def test_delete_with_category_filter(self):
        project = ProjectF.create()
        category = CategoryFactory.create(**{'project': project})
        category_2 = CategoryFactory.create(**{'project': project})

        group = UserGroupF.create(**{
            'project': project,
            'filters': {
                category.id: {},
                category_2.id: {}
            }
        })

        category.delete()

        ref = UserGroup.objects.get(pk=group.id)
        self.assertEqual(ref.filters, {str(category_2.id): {}})
Exemple #12
0
    def test_delete_with_field_filter(self):
        project = ProjectF.create()
        category = CategoryFactory.create(**{'project': project})
        field = Field.create('name', 'key', 'description', False, category,
                             'TextField')

        group = UserGroupF.create(**{
            'project': project,
            'filters': {
                category.id: {
                    field.key: 'blah'
                }
            }
        })

        field.delete()

        ref = UserGroup.objects.get(pk=group.id)
        self.assertEqual(ref.filters, {str(category.id): {}})
Exemple #13
0
    def test_delete_with_field_filter(self):
        project = ProjectF.create()
        category = CategoryFactory.create(**{'project': project})
        field = Field.create(
            'name', 'key', 'description', False, category,
            'TextField'
        )

        group = UserGroupF.create(
            **{
                'project': project,
                'filters': {
                    category.id: {field.key: 'blah'}}
            }
        )

        field.delete()

        ref = UserGroup.objects.get(pk=group.id)
        self.assertEqual(ref.filters, {str(category.id): {}})