示例#1
0
    def test_get_update_projects(self):
        # Setup everything
        updated_project_1 = ProjectF.create()
        updated_project_2 = ProjectF.create()
        not_updated_project = ProjectF.create()

        for x in range(0, 2):
            for project in [
                    updated_project_1, updated_project_2, not_updated_project
            ]:
                ObservationFactory.create(project=project)

        updated = ObservationFactory.create(project=updated_project_2)

        yesterday = datetime.utcnow().replace(tzinfo=utc)

        ObservationFactory.create(project=updated_project_1)
        updated.update(properties={'key': 'value'}, updator=UserF.create())

        # the tests
        command = Command()
        updated_projects = command.get_updated_projects(yesterday)
        self.assertIn(updated_project_1, updated_projects)
        self.assertIn(updated_project_2, updated_projects)
        self.assertNotIn(not_updated_project, updated_projects)
示例#2
0
    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)
示例#3
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)
示例#4
0
    def setUp(self):
        """Setup for test."""
        self.user = UserFactory.create()
        self.category_tweet = CategoryFactory.create(name="Tweets")

        self.observation = ObservationFactory.create()
        self.observation_tweet = ObservationFactory.create(
            category=self.category_tweet)
示例#5
0
    def setUp(self):
        """Setup for test."""
        self.user = UserFactory.create()
        self.category_tweet = CategoryFactory.create(
            name="Tweets")

        self.observation = ObservationFactory.create()
        self.observation_tweet = ObservationFactory.create(
            category=self.category_tweet)
示例#6
0
    def test_log_create_draft(self):
        """Test when observation gets created as a draft."""
        log_count_init = LoggerHistory.objects.count()
        ObservationFactory.create(**{
            'status': 'draft',
            'creator': self.user,
            'location': self.location,
            'project': self.project,
            'category': self.category})

        self.assertEqual(LoggerHistory.objects.count(), log_count_init)
示例#7
0
    def test_daily_digest(self):
        do_not_notify = UserF.create()
        moderator = UserF.create()
        contributor = UserF.create()
        UserF.create()

        project = ProjectF.create(
            add_admins=[moderator],
            add_contributors=[contributor]
        )
        AdminsFactory.create(**{
            'project': project,
            'user': do_not_notify,
            'contact': False
        })

        suspended = ObservationFactory.create(
            created_at=(datetime.utcnow() - timedelta(2)).replace(tzinfo=utc),
            project=project,
            creator=contributor,
            status='active'
        )

        updated = ObservationFactory.create(
            project=project,
            creator=contributor
        )

        approved = ObservationFactory.create(
            project=project,
            creator=contributor,
            status='pending'
        )

        yesterday = datetime.utcnow().replace(tzinfo=utc)

        suspended.update(
            properties=None,
            status='pending',
            updator=UserF.create()
        )
        updated.update(properties={'key': 'value'}, updator=UserF.create())
        approved.update(properties=None, status='active', updator=moderator)

        for user in [moderator, contributor]:
            ObservationFactory.create(
                project=project,
                creator=user,
                status='pending'
            )

        command = Command()
        command.send_daily_digest(yesterday)
        self.assertEquals(len(mail.outbox), 3)
示例#8
0
    def test_log_create_draft(self):
        """Test when observation gets created as a draft."""
        log_count_init = LoggerHistory.objects.count()
        ObservationFactory.create(
            **{
                'status': 'draft',
                'creator': self.user,
                'location': self.location,
                'project': self.project,
                'category': self.category
            })

        self.assertEqual(LoggerHistory.objects.count(), log_count_init)
示例#9
0
    def test_delete_with_observation(self):
        category = CategoryFactory.create()
        observation = ObservationFactory.create(**{"category": category})
        category.delete()

        Category.objects.get(pk=category.id)
        Observation.objects.get(pk=observation.id)
示例#10
0
    def test_delete_with_observation(self):
        category = CategoryFactory.create()
        observation = ObservationFactory.create(**{'category': category})
        category.delete()

        Category.objects.get(pk=category.id)
        Observation.objects.get(pk=observation.id)
 def test_get_type_name(self):
     audio_file = AudioFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         audio=get_image())
     self.assertEqual(audio_file.type_name, 'AudioFile')
 def test_get_type_name(self):
     image_file = ImageFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         image=get_image())
     self.assertEqual(image_file.type_name, 'ImageFile')
 def test_get_type_name(self):
     document_file = DocumentFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         document=get_pdf_document())
     self.assertEqual(document_file.type_name, 'DocumentFile')
示例#14
0
 def test_get_type_name(self):
     document_file = DocumentFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         document=get_pdf_document()
     )
     self.assertEqual(document_file.type_name, 'DocumentFile')
示例#15
0
 def test_delete_file(self):
     audio_file = AudioFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         audio=get_image())
     audio_file.delete()
     self.assertEquals(audio_file.status, 'deleted')
 def test_delete_file(self):
     image_file = ImageFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         image=get_image())
     image_file.delete()
     self.assertEqual(image_file.status, 'deleted')
示例#17
0
 def test_get_type_name(self):
     image_file = ImageFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         image=get_image()
     )
     self.assertEqual(image_file.type_name, 'ImageFile')
 def test_delete_file(self):
     document_file = DocumentFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         document=get_pdf_document())
     document_file.delete()
     self.assertEquals(document_file.status, 'deleted')
示例#19
0
 def test_get_type_name(self):
     audio_file = AudioFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         audio=get_image()
     )
     self.assertEqual(audio_file.type_name, 'AudioFile')
示例#20
0
 def test_delete_file(self):
     document_file = DocumentFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         document=get_pdf_document()
     )
     document_file.delete()
     self.assertEquals(document_file.status, 'deleted')
示例#21
0
    def test_daily_digest(self):
        do_not_notify = UserF.create()
        moderator = UserF.create()
        contributor = UserF.create()
        UserF.create()

        project = ProjectF.create(add_admins=[moderator],
                                  add_contributors=[contributor])
        AdminsFactory.create(**{
            'project': project,
            'user': do_not_notify,
            'contact': False
        })

        suspended = ObservationFactory.create(
            created_at=(datetime.utcnow() - timedelta(2)).replace(tzinfo=utc),
            project=project,
            creator=contributor,
            status='active')

        updated = ObservationFactory.create(project=project,
                                            creator=contributor)

        approved = ObservationFactory.create(project=project,
                                             creator=contributor,
                                             status='pending')

        yesterday = datetime.utcnow().replace(tzinfo=utc)

        suspended.update(properties=None,
                         status='pending',
                         updator=UserF.create())
        updated.update(properties={'key': 'value'}, updator=UserF.create())
        approved.update(properties=None, status='active', updator=moderator)

        for user in [moderator, contributor]:
            ObservationFactory.create(project=project,
                                      creator=user,
                                      status='pending')

        command = Command()
        command.send_daily_digest(yesterday)
        self.assertEquals(len(mail.outbox), 3)
 def test_get_type_name(self):
     video_file = VideoFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         video=get_image(),
         youtube_link='http://example.com/1122323',
         swf_link='http://example.com/1122323.swf')
     self.assertEqual(video_file.type_name, 'VideoFile')
示例#23
0
    def test_create_image(self):
        image_file = MediaFile.objects.create(
            name='Test name',
            description='Test Description',
            contribution=ObservationFactory.create(),
            creator=UserFactory.create(),
            the_file=get_image())

        self.assertIsNotNone(image_file.image)
        self.assertEqual(image_file.type_name, 'ImageFile')
示例#24
0
 def test_delete_file(self):
     audio_file = AudioFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         audio=get_image()
     )
     audio_file.delete()
     self.assertEqual(audio_file.status, 'deleted')
示例#25
0
 def test_delete_file(self):
     image_file = ImageFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         image=get_image()
     )
     image_file.delete()
     self.assertEquals(image_file.status, 'deleted')
示例#26
0
 def test_delete_file(self):
     video_file = VideoFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         video=get_image(),
         youtube_link='http://example.com/1122323',
         swf_link='http://example.com/1122323.swf')
     video_file.delete()
     self.assertEquals(video_file.status, 'deleted')
示例#27
0
 def test_get_type_name(self):
     video_file = VideoFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         video=get_image(),
         youtube_link='http://example.com/1122323',
         swf_link='http://example.com/1122323.swf'
     )
     self.assertEqual(video_file.type_name, 'VideoFile')
示例#28
0
    def test_create_image(self):
        image_file = MediaFile.objects.create(
            name='Test name',
            description='Test Description',
            contribution=ObservationFactory.create(),
            creator=UserF.create(),
            the_file=get_image()
        )

        self.assertIsNotNone(image_file.image)
        self.assertEqual(image_file.type_name, 'ImageFile')
示例#29
0
 def test_delete_file(self):
     video_file = VideoFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserFactory.create(),
         video=get_image(),
         youtube_link='http://example.com/1122323',
         swf_link='http://example.com/1122323.swf'
     )
     video_file.delete()
     self.assertEquals(video_file.status, 'deleted')
示例#30
0
    def test_get_data_combined(self):
        user = UserF.create()
        project = ProjectF.create(add_admins=[user])
        category_1 = CategoryFactory(**{'project': project})
        category_2 = CategoryFactory(**{'project': project})
        category_3 = CategoryFactory(**{'project': project})
        view = GroupingFactory(**{'project': project})
        for x in range(0, 5):
            ObservationFactory.create(**{
                'project': project,
                'category': category_1}
            )
            ObservationFactory.create(**{
                'project': project,
                'category': category_2}
            )
            ObservationFactory.create(**{
                'project': project,
                'category': category_3}
            )

        RuleFactory(**{
            'grouping': view,
            'category': category_1
        })
        RuleFactory(**{
            'grouping': view,
            'category': category_2
        })

        self.assertEqual(view.data(user).count(), 10)
        for observation in view.data(user):
            self.assertNotEqual(
                observation.category, category_3)
示例#31
0
    def test_get_data_text_filter(self):
        user = UserFactory.create()
        project = ProjectFactory.create()

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

        UserGroupFactory.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)
示例#32
0
    def test_get_update_stats(self):
        moderator = UserF.create()
        contributor = UserF.create()
        some_dude = UserF.create()

        project = ProjectF.create(add_admins=[moderator],
                                  add_contributors=[contributor])

        suspended = ObservationFactory.create(
            created_at=(datetime.utcnow() - timedelta(2)).replace(tzinfo=utc),
            project=project,
            creator=contributor,
            status='active')

        updated = ObservationFactory.create(project=project,
                                            creator=contributor)

        reported = ObservationFactory.create(project=project,
                                             creator=contributor)

        approved = ObservationFactory.create(project=project,
                                             creator=contributor,
                                             status='pending')

        yesterday = datetime.utcnow().replace(tzinfo=utc)

        suspended.update(properties=None,
                         status='pending',
                         updator=UserF.create())

        reported.update(properties=None,
                        status='review',
                        updator=UserF.create())

        updated.update(properties={'key': 'value'}, updator=UserF.create())
        approved.update(properties=None, status='active', updator=moderator)

        for user in [moderator, contributor]:
            ObservationFactory.create(project=project,
                                      creator=user,
                                      status='pending')

        command = Command()

        report = command.get_updated_items(project, moderator, yesterday)
        to_moderate = report.get('to_moderate')
        self.assertEqual(len(to_moderate.get('new')), 2)
        self.assertEqual(len(to_moderate.get('suspended')), 1)
        self.assertIsNone(report.get('yours'))

        report = command.get_updated_items(project, contributor, yesterday)

        yours = report.get('yours')
        self.assertEqual(len(yours.get('changed')), 4)
        self.assertEqual(len(yours.get('approved')), 1)
        self.assertEqual(len(yours.get('reported')), 1)
        self.assertEqual(len(yours.get('suspended')), 1)

        report = command.get_updated_items(project, some_dude, yesterday)
        self.assertEqual(report, None)
示例#33
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)
示例#34
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)
示例#35
0
    def test_get_data_text_filter(self):
        admin = UserF.create()
        project = ProjectF.create(add_admins=[admin])
        category_1 = CategoryFactory(**{'project': project})
        TextFieldFactory(**{
            'key': 'text',
            'category': category_1
        })
        category_2 = CategoryFactory(**{'project': project})
        TextFieldFactory(**{
            'key': 'bla',
            'category': category_2
        })

        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,
                'status': 'pending',
                'properties': {'text': 'yes ' + str(x)}}
            )

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

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

        viewer = UserF.create()
        view = GroupingFactory(add_viewers=[viewer], **{'project': project})
        RuleFactory(**{
            'grouping': view,
            'category': category_1,
            'constraints': {'text': 'yes'}
        })
        self.assertEqual(view.data(admin).count(), 10)
        self.assertEqual(view.data(viewer).count(), 5)
示例#36
0
    def test_get_context_data(self):
        """Test getting context data."""
        user = UserFactory.create(**{'is_superuser': True})

        # 1 contribution, 1 comment
        project_1 = ProjectFactory.create()
        category_1 = CategoryFactory.create(project=project_1)
        contribution_1 = ObservationFactory.create(
            project=project_1,
            category=category_1)
        CommentFactory.create(commentto=contribution_1)

        # 2 contributions (1 deleted), 2 comments
        project_2 = ProjectFactory.create(add_admins=[user])
        category_2 = CategoryFactory.create(project=project_2)
        contribution_2 = ObservationFactory.create(
            project=project_2,
            category=category_2)
        CommentFactory.create(commentto=contribution_2)
        contribution_3 = ObservationFactory.create(
            project=project_2,
            category=category_2)
        CommentFactory.create(commentto=contribution_3)
        contribution_3.delete()

        # 2 contributions (1 deleted), 3 comments (1 deleted)
        project_3 = ProjectFactory.create(add_moderators=[user])
        category_3 = CategoryFactory.create(project=project_3)
        contribution_4 = ObservationFactory.create(
            project=project_3,
            category=category_3)
        CommentFactory.create(commentto=contribution_4)
        comment_to_delete = CommentFactory.create(commentto=contribution_4)
        comment_to_delete.delete()
        contribution_5 = ObservationFactory.create(
            project=project_3,
            category=category_3)
        CommentFactory.create(commentto=contribution_5)
        contribution_5.delete()

        # 1 contribution, 2 comments (1 deleted)
        project_4 = ProjectFactory.create(add_contributors=[user])
        category_4 = CategoryFactory.create(project=project_4)
        contribution_6 = ObservationFactory.create(
            project=project_4,
            category=category_4)
        CommentFactory.create(commentto=contribution_6)
        comment_to_delete = CommentFactory.create(commentto=contribution_6)
        comment_to_delete.delete()

        view = ManageProjects()
        context = view.get_context_data()
        self.assertEqual(len(context.get('projects')), 4)

        for project in context.get('projects'):
            project.refresh_from_db()
            self.assertEqual(project.contributions_count, 1)
            self.assertEqual(project.comments_count, 1)
            self.assertEqual(project.media_count, 0)
示例#37
0
    def test_create_not_supported(self):
        xyz_file = StringIO()
        xyz = Image.new('RGBA', size=(50, 50), color=(256, 0, 0))
        xyz.save(xyz_file, 'png')
        xyz_file.seek(0)

        the_file = ContentFile(xyz_file.read(), 'test.xyz')
        the_file.content_type = 'chemical/x-xyz'

        MediaFile.objects.create(name='Test name',
                                 description='Test Description',
                                 contribution=ObservationFactory.create(),
                                 creator=UserFactory.create(),
                                 the_file=the_file)
示例#38
0
    def test_get_data_multiple_lookup_filter(self):
        user = UserF.create()
        project = ProjectF.create(add_admins=[user])
        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
        })

        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]}
            })

        view = GroupingFactory(**{'project': project})
        RuleFactory(**{
            'grouping': view,
            'category': category_1,
            'constraints': {'lookup': [lookup_1.id, lookup_2.id]}
        })

        self.assertEqual(view.data(user).count(), 10)
示例#39
0
    def test_get_data_lookup_filter(self):
        user = UserFactory.create()
        project = ProjectFactory.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
        })

        UserGroupFactory.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)
示例#40
0
 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.location = LocationFactory.create(**{
         'creator': self.user})
     self.observation = ObservationFactory.create(**{
         'creator': self.user,
         'location': self.location,
         'project': self.project,
         'category': self.category})
示例#41
0
    def test_get_update_projects(self):
        # Setup everything
        updated_project_1 = ProjectF.create()
        updated_project_2 = ProjectF.create()
        not_updated_project = ProjectF.create()

        for x in range(0, 2):
            for project in [
                    updated_project_1, updated_project_2, not_updated_project]:
                ObservationFactory.create(project=project)

        updated = ObservationFactory.create(project=updated_project_2)

        yesterday = datetime.utcnow().replace(tzinfo=utc)

        ObservationFactory.create(project=updated_project_1)
        updated.update(properties={'key': 'value'}, updator=UserF.create())

        # the tests
        command = Command()
        updated_projects = command.get_updated_projects(yesterday)
        self.assertIn(updated_project_1, updated_projects)
        self.assertIn(updated_project_2, updated_projects)
        self.assertNotIn(not_updated_project, updated_projects)
示例#42
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
        )
示例#43
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)
示例#44
0
    def test_get_data_subset_user_group_filter(self):
        user = UserFactory.create()
        project = ProjectFactory.create()

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

        UserGroupFactory.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
        )
示例#45
0
    def test_create_not_supported(self):
        xyz_file = StringIO()
        xyz = Image.new('RGBA', size=(50, 50), color=(256, 0, 0))
        xyz.save(xyz_file, 'png')
        xyz_file.seek(0)

        the_file = ContentFile(xyz_file.read(), 'test.xyz')
        the_file.content_type = 'chemical/x-xyz'

        MediaFile.objects.create(
            name='Test name',
            description='Test Description',
            contribution=ObservationFactory.create(),
            creator=UserF.create(),
            the_file=the_file
        )
示例#46
0
 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.location = LocationFactory.create(**{'creator': self.user})
     self.observation = ObservationFactory.create(
         **{
             'creator': self.user,
             'location': self.location,
             'project': self.project,
             'category': self.category
         })
示例#47
0
    def test_get_context_data(self):
        """Test getting context data."""
        user = UserFactory.create(**{'is_superuser': True})

        # 1 contribution, 1 comment
        project_1 = ProjectFactory.create()
        category_1 = CategoryFactory.create(project=project_1)
        contribution_1 = ObservationFactory.create(project=project_1,
                                                   category=category_1)
        CommentFactory.create(commentto=contribution_1)

        # 2 contributions (1 deleted), 2 comments
        project_2 = ProjectFactory.create(add_admins=[user])
        category_2 = CategoryFactory.create(project=project_2)
        contribution_2 = ObservationFactory.create(project=project_2,
                                                   category=category_2)
        CommentFactory.create(commentto=contribution_2)
        contribution_3 = ObservationFactory.create(project=project_2,
                                                   category=category_2)
        CommentFactory.create(commentto=contribution_3)
        contribution_3.delete()

        # 2 contributions (1 deleted), 3 comments (1 deleted)
        project_3 = ProjectFactory.create(add_moderators=[user])
        category_3 = CategoryFactory.create(project=project_3)
        contribution_4 = ObservationFactory.create(project=project_3,
                                                   category=category_3)
        CommentFactory.create(commentto=contribution_4)
        comment_to_delete = CommentFactory.create(commentto=contribution_4)
        comment_to_delete.delete()
        contribution_5 = ObservationFactory.create(project=project_3,
                                                   category=category_3)
        CommentFactory.create(commentto=contribution_5)
        contribution_5.delete()

        # 1 contribution, 2 comments (1 deleted)
        project_4 = ProjectFactory.create(add_contributors=[user])
        category_4 = CategoryFactory.create(project=project_4)
        contribution_6 = ObservationFactory.create(project=project_4,
                                                   category=category_4)
        CommentFactory.create(commentto=contribution_6)
        comment_to_delete = CommentFactory.create(commentto=contribution_6)
        comment_to_delete.delete()

        view = ManageProjects()
        context = view.get_context_data()
        self.assertEqual(len(context.get('projects')), 4)

        for project in context.get('projects'):
            project.refresh_from_db()
            self.assertEqual(project.contributions_count, 1)
            self.assertEqual(project.comments_count, 1)
            self.assertEqual(project.media_count, 0)
示例#48
0
    def test_get_data_category_filter_and_search(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_1.id: {}}
            }
        )

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

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

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

            ObservationFactory.create(**{
                'project': project,
                'category': category_2}
            )
        self.assertEqual(
            project.get_all_contributions(user, search='blah').count(),
            5
        )
示例#49
0
    def test_get_data_no_rules(self):
        admin = UserF.create()
        project = ProjectF.create(add_admins=[admin])
        category_1 = CategoryFactory(**{'project': project})
        TextFieldFactory(**{
            'key': 'text',
            'category': category_1
        })
        category_2 = CategoryFactory(**{'project': project})
        TextFieldFactory(**{
            'key': 'bla',
            'category': category_2
        })

        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,
                'status': 'pending',
                'properties': {'text': 'yes ' + str(x)}}
            )

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

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

        view = GroupingFactory(**{'project': project})
        self.assertEqual(view.data(admin).count(), 0)
示例#50
0
    def test_log_create(self):
        """Test when observation gets created."""
        log_count_init = LoggerHistory.objects.count()
        observation = ObservationFactory.create(
            **{
                'creator': self.user,
                'location': self.location,
                'project': self.project,
                '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, None)
        self.assertEqual(log.location, {
            'id': str(self.location.id),
            'name': self.location.name
        })
        self.assertEqual(log.observation, {'id': str(observation.id)})
        self.assertEqual(log.comment, None)
        self.assertEqual(log.subset, None)
        self.assertEqual(
            log.action, {
                'id': 'created',
                'class': 'Observation',
                'field': 'status',
                'value': observation.status
            })
        self.assertEqual(log_count, log_count_init + 1)
        self.assertEqual(log.historical, None)
示例#51
0
    def test_upload_image_with_wrong_file_name(self):
        image = get_image()
        project = ProjectFactory.create()
        EpiCollectProjectModel.objects.create(project=project, enabled=True)
        contribution = ObservationFactory.create(**{'project': project})
        EpiCollectMedia.objects.create(
            contribution=contribution,
            file_name='file_name.jpg'
        )

        data = {'name': image}
        factory = APIRequestFactory()
        url = reverse('geokey_epicollect:upload', kwargs={
            'project_id': project.id
        })
        request = factory.post(url + '?type=thumbnail', data)

        view = EpiCollectUploadView.as_view()
        response = view(request, project_id=project.id)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, '0')
示例#52
0
    def test_get_data_category_filter(self):
        user = UserF.create()
        project = ProjectF.create()

        category_1 = CategoryFactory(**{'project': project})
        category_2 = CategoryFactory(**{'project': project})

        UserGroupF.create(
            add_users=[user],
            **{
                '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,
                'status': 'pending'}
            )

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

            ObservationFactory.create(**{
                'project': project,
                'category': category_2}
            )
        self.assertEqual(project.get_all_contributions(user).count(), 10)
示例#53
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)
示例#54
0
    def test_get_data_min_max_date_filter(self):
        user = UserFactory.create()
        project = ProjectFactory.create()
        category_1 = CategoryFactory(**{'project': project})
        DateFieldFactory(**{
            'key': 'date',
            'category': category_1
        })
        category_2 = CategoryFactory(**{'project': project})
        DateFieldFactory(**{
            'key': 'bla',
            'category': category_2
        })

        UserGroupFactory.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)
示例#55
0
    def test_get_data_max_time_filter(self):
        user = UserF.create()
        project = ProjectF.create(add_admins=[user])
        category_1 = CategoryFactory(**{'project': project})
        TimeFieldFactory(**{
            'key': 'time',
            'category': category_1
        })
        category_2 = CategoryFactory(**{'project': project})
        TimeFieldFactory(**{
            'key': 'bla',
            'category': category_2
        })

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

            ObservationFactory.create(**{
                'project': project,
                'category': category_1,
                'properties': {'time': '18:00'}
            })

            ObservationFactory.create(**{
                'project': project,
                'category': category_2,
                'properties': {'bla': '11:00'}
            })

        view = GroupingFactory(**{'project': project})
        RuleFactory(**{
            'grouping': view,
            'category': category_1,
            'constraints': {'time': {
                'maxval': '12:00'}
            }
        })

        self.assertEqual(view.data(user).count(), 5)