Esempio n. 1
0
    def test_with_inactive_project(self):
        admin = UserF.create()
        email_user = UserF.create()

        project = ProjectF.create(
            add_admins=[admin],
            **{'status': 'inactive'}
        )

        view = ProjectContactAdmins.as_view()
        url = reverse(
            'api:project_contact_admins',
            kwargs={
                'project_id': project.id
            }
        )
        request = APIRequestFactory().post(
            url,
            json.dumps({'email_text': 'Blah Blah'}),
            content_type='application/json'
        )
        force_authenticate(request, user=email_user)

        response = view(request, project_id=project.id).render()
        self.assertEqual(response.status_code, 404)
        self.assertEquals(len(mail.outbox), 0)
Esempio n. 2
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserF.create()
        self.contributor = UserF.create()
        self.non_member = UserF.create()

        self.public_project = ProjectF.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor],
            **{
                'isprivate': False
            }
        )

        self.private_project = ProjectF.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )

        self.inactive_project = ProjectF.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor],
            **{
                'status': 'inactive'
            }
        )

        self.deleted_project = ProjectF.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor],
            **{'isprivate': False}
        )
        self.deleted_project.delete()
Esempio n. 3
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)
Esempio n. 4
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)
Esempio n. 5
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)
Esempio n. 6
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserF.create()
        self.contributor = UserF.create()
        self.non_member = UserF.create()

        self.project = ProjectF.create(add_admins=[self.admin],
                                       add_contributors=[self.contributor])
Esempio n. 7
0
 def setUp(self):
     self.creator = UserF.create()
     self.admin = UserF.create()
     self.view_member = UserF.create()
     self.contributor = UserF.create()
     self.project = ProjectF.create(add_admins=[self.admin],
                                    add_contributors=[self.contributor],
                                    **{'creator': self.creator})
Esempio n. 8
0
 def setUp(self):
     self.creator = UserF.create()
     self.admin = UserF.create()
     self.view_member = UserF.create()
     self.contributor = UserF.create()
     self.project = ProjectF.create(
         add_admins=[self.admin],
         add_contributors=[self.contributor],
         **{'creator': self.creator}
     )
Esempio n. 9
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserF.create()
        self.contributor = UserF.create()
        self.non_member = UserF.create()

        self.project = ProjectF.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )
Esempio n. 10
0
    def test_all_contacts(self):
        admin = UserF.create()
        contributor = UserF.create()
        email_user = UserF.create()

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

        project.contact_admins(email_user, 'Test email')
        # Should be 2 because project creator is admin too
        self.assertEquals(len(mail.outbox), 2)
Esempio n. 11
0
    def test_all_contacts(self):
        admin = UserF.create()
        contributor = UserF.create()
        email_user = UserF.create()

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

        project.contact_admins(email_user, 'Test email')
        # Should be 2 because project creator is admin too
        self.assertEquals(len(mail.outbox), 2)
Esempio n. 12
0
    def test_post_with_user(self):
        factory = APIRequestFactory()
        user = UserF.create(**{'is_superuser': False})
        user_to_add = UserF.create(**{'is_superuser': False})
        request = factory.post(
            reverse('ajax:superusers_adduser'),
            {'userId': user_to_add.id}
        )
        force_authenticate(request, user=user)
        view = AddSuperUsersAjaxView.as_view()
        response = view(request).render()

        self.assertEqual(response.status_code, 403)
        self.assertEqual(len(User.objects.filter(is_superuser=True)), 0)
Esempio n. 13
0
    def test_selected_contacts(self):
        admin = UserF.create()
        contributor = UserF.create()
        email_user = UserF.create()

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

        admin_rel = Admins.objects.get(project=project, user=admin)
        admin_rel.contact = False
        admin_rel.save()

        project.contact_admins(email_user, 'Test email')
        self.assertEquals(len(mail.outbox), 1)
Esempio n. 14
0
    def test_post_with_user(self):
        factory = APIRequestFactory()
        user = UserF.create(**{'is_superuser': False})
        user_to_add = UserF.create(**{'is_superuser': False})
        request = factory.post(
            reverse('ajax:superusers_adduser'),
            {'userId': user_to_add.id}
        )
        force_authenticate(request, user=user)
        view = AddSuperUsersAjaxView.as_view()
        response = view(request).render()

        self.assertEqual(response.status_code, 403)
        self.assertEqual(len(User.objects.filter(is_superuser=True)), 0)
Esempio n. 15
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)
Esempio n. 16
0
    def test_delete_with_user(self):
        factory = APIRequestFactory()
        user = UserF.create(**{'is_superuser': False})
        user_to_remove = UserF.create(**{'is_superuser': True})
        request = factory.delete(
            reverse('ajax:superusers_deleteuser', kwargs={
                'user_id': user_to_remove.id
            })
        )
        force_authenticate(request, user=user)
        view = DeleteSuperUsersAjaxView.as_view()
        response = view(request, user_id=user_to_remove.id).render()

        self.assertEqual(response.status_code, 403)
        self.assertEqual(len(User.objects.filter(is_superuser=True)), 1)
Esempio n. 17
0
    def test_get_role(self):
        admin = UserF.create()
        moderator = UserF.create()
        contributor = UserF.create()
        other = UserF.create()

        project = ProjectF.create(add_admins=[admin],
                                  add_moderators=[moderator],
                                  add_contributors=[contributor],
                                  add_viewers=[other])

        self.assertEqual('administrator', project.get_role(admin))
        self.assertEqual('moderator', project.get_role(moderator))
        self.assertEqual('contributor', project.get_role(contributor))
        self.assertEqual('watcher', project.get_role(other))
Esempio n. 18
0
    def test_delete_with_user(self):
        factory = APIRequestFactory()
        user = UserF.create(**{'is_superuser': False})
        user_to_remove = UserF.create(**{'is_superuser': True})
        request = factory.delete(
            reverse('ajax:superusers_deleteuser', kwargs={
                'user_id': user_to_remove.id
            })
        )
        force_authenticate(request, user=user)
        view = DeleteSuperUsersAjaxView.as_view()
        response = view(request, user_id=user_to_remove.id).render()

        self.assertEqual(response.status_code, 403)
        self.assertEqual(len(User.objects.filter(is_superuser=True)), 1)
Esempio n. 19
0
    def test_category_serialization(self):
        user = UserF.create()

        project = ProjectF.create(
            add_admins=[user]
        )
        CategoryFactory.create(**{'project': project})
        CategoryFactory.create(
            **{'project': project, 'status': 'inactive'}
        )
        o1 = CategoryFactory.create(**{'project': project})
        TextFieldFactory.create(**{'category': o1})
        o2 = CategoryFactory.create(**{'project': project})
        TextFieldFactory.create(**{'category': o2})

        request = self.factory.get(
            '/api/projects/%s/' % project.id)
        force_authenticate(request, user=user)
        view = SingleProject.as_view()
        response = view(request, project_id=project.id).render()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            2,
            len(json.loads(response.content).get('categories'))
        )
Esempio n. 20
0
    def test_post_with_user(self):
        """
        Updating with normal user should render the page with an error message
        """
        user = UserF.create()
        subset = SubsetFactory.create()

        self.request.user = user
        self.request.method = 'POST'
        self.request.POST = {
            'name': 'Name',
            'description': 'Description',
        }

        response = self.view(
            self.request,
            project_id=subset.project.id,
            subset_id=subset.id).render()

        rendered = render_to_string(
            'subsets/subsets_settings.html',
            {
                'error_description': 'Project matching query does not exist.',
                'error': 'Not found.',
                'user': user,
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version()
            }
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'), rendered)

        reference = Subset.objects.get(pk=subset.id)
        self.assertNotEqual(reference.name, 'Name')
        self.assertNotEqual(reference.description, 'Description')
Esempio n. 21
0
    def test_post_with_user(self):
        """
        Posting with normal user should render with an error message and not
        update the filter
        """
        subset = SubsetFactory.create()
        user = UserF.create()

        category = CategoryFactory.create(**{'project': subset.project})

        self.request.user = user
        self.request.method = 'POST'
        self.request.POST = {
            'filters': '{ "%s": { } }' % category.id
        }
        response = self.view(
            self.request,
            project_id=subset.project.id,
            subset_id=subset.id).render()

        reference_subset = Subset.objects.get(pk=subset.id)
        self.assertIsNone(reference_subset.filters)

        rendered = render_to_string(
            'subsets/subsets_data.html',
            {
                'error_description': 'Project matching query does not exist.',
                'error': 'Not found.',
                'user': user,
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version()
            }
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'), rendered)
Esempio n. 22
0
 def test_get_with_user(self):
     view = ProjectCreate.as_view()
     url = reverse('admin:project_create')
     request = APIRequestFactory().get(url)
     request.user = UserF.create()
     response = view(request).render()
     self.assertEqual(response.status_code, 200)
Esempio n. 23
0
    def test_get_with_user(self):
        """
        Accessing the view with normal user should render the page with an
        error message
        """
        subset = SubsetFactory.create()
        user = UserF.create()

        self.request.user = user
        response = self.view(
            self.request,
            project_id=subset.project.id,
            subset_id=subset.id).render()

        rendered = render_to_string(
            'base.html',
            {
                'error_description': 'Project matching query does not exist.',
                'error': 'Not found.',
                'user': user,
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version()
            }
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'), rendered)
        self.assertEqual(Subset.objects.count(), 1)
Esempio n. 24
0
 def test_get_context_data(self):
     user = UserF.create(**{'is_superuser': True})
     ProjectF.create_batch(5, add_admins=[user])
     ProjectF.create_batch(5)
     view = ProjectsList()
     context = view.get_context_data()
     self.assertEqual(len(context.get('projects')), 10)
Esempio n. 25
0
    def test_post_with_superuser(self):
        user = UserF.create(**{'is_superuser': True})
        self.create_inactive()
        self.request.POST = QueryDict(
            'activate_users=%s&activate_users=%s' % (
                self.inactive_1.id, self.inactive_2.id))
        self.request.method = 'POST'
        self.request.user = user

        response = self.view(self.request).render()

        rendered = render_to_string(
            'superusertools/manage_inactiveusers.html',
            {
                'inactive_users': [self.inactive_3],
                'user': user,
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version(),
                'messages': get_messages(self.request)
            }
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode('utf-8'), rendered)
        self.assertEqual(
            User.objects.filter(is_active=False).count(), 1
        )
        self.assertEqual(
            EmailAddress.objects.filter(verified=False).count(), 1
        )
Esempio n. 26
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)
Esempio n. 27
0
    def test(self):
        project = ProjectF.create(**{
            'isprivate': False,
            'everyone_contributes': 'auth'
        })

        self.assertTrue(project.can_contribute(UserF.create()))
        self.assertFalse(project.can_contribute(AnonymousUser()))

        project = ProjectF.create(**{
            'isprivate': False,
            'everyone_contributes': 'true'
        })

        self.assertTrue(project.can_contribute(UserF.create()))
        self.assertTrue(project.can_contribute(AnonymousUser()))
Esempio n. 28
0
    def test_selected_contacts(self):
        admin = UserF.create()
        contributor = UserF.create()
        email_user = UserF.create()

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

        admin_rel = Admins.objects.get(project=project, user=admin)
        admin_rel.contact = False
        admin_rel.save()

        project.contact_admins(email_user, 'Test email')
        self.assertEquals(len(mail.outbox), 1)
Esempio n. 29
0
 def test_get_context_data(self):
     user = UserF.create(**{'is_superuser': True})
     ProjectF.create_batch(5, add_admins=[user])
     ProjectF.create_batch(5)
     view = ProjectsList()
     context = view.get_context_data()
     self.assertEqual(len(context.get('projects')), 10)
Esempio n. 30
0
    def test_get_role(self):
        admin = UserF.create()
        moderator = UserF.create()
        contributor = UserF.create()
        other = UserF.create()

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

        self.assertEqual('administrator', project.get_role(admin))
        self.assertEqual('moderator', project.get_role(moderator))
        self.assertEqual('contributor', project.get_role(contributor))
        self.assertEqual('watcher', project.get_role(other))
Esempio n. 31
0
    def test_create_project(self):
        creator = UserF.create()

        project = Project.create(
            'Test', 'Test desc', True, True, creator
        )
        self.assertIn(creator, project.admins.all())
Esempio n. 32
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)
Esempio n. 33
0
 def test_get_with_superuser(self):
     view = PlatformSettings.as_view()
     url = reverse('admin:superuser_index')
     request = APIRequestFactory().get(url)
     request.user = UserF.create(**{'is_superuser': True})
     response = view(request).render()
     self.assertEqual(response.status_code, 200)
Esempio n. 34
0
 def test_superuser(self):
     view = ExampleView.as_view()
     request = APIRequestFactory().get("http://example.com")
     request.user = UserF.create(**{"is_superuser": True})
     response = view(request).render()
     self.assertEqual(response.status_code, 200)
     self.assertNotContains(response, "This extension is for super users only.")
Esempio n. 35
0
    def test(self):
        project = ProjectF.create(**{
            'isprivate': False,
            'everyone_contributes': 'auth'
        })

        self.assertTrue(project.can_contribute(UserF.create()))
        self.assertFalse(project.can_contribute(AnonymousUser()))

        project = ProjectF.create(**{
            'isprivate': False,
            'everyone_contributes': 'true'
        })

        self.assertTrue(project.can_contribute(UserF.create()))
        self.assertTrue(project.can_contribute(AnonymousUser()))
Esempio n. 36
0
 def test_get_with_superuser(self):
     view = PlatformSettings.as_view()
     url = reverse('admin:superuser_index')
     request = APIRequestFactory().get(url)
     request.user = UserF.create(**{'is_superuser': True})
     response = view(request).render()
     self.assertEqual(response.status_code, 200)
Esempio n. 37
0
    def test_create_project(self):
        creator = UserF.create()

        project = Project.create(
            'Test', 'Test desc', True, True, creator
        )
        self.assertIn(creator, project.admins.all())
Esempio n. 38
0
 def test_get_with_user(self):
     view = ProjectCreate.as_view()
     url = reverse('admin:project_create')
     request = APIRequestFactory().get(url)
     request.user = UserF.create()
     response = view(request).render()
     self.assertEqual(response.status_code, 200)
Esempio n. 39
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)
Esempio n. 40
0
    def test_some_dude(self):
        user = UserF.create()

        view = GroupingFactory.create()

        self.assertFalse(view.can_view(user))
        self.assertFalse(view.can_read(user))
        self.assertFalse(view.can_moderate(user))
Esempio n. 41
0
 def test_superuser(self):
     view = ExampleView.as_view()
     request = APIRequestFactory().get('http://example.com')
     request.user = UserF.create(**{'is_superuser': True})
     response = view(request).render()
     self.assertEqual(response.status_code, 200)
     self.assertNotContains(response,
                            'This extension is for super users only.')
Esempio n. 42
0
 def test_get_type_name(self):
     image_file = ImageFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserF.create(),
         image=get_image())
     self.assertEqual(image_file.type_name, 'ImageFile')
Esempio n. 43
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)
Esempio n. 44
0
 def test_delete_not_existing_admin(self):
     user = UserF.create()
     request = self.factory.delete('/ajax/projects/%s/admins/%s/' %
                                   (self.project.id, user.id))
     force_authenticate(request, user=self.admin)
     view = ProjectAdminsUser.as_view()
     response = view(request, project_id=self.project.id,
                     user_id=user.id).render()
     self.assertEqual(response.status_code, 404)
Esempio n. 45
0
 def test_delete_file(self):
     image_file = ImageFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserF.create(),
         image=get_image())
     image_file.delete()
     self.assertEquals(image_file.status, 'deleted')
Esempio n. 46
0
    def test_with_active_project(self):
        admin = UserF.create()
        email_user = UserF.create()

        project = ProjectF.create(add_admins=[admin], add_viewer=[email_user])

        view = ProjectContactAdmins.as_view()
        url = reverse('api:project_contact_admins',
                      kwargs={'project_id': project.id})
        request = APIRequestFactory().post(url,
                                           json.dumps(
                                               {'email_text': 'Blah Blah'}),
                                           content_type='application/json')
        force_authenticate(request, user=email_user)

        response = view(request, project_id=project.id).render()
        self.assertEqual(response.status_code, 204)
        self.assertEquals(len(mail.outbox), 2)
Esempio n. 47
0
 def test_get_type_name(self):
     image_file = ImageFile.objects.create(
         name='Test name',
         description='Test Description',
         contribution=ObservationFactory.create(),
         creator=UserF.create(),
         image=get_image()
     )
     self.assertEqual(image_file.type_name, 'ImageFile')
Esempio n. 48
0
 def test_get_with_user(self):
     user = UserF.create()
     ProjectF.create(add_contributors=[user])
     view = ProjectsInvolved.as_view()
     url = reverse('admin:projects_involved')
     request = APIRequestFactory().get(url)
     request.user = user
     response = view(request).render()
     self.assertEqual(response.status_code, 200)
Esempio n. 49
0
 def test_get_with_user(self):
     user = UserF.create()
     ProjectF.create(add_contributors=[user])
     view = ProjectsInvolved.as_view()
     url = reverse('admin:projects_involved')
     request = APIRequestFactory().get(url)
     request.user = user
     response = view(request).render()
     self.assertEqual(response.status_code, 200)
Esempio n. 50
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)