Exemplo n.º 1
0
    def setUp(self):
        """Set up tests."""
        self.anonymous_user = AnonymousUser()
        self.regular_user = UserFactory.create()
        self.admin_user = UserFactory.create()

        self.project = ProjectFactory.create(creator=self.admin_user)

        self.socialaccount_2 = SocialAccount.objects.create(
            user=self.admin_user, provider='facebook', uid='2')
        self.socialaccount_1 = SocialAccount.objects.create(
            user=self.admin_user, provider='twitter', uid='1')
        self.socialaccount_3 = SocialAccount.objects.create(
            user=self.admin_user, provider='twitter', uid='3')
        self.si_pull = SocialInteractionPullFactory.create(
            socialaccount=self.socialaccount_1,
            project=self.project,
            creator=self.admin_user
        )
        self.view = SocialInteractionPullSettings.as_view()
        self.request = HttpRequest()
        self.request.method = 'GET'
        self.request.user = self.anonymous_user

        self.freq = freq_dic.keys()
        refund_dict = {value: key for key, value in STATUS}
        self.status_types = refund_dict.keys()

        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)
Exemplo n.º 2
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.contributor = UserFactory.create()
        self.non_member = UserFactory.create()

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

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

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

        self.deleted_project = ProjectFactory.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor],
            **{'isprivate': False}
        )
        self.deleted_project.delete()
Exemplo n.º 3
0
    def setUp(self):
        """Set up test."""
        self.anonymous_user = AnonymousUser()
        self.regular_user = UserFactory.create()
        self.admin_user = UserFactory.create()

        self.project = ProjectFactory.create(creator=self.admin_user)

        self.socialaccount_2 = SocialAccount.objects.create(
            user=self.admin_user, provider='facebook', uid='2')
        self.socialaccount_1 = SocialAccount.objects.create(
            user=self.admin_user, provider='twitter', uid='1')
        self.socialaccount_3 = SocialAccount.objects.create(
            user=self.admin_user, provider='twitter', uid='3')
        self.si_pull = SocialInteractionPullFactory.create(
            socialaccount=self.socialaccount_1,
            project=self.project,
            creator=self.admin_user
        )

        self.view = SocialInteractionPullDelete.as_view()
        self.request = HttpRequest()
        self.request.method = 'GET'
        self.request.user = self.anonymous_user

        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)
Exemplo n.º 4
0
    def test_when_email_already_exists(self):
        """Test method when email is already in use."""
        UserFactory.create(display_name='Tom Black',
                           email='tom-black@user.%s' % self.domain)

        email = generate_fake_email('Tom Black!')
        self.assertEqual(email, 'tom-black-2@user.%s' % self.domain)
Exemplo n.º 5
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)
Exemplo n.º 6
0
    def test_when_display_name_already_exists(self):
        """Test method when display name is already in use."""
        UserFactory.create(display_name='Tom Black',
                           email='tom-black@user.%s' % self.domain)

        display_name = generate_display_name('Tom Black')
        self.assertEqual(display_name, 'Tom Black 2')
Exemplo n.º 7
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_media_file_count_update(VideoFile, instance=video_file)
        self.assertEqual(video_file.contribution.num_media, 1)
        self.assertEqual(video_file.contribution.num_comments, 0)
Exemplo n.º 8
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.contributor = UserFactory.create()
        self.non_member = UserFactory.create()

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

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

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

        self.deleted_project = ProjectFactory.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor],
            **{'isprivate': False}
        )
        self.deleted_project.delete()
Exemplo n.º 9
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)
Exemplo n.º 10
0
    def test_get_context_data(self):
        """Test getting context data."""
        UserFactory.create_batch(2, **{"is_superuser": True})
        UserFactory.create_batch(2, **{"is_superuser": False})
        view = ManageSuperusers()
        context = view.get_context_data()

        self.assertEqual(len(context.get("superusers")), 2)
Exemplo n.º 11
0
    def setUp(self):
        """Set up test."""
        self.factory = APIRequestFactory()
        self.view = SingleSuperuserAjaxView.as_view()

        self.user = UserFactory.create(**{'is_superuser': False})
        self.superuser = UserFactory.create(**{'is_superuser': True})
        self.user_to_remove = UserFactory.create(**{'is_superuser': True})
Exemplo n.º 12
0
 def create_inactive(self):
     """Create 3 inactive users."""
     self.inactive_1 = UserFactory.create(**{"is_active": False})
     EmailAddress(user=self.inactive_1, email=self.inactive_1.email, verified=False).save()
     self.inactive_2 = UserFactory.create(**{"is_active": False})
     EmailAddress(user=self.inactive_2, email=self.inactive_2.email, verified=False).save()
     self.inactive_3 = UserFactory.create(**{"is_active": False})
     EmailAddress(user=self.inactive_3, email=self.inactive_3.email, verified=False).save()
Exemplo n.º 13
0
    def setUp(self):
        """Set up test."""
        self.factory = APIRequestFactory()
        self.view = SingleSuperuserAjaxView.as_view()

        self.user = UserFactory.create(**{"is_superuser": False})
        self.superuser = UserFactory.create(**{"is_superuser": True})
        self.user_to_remove = UserFactory.create(**{"is_superuser": True})
Exemplo n.º 14
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.contributor = UserFactory.create()
        self.non_member = UserFactory.create()

        self.project = ProjectFactory.create(
            add_admins=[self.admin], add_contributors=[self.contributor])
Exemplo n.º 15
0
    def test_get_context_data(self):
        """Test getting context data."""
        UserFactory.create_batch(2, **{'is_superuser': True})
        UserFactory.create_batch(2, **{'is_superuser': False})
        view = ManageSuperusers()
        context = view.get_context_data()

        self.assertEqual(len(context.get('superusers')), 2)
Exemplo n.º 16
0
    def setUp(self):
        """Set up test."""
        self.factory = APIRequestFactory()
        self.view = SuperusersAjaxView.as_view()
        self.url = reverse('ajax:superusertools_superusers')

        self.user = UserFactory.create(**{'is_superuser': False})
        self.superuser = UserFactory.create(**{'is_superuser': True})
        self.user_to_add = UserFactory.create(**{'is_superuser': False})
Exemplo n.º 17
0
 def setUp(self):
     self.creator = UserFactory.create()
     self.admin = UserFactory.create()
     self.view_member = UserFactory.create()
     self.contributor = UserFactory.create()
     self.project = ProjectFactory.create(
         add_admins=[self.admin],
         add_contributors=[self.contributor],
         **{'creator': self.creator})
Exemplo n.º 18
0
    def setUp(self):
        """Set up test."""
        self.factory = APIRequestFactory()
        self.view = SuperusersAjaxView.as_view()
        self.url = reverse("ajax:superusertools_superusers")

        self.user = UserFactory.create(**{"is_superuser": False})
        self.superuser = UserFactory.create(**{"is_superuser": True})
        self.user_to_add = UserFactory.create(**{"is_superuser": False})
Exemplo n.º 19
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.contributor = UserFactory.create()
        self.non_member = UserFactory.create()

        self.project = ProjectFactory.create(
            add_admins=[self.admin],
            add_contributors=[self.contributor]
        )
Exemplo n.º 20
0
 def setUp(self):
     self.creator = UserFactory.create()
     self.admin = UserFactory.create()
     self.view_member = UserFactory.create()
     self.contributor = UserFactory.create()
     self.project = ProjectFactory.create(
         add_admins=[self.admin],
         add_contributors=[self.contributor],
         **{'creator': self.creator}
     )
Exemplo n.º 21
0
    def setUp(self):
        """Set up test."""
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.regular_user = UserFactory.create()
        self.anonymous_user = AnonymousUser()
        self.project = ProjectFactory(add_admins=[self.admin])
        self.sapelli_project = SapelliProjectFactory.create(
            **{'geokey_project': self.project})

        self.file_name = 'Collector_2015-01-20T18.02.12.log'
        self.file = get_test_file(self.file_name)
Exemplo n.º 22
0
    def setUp(self):
        """Set up test."""
        self.factory = APIRequestFactory()
        self.admin = UserFactory.create()
        self.regular_user = UserFactory.create()
        self.anonymous_user = AnonymousUser()
        self.project = ProjectFactory(add_admins=[self.admin])
        self.sapelli_project = SapelliProjectFactory.create(
            **{'geokey_project': self.project})

        self.file_name = 'Collector_2015-01-20T18.02.12.log'
        self.file = get_test_file(self.file_name)
Exemplo n.º 23
0
    def setUp(self):
        """Set up test."""
        self.admin = UserFactory.create()
        self.regular_user = UserFactory.create()
        self.anonymous_user = AnonymousUser()
        self.sapelli_project = create_horniman_sapelli_project(self.admin)

        self.view = DataLogsDownload.as_view()
        self.request = HttpRequest()
        self.request.method = 'GET'

        setattr(self.request, 'session', 'session')
        setattr(self.request, '_messages', FallbackStorage(self.request))
Exemplo n.º 24
0
    def setUp(self):
        """Set up test."""
        self.admin = UserFactory.create()
        self.regular_user = UserFactory.create()
        self.anonymous_user = AnonymousUser()
        self.sapelli_project = create_horniman_sapelli_project(self.admin)

        self.view = DataLogsDownload.as_view()
        self.request = HttpRequest()
        self.request.method = 'GET'

        setattr(self.request, 'session', 'session')
        setattr(self.request, '_messages', FallbackStorage(self.request))
Exemplo n.º 25
0
 def create_inactive(self):
     """Create 3 inactive users."""
     self.inactive_1 = UserFactory.create(**{'is_active': False})
     EmailAddress(user=self.inactive_1,
                  email=self.inactive_1.email,
                  verified=False).save()
     self.inactive_2 = UserFactory.create(**{'is_active': False})
     EmailAddress(user=self.inactive_2,
                  email=self.inactive_2.email,
                  verified=False).save()
     self.inactive_3 = UserFactory.create(**{'is_active': False})
     EmailAddress(user=self.inactive_3,
                  email=self.inactive_3.email,
                  verified=False).save()
Exemplo n.º 26
0
    def test_post_with_user(self):
        factory = APIRequestFactory()
        user = UserFactory.create(**{'is_superuser': False})
        user_to_add = UserFactory.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)
Exemplo n.º 27
0
    def test_delete_with_user(self):
        factory = APIRequestFactory()
        user = UserFactory.create(**{'is_superuser': False})
        user_to_remove = UserFactory.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)
Exemplo n.º 28
0
    def test_import_from_csv_texttest_unicode(self):
        user = UserFactory.create()
        sapelli_project = create_textunicode_sapelli_project(user)

        form = sapelli_project.forms.all()[0]

        # Import records with unicode characters:
        path = normpath(
            join(dirname(abspath(__file__)), 'files/TextUnicode.csv'))
        file = File(open(path, 'rb'))
        imported, imported_joined_locs, imported_no_loc, updated, ignored_dup = sapelli_project.import_from_csv(
            user, file, form.category_id)
        self.assertEqual(imported, 2)
        self.assertEqual(imported_joined_locs, 0)
        self.assertEqual(imported_no_loc, 0)
        self.assertEqual(updated, 0)
        self.assertEqual(ignored_dup, 0)
        self.assertEqual(sapelli_project.geokey_project.observations.count(),
                         2)

        observation = sapelli_project.geokey_project.observations.get(
            category_id=form.category.id,
            properties__StartTime='2015-12-12T06:23:04.570-05:00')
        self.assertEqual(observation.properties['txttext'],
                         u'\ud55c\uc790test')
Exemplo n.º 29
0
    def test_import_from_csv_horniman_corrupt(self):
        user = UserFactory.create()
        sapelli_project = create_horniman_sapelli_project(user)

        form = sapelli_project.forms.all()[0]

        # Call import with an invalid form_category_id (must fail):
        path = normpath(join(dirname(abspath(__file__)), 'files/Horniman.csv'))
        file = File(open(path, 'rb'))
        self.assertRaises(
            SapelliCSVException,
            sapelli_project.import_from_csv,
            user,
            file,
            form.category_id + 1  # invalid!
        )
        # Process CSV without form identification info in header, without user-selected form (must fail):
        path = normpath(
            join(dirname(abspath(__file__)),
                 'files/Horniman_updated_no_form_ident.csv'))
        file = File(open(path, 'rb'))
        self.assertRaises(SapelliCSVException, sapelli_project.import_from_csv,
                          user, file
                          # no form.category_id given!
                          )
Exemplo n.º 30
0
    def test_post_with_user(self):
        """
        Updating with normal user should render the page with an error message
        """

        user = UserFactory.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/subset_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')
Exemplo n.º 31
0
    def test_get_with_superuser(self):
        """Test GET with superuser."""
        view = ManageSuperusers.as_view()
        self.request.user = UserFactory.create(**{'is_superuser': True})
        response = view(self.request).render()

        self.assertEqual(response.status_code, 200)
Exemplo n.º 32
0
    def test_post_with_user(self):
        """
        Updating with normal user should render the page with an error message
        """

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

        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/subset_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)
Exemplo n.º 33
0
    def setUp(self):
        """Set up test method 'create_new_observation'."""
        self.admin = UserFactory.create()
        self.project = ProjectFactory.create(creator=self.admin)

        self.socialaccount = SocialAccount.objects.create(user=self.admin,
                                                          provider='facebook',
                                                          uid='1')
        self.category = CategoryFactory.create(name='Tweets',
                                               creator=self.admin,
                                               project=self.project)

        self.field_text = TextFieldFactory.create(key='tweet',
                                                  category=self.category)

        self.tweet_id_field = NumericFieldFactory.create(
            key='tweet-id', category=self.category)

        self.si_pull = SocialInteractionPullFactory.create(
            socialaccount=self.socialaccount,
            project=self.project,
            creator=self.admin)

        self.geo_tweet = {
            'geometry': u'POINT (-0.1350858 51.5246635)',
            'text': u'#Project2 scorpion @adeuonce',
            'created_at': datetime(2017, 5, 23, 14, 43, 1),
            'id': 867028097530572801,
            'user': u'Pepito Grillo'
        }
Exemplo n.º 34
0
    def test_post_with_superuser_when_updating(self):
        """Test POST with superuser."""
        data = {
            'client_id': 'xxxxxxxxxxxxxxxxxx',
            'secret': 'xxxxxxxxxxxxxxxxxx',
            'key': ''
        }
        view = ProviderOverview.as_view()
        request = APIRequestFactory().post(self.url, data)
        request.user = UserFactory.create(**{'is_superuser': True})

        social_app = SocialApp.objects.create(provider='google',
                                              name='Google',
                                              client_id='yyyyyyyyyyyyyyyyyy',
                                              secret='yyyyyyyyyyyyyyyyyy',
                                              key='')
        social_app.sites.add(get_current_site(request))

        setattr(request, 'session', 'session')
        messages = FallbackStorage(request)
        setattr(request, '_messages', messages)

        response = view(request, provider_id='google').render()
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Provider has been updated.')
        self.assertEqual(SocialApp.objects.latest('id'), social_app)

        reference = SocialApp.objects.get(pk=social_app.id)
        self.assertEqual(reference.client_id, data.get('client_id'))
        self.assertEqual(reference.secret, data.get('secret'))
        self.assertEqual(reference.key, data.get('key'))
Exemplo n.º 35
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 = UserFactory.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)
Exemplo n.º 36
0
    def test_post_with_user(self):
        """
        Updating with normal user should render the page with an error message
        """

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

        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/subset_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)
Exemplo n.º 37
0
 def setUp(self):
     """Set up test."""
     self.user = UserFactory.create()
     self.project = ProjectFactory.create(**{
         'creator': self.user})
     self.usergroup = UserGroupFactory.create(**{
         'project': self.project})
Exemplo n.º 38
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 = UserFactory.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)
Exemplo n.º 39
0
    def test_log_remove_user(self):
        """Test when user is removed."""
        existing_user = UserFactory.create()
        self.usergroup.users.add(existing_user)
        log_count_init = LoggerHistory.objects.count()
        self.usergroup.users.remove(existing_user)

        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, {
            'id': str(self.usergroup.id),
            'name': self.usergroup.name})
        self.assertEqual(log.category, None)
        self.assertEqual(log.field, None)
        self.assertEqual(log.location, None)
        self.assertEqual(log.observation, None)
        self.assertEqual(log.comment, None)
        self.assertEqual(log.subset, None)
        self.assertEqual(log.action, {
            'id': 'updated',
            'class': 'UserGroup_users',
            'subaction': 'remove',
            'user_id': str(existing_user.id),
            'user_display_name': existing_user.display_name})
        self.assertEqual(log_count, log_count_init + 1)
        self.assertEqual(log.historical, None)
Exemplo n.º 40
0
    def test_category_serialization(self):
        user = UserFactory.create()

        project = ProjectFactory.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'))
        )
Exemplo n.º 41
0
    def test_get_with_superuser(self):
        """Test GET with superuser."""
        view = ManageSuperusers.as_view()
        self.request.user = UserFactory.create(**{"is_superuser": True})
        response = view(self.request).render()

        self.assertEqual(response.status_code, 200)
Exemplo n.º 42
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)
Exemplo n.º 43
0
    def test_get_role(self):
        admin = UserFactory.create()
        moderator = UserFactory.create()
        contributor = UserFactory.create()
        other = UserFactory.create()

        project = ProjectFactory.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))
Exemplo n.º 44
0
    def test_post_with_superuser_when_updating(self):
        """Test POST with superuser."""
        data = {"client_id": "xxxxxxxxxxxxxxxxxx", "secret": "xxxxxxxxxxxxxxxxxx", "key": ""}
        view = ProviderOverview.as_view()
        request = APIRequestFactory().post(self.url, data)
        request.user = UserFactory.create(**{"is_superuser": True})

        social_app = SocialApp.objects.create(
            provider="google", name="Google", client_id="yyyyyyyyyyyyyyyyyy", secret="yyyyyyyyyyyyyyyyyy", key=""
        )
        social_app.sites.add(get_current_site(request))

        setattr(request, "session", "session")
        messages = FallbackStorage(request)
        setattr(request, "_messages", messages)

        response = view(request, provider_id="google").render()
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Provider has been updated.")
        self.assertEqual(SocialApp.objects.latest("id"), social_app)

        reference = SocialApp.objects.get(pk=social_app.id)
        self.assertEqual(reference.client_id, data.get("client_id"))
        self.assertEqual(reference.secret, data.get("secret"))
        self.assertEqual(reference.key, data.get("key"))
Exemplo n.º 45
0
    def test_post_with_superuser(self):
        """Test POST with superuser."""
        self.create_inactive()
        user = UserFactory.create(**{"is_superuser": True})
        self.request.method = "POST"
        self.request.POST = QueryDict("activate_users=%s&activate_users=%s" % (self.inactive_1.id, self.inactive_2.id))
        self.request.user = user
        response = self.view(self.request).render()

        rendered = render_to_string(
            "superusertools/manage_inactive_users.html",
            {
                "GEOKEY_VERSION": version.get_version(),
                "PLATFORM_NAME": get_current_site(self.request).name,
                "user": user,
                "messages": get_messages(self.request),
                "inactive_users": [self.inactive_3],
            },
        )

        self.assertEqual(response.status_code, 200)
        response = render_helpers.remove_csrf(response.content.decode("utf-8"))
        self.assertEqual(response, rendered)
        self.assertEqual(User.objects.filter(is_active=False).count(), 1)
        self.assertEqual(len(EmailAddress.objects.filter(verified=False)), 1)
Exemplo n.º 46
0
 def test_get_with_user(self):
     view = ProjectCreate.as_view()
     url = reverse('admin:project_create')
     request = APIRequestFactory().get(url)
     request.user = UserFactory.create()
     response = view(request).render()
     self.assertEqual(response.status_code, 200)
Exemplo n.º 47
0
    def test_post_with_user(self):
        """Test POST with user."""
        self.create_inactive()
        user = UserFactory.create()
        self.request.method = "POST"
        self.request.POST = QueryDict("activate_users=%s&activate_users=%s" % (self.inactive_1.id, self.inactive_2.id))
        self.request.user = user
        response = self.view(self.request).render()

        rendered = render_to_string(
            "superusertools/manage_inactive_users.html",
            {
                "GEOKEY_VERSION": version.get_version(),
                "PLATFORM_NAME": get_current_site(self.request).name,
                "user": user,
                "error": "Permission denied.",
                "error_description": "No rights to access superuser tools.",
            },
        )

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content.decode("utf-8"), rendered)
        response = render_helpers.remove_csrf(response.content.decode("utf-8"))
        self.assertEqual(User.objects.filter(is_active=False).count(), 3)
        self.assertEqual(len(EmailAddress.objects.filter(verified=False)), 3)
Exemplo n.º 48
0
    def test_create_project(self):
        creator = UserFactory.create()

        project = Project.create(
            'Test', 'Test desc', True, False, True, creator
        )
        self.assertIn(creator, project.admins.all())
Exemplo n.º 49
0
    def test(self):
        project = ProjectFactory.create(**{
            'isprivate': False,
            'everyone_contributes': 'auth'
        })

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

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

        self.assertTrue(project.can_contribute(UserFactory.create()))
        self.assertTrue(project.can_contribute(AnonymousUser()))
Exemplo n.º 50
0
    def test_import_geomtry_inbetween(self):
        the_file = get_csv_file(['id', 'name', 'geom', 'description'])

        category = CategoryFactory.create()
        NumericFieldFactory.create(**{
            'name': 'ID',
            'key': 'id',
            'category': category
        })
        TextFieldFactory.create(**{
            'name': 'Name',
            'key': 'name',
            'category': category
        })
        TextFieldFactory.create(**{
            'name': 'Description',
            'key': 'description',
            'category': category
        })

        data_import = DataImportFactory.create(**{
            'fields': ['id', 'name', 'description'],
            'category': category,
            'project': category.project,
            'csv_file': File(open(the_file.name))
        })

        data_import.import_csv(UserFactory.create())
        self.assertEqual(Observation.objects.count(), 2)
Exemplo n.º 51
0
    def test_import_csv_last(self):
        category = CategoryFactory.create()
        NumericFieldFactory.create(**{
            'name': 'ID',
            'key': 'id',
            'category': category
        })
        TextFieldFactory.create(**{
            'name': 'Name',
            'key': 'name',
            'category': category
        })
        TextFieldFactory.create(**{
            'name': 'Description',
            'key': 'description',
            'category': category
        })

        data_import = DataImportFactory.create(**{
            'fields': ['id', 'name', 'description'],
            'category': category,
            'project': category.project,
            'geom_field': 'geom'
        })

        data_import.import_csv(UserFactory.create())
        self.assertEqual(Observation.objects.count(), 2)
Exemplo n.º 52
0
    def test_log_remove_admin(self):
        """Test when admin is removed."""
        existing_admin = UserFactory.create()
        admins_relation = AdminsFactory.create(project=self.project,
                                               user=existing_admin)
        log_count_init = LoggerHistory.objects.count()
        admins_relation.delete()

        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, None)
        self.assertEqual(log.field, None)
        self.assertEqual(log.location, None)
        self.assertEqual(log.observation, None)
        self.assertEqual(log.comment, None)
        self.assertEqual(log.subset, None)
        self.assertEqual(
            log.action, {
                'id': 'deleted',
                'class': 'Admins',
                'user_id': str(existing_admin.id),
                'user_display_name': existing_admin.display_name
            })
        self.assertEqual(log_count, log_count_init + 1)
        self.assertEqual(log.historical, None)
Exemplo n.º 53
0
    def test_post_save_image_file_count_update(self):
        observation = ObservationFactory()
        image_file = ImageFile.objects.create(name='Test name',
                                              description='Test Description',
                                              contribution=observation,
                                              creator=UserFactory.create(),
                                              image=get_image())
        ImageFile.objects.create(status='deleted',
                                 name='Test name',
                                 description='Test Description',
                                 contribution=observation,
                                 creator=UserFactory.create(),
                                 image=get_image())

        post_save_media_file_count_update(ImageFile, instance=image_file)
        self.assertEqual(image_file.contribution.num_media, 1)
        self.assertEqual(image_file.contribution.num_comments, 0)
Exemplo n.º 54
0
    def test_get_with_user(self):
        """Test GET with user."""
        view = ManageSuperusers.as_view()
        self.request.user = UserFactory.create(**{'is_superuser': False})
        response = view(self.request).render()

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'No rights to access superuser tools.')
Exemplo n.º 55
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')
Exemplo n.º 56
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')
Exemplo n.º 57
0
 def setUp(self):
     """Set up test."""
     self.user = UserFactory.create()
     self.project = ProjectFactory.create(**{
         'creator': self.user})
     self.subset = SubsetFactory.create(**{
         'creator': self.user,
         'project': self.project})
Exemplo n.º 58
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')
Exemplo n.º 59
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)
Exemplo n.º 60
0
 def test_get_with_user(self):
     user = UserFactory.create()
     ProjectFactory.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)