Ejemplo n.º 1
0
    def test_post_save_video_file_count_update(self):
        observation = ObservationFactory()
        video_file = VideoFile.objects.create(
            name='Test name',
            description='Test Description',
            contribution=observation,
            creator=UserFactory.create(),
            video=get_image(),
            youtube_link='http://example.com/1122323',
            swf_link='http://example.com/1122323.swf'
        )
        VideoFile.objects.create(
            status='deleted',
            name='Test name',
            description='Test Description',
            contribution=observation,
            creator=UserFactory.create(),
            video=get_image(),
            youtube_link='http://example.com/1122323',
            swf_link='http://example.com/1122323.swf'
        )

        post_save_count_update(
            VideoFile,
            instance=video_file,
            created=True)

        observation.refresh_from_db()
        self.assertEqual(observation.num_media, 1)
        self.assertEqual(observation.num_comments, 0)
Ejemplo n.º 2
0
    def test(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
        })

        ObservationFactory.create_batch(5, **{
            'project': project,
            'category': category_1,
            'properties': {'text': 'yes'}}
        )

        viewer = UserF.create()
        view = GroupingFactory(add_viewers=[viewer], **{'project': project})
        RuleFactory(**{
            'grouping': view,
            'category': category_1,
            'constraints': {'text': 'yes'}
        })

        serializer = GroupingSerializer(view, context={'user': admin})
        self.assertEqual(len(serializer.get_data(view).get('features')), 5)
        self.assertEqual(serializer.get_num_contributions(view), 5)
Ejemplo n.º 3
0
    def test(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})

        ObservationFactory.create_batch(
            5, **{
                'project': project,
                'category': category_1,
                'properties': {
                    'text': 'yes'
                }
            })

        viewer = UserF.create()
        view = GroupingFactory(add_viewers=[viewer], **{'project': project})
        RuleFactory(
            **{
                'grouping': view,
                'category': category_1,
                'constraints': {
                    'text': 'yes'
                }
            })

        serializer = GroupingSerializer(view, context={'user': admin})
        self.assertEqual(len(serializer.get_data(view).get('features')), 5)
        self.assertEqual(serializer.get_num_contributions(view), 5)
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
    def test_post_save_document_file_count_update(self):
        observation = ObservationFactory()
        document_file = DocumentFile.objects.create(
            name='Test name',
            description='Test Description',
            contribution=observation,
            creator=UserFactory.create(),
            document=get_pdf_document()
        )
        DocumentFile.objects.create(
            status='deleted',
            name='Test name',
            description='Test Description',
            contribution=observation,
            creator=UserFactory.create(),
            document=get_pdf_document()
        )

        post_save_count_update(
            DocumentFile,
            instance=document_file,
            created=True)

        observation.refresh_from_db()
        self.assertEqual(observation.num_media, 1)
        self.assertEqual(observation.num_comments, 0)
Ejemplo n.º 6
0
    def test_post_save_audio_file_count_update(self):
        observation = ObservationFactory()
        audio_file = AudioFile.objects.create(
            name='Test name',
            description='Test Description',
            contribution=observation,
            creator=UserFactory.create(),
            audio=get_image()
        )
        AudioFile.objects.create(
            status='deleted',
            name='Test name',
            description='Test Description',
            contribution=observation,
            creator=UserFactory.create(),
            audio=get_image()
        )

        post_save_count_update(
            AudioFile,
            instance=audio_file,
            created=True)

        observation.refresh_from_db()
        self.assertEqual(observation.num_media, 1)
        self.assertEqual(observation.num_comments, 0)
Ejemplo n.º 7
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)
Ejemplo n.º 8
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)
Ejemplo n.º 9
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)
Ejemplo n.º 10
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)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
    def test_download_data_as_tsv(self):
        project = ProjectFactory.create(**{'isprivate': False})
        EpiCollectProjectModel.objects.create(project=project, enabled=True)
        ObservationFactory.create_batch(
            20, **{'project': project, 'properties': {'key': 'value'}})

        factory = APIRequestFactory()
        url = reverse('geokey_epicollect:download', kwargs={
            'project_id': project.id
        }) + '?xml=false'
        request = factory.get(url)
        view = EpiCollectDownloadView.as_view()
        response = view(request, project_id=project.id)
        self.assertEqual(response.status_code, 200)
Ejemplo n.º 15
0
    def test_get_user_contributions(self):
        user = UserFactory.create()
        project = ProjectFactory.create()
        ObservationFactory.create_batch(
            5,
            **{'creator': user, 'project': project}
        )
        serializer = ProjectSerializer(project, context={'user': user})
        self.assertEqual(5, serializer.get_user_contributions(project))

        serializer = ProjectSerializer(
            project, context={'user': AnonymousUser()}
        )
        self.assertEqual(0, serializer.get_user_contributions(project))
Ejemplo n.º 16
0
    def test_get_user_contributions(self):
        user = UserFactory.create()
        project = ProjectFactory.create()
        ObservationFactory.create_batch(
            5,
            **{'creator': user, 'project': project}
        )
        serializer = ProjectSerializer(project, context={'user': user})
        self.assertEqual(5, serializer.get_user_contributions(project))

        serializer = ProjectSerializer(
            project, context={'user': AnonymousUser()}
        )
        self.assertEqual(0, serializer.get_user_contributions(project))
Ejemplo n.º 17
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)
Ejemplo n.º 18
0
    def test_post_image_file_save(self):
        observation = ObservationFactory()
        video_file = VideoFile.objects.create(
            name='Test name',
            description='Test Description',
            contribution=observation,
            creator=UserF.create(),
            video=get_image(),
            youtube_link='http://example.com/1122323',
            swf_link='http://example.com/1122323.swf'
        )
        VideoFile.objects.create(
            status='deleted',
            name='Test name',
            description='Test Description',
            contribution=observation,
            creator=UserF.create(),
            video=get_image(),
            youtube_link='http://example.com/1122323',
            swf_link='http://example.com/1122323.swf'
        )

        post_save_media_file_update(VideoFile, instance=video_file)
        self.assertEqual(video_file.contribution.num_media, 1)
        self.assertEqual(video_file.contribution.num_comments, 0)
Ejemplo n.º 19
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)
Ejemplo n.º 20
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')
Ejemplo n.º 21
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')
Ejemplo n.º 22
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')
Ejemplo n.º 23
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)
Ejemplo n.º 24
0
    def test_get_created_before_and_after(self):
        user = UserFactory.create()
        project = ProjectFactory.create()
        category_1 = CategoryFactory(**{'project': project})

        UserGroupFactory.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)
Ejemplo n.º 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.assertEqual(image_file.status, 'deleted')
Ejemplo n.º 26
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')
Ejemplo n.º 27
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')
Ejemplo n.º 28
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')
Ejemplo n.º 29
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')
Ejemplo n.º 30
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')
Ejemplo n.º 31
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')
Ejemplo n.º 32
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')
Ejemplo n.º 33
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')
Ejemplo n.º 34
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)
Ejemplo n.º 35
0
    def test_post_save_audio_file_count_update(self):
        observation = ObservationFactory()
        audio_file = AudioFile.objects.create(name='Test name',
                                              description='Test Description',
                                              contribution=observation,
                                              creator=UserFactory.create(),
                                              audio=get_image())
        AudioFile.objects.create(status='deleted',
                                 name='Test name',
                                 description='Test Description',
                                 contribution=observation,
                                 creator=UserFactory.create(),
                                 audio=get_image())

        post_save_count_update(AudioFile, instance=audio_file, created=True)

        observation.refresh_from_db()
        self.assertEqual(observation.num_media, 1)
        self.assertEqual(observation.num_comments, 0)
Ejemplo n.º 36
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')
Ejemplo n.º 37
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')
Ejemplo n.º 38
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')
Ejemplo n.º 39
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')
Ejemplo n.º 40
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')
Ejemplo n.º 41
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)
Ejemplo n.º 42
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')
Ejemplo n.º 43
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)
Ejemplo n.º 44
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)
Ejemplo n.º 45
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)
Ejemplo n.º 46
0
    def test_get_data_with_none_rule(self):
        user = UserFactory.create()
        project = ProjectFactory.create()
        category_1 = CategoryFactory(**{'project': project})
        category_2 = CategoryFactory(**{'project': project})
        category_3 = CategoryFactory(**{'project': project})

        UserGroupFactory.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)
Ejemplo n.º 47
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)
Ejemplo n.º 48
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)
Ejemplo n.º 49
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)
Ejemplo n.º 50
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)
Ejemplo n.º 51
0
    def test_post_save_document_file_count_update(self):
        observation = ObservationFactory()
        document_file = DocumentFile.objects.create(
            name='Test name',
            description='Test Description',
            contribution=observation,
            creator=UserFactory.create(),
            document=get_pdf_document())
        DocumentFile.objects.create(status='deleted',
                                    name='Test name',
                                    description='Test Description',
                                    contribution=observation,
                                    creator=UserFactory.create(),
                                    document=get_pdf_document())

        post_save_count_update(DocumentFile,
                               instance=document_file,
                               created=True)

        observation.refresh_from_db()
        self.assertEqual(observation.num_media, 1)
        self.assertEqual(observation.num_comments, 0)
Ejemplo n.º 52
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)
Ejemplo n.º 53
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)
Ejemplo n.º 54
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)
Ejemplo n.º 55
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)