Beispiel #1
0
    def test_post_with_user(self):
        sapelli_project = create_horniman_sapelli_project(self.user)

        path = normpath(join(dirname(abspath(__file__)), 'files/Horniman.csv'))
        file = File(open(path, 'rb'))

        self.request.method = 'POST'
        self.request.FILES = {'csv_file': file}
        self.request.POST = {
            'form_category_id': sapelli_project.forms.first().category_id
        }
        self.request.user = self.user

        response = self.view(
            self.request,
            project_id=sapelli_project.geokey_project.id).render()

        self.assertEqual(response.status_code, 200)

        rendered = render_to_string(
            'sapelli/upload_data_csv.html', {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'messages': get_messages(self.request),
                'user': self.user,
                'sapelli_project': sapelli_project,
            })

        self.assertContains(
            response, '4 records have been added as project contributions')
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
        self.assertEqual(sapelli_project.geokey_project.observations.count(),
                         5)
Beispiel #2
0
    def test_post_with_admin(self):
        """
        Updating with project admin should render the page with a success
        message
        """

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

        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.objects.get(pk=subset.id)
        self.assertEqual(reference.filters,
                         json.loads('{ "%s": { } }' % category.id))

        rendered = render_to_string(
            'subsets/subset_data.html', {
                'project': reference.project,
                'subset': reference,
                'user': user,
                'PLATFORM_NAME': get_current_site(self.request).name,
                'messages': get_messages(self.request),
                'GEOKEY_VERSION': version.get_version()
            })

        self.assertEqual(response.status_code, 200)
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
Beispiel #3
0
    def test_get_with_user(self):
        """
        Accessing the view with normal user should render the page with an
        error message
        """

        user = UserFactory.create()
        subset = SubsetFactory.create()

        self.request.user = user
        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)
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
Beispiel #4
0
    def test_get_with_admin(self):
        """
        Accessing the view with project admin should render the page
        """

        subset = SubsetFactory.create()
        user = subset.project.creator

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

        rendered = render_to_string(
            'subsets/subset_settings.html',
            {
                'project': subset.project,
                'subset': subset,
                'user': user,
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version()
            }
        )
        self.assertEqual(response.status_code, 200)
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
Beispiel #5
0
    def test_get_with_user(self):
        user = UserFactory.create()
        self.request.user = user

        response = self.view(self.request).render()
        self.assertEqual(response.status_code, 200)

        rendered = render_to_string(
            'sapelli/upload_sapelli_project.html', {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': user,
            })
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
Beispiel #6
0
    def test_get_with_user(self):
        sapelli_project = SapelliProjectFactory.create()
        self.request.user = sapelli_project.geokey_project.creator

        response = self.view(self.request).render()
        self.assertEqual(response.status_code, 200)

        rendered = render_to_string(
            'sapelli/index.html', {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'messages': get_messages(self.request),
                'user': sapelli_project.geokey_project.creator,
                'sapelli_projects': [sapelli_project],
            })
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
Beispiel #7
0
    def test_get_with_admin(self):
        """Test GET with admin."""
        self.request.user = self.admin
        response = self.view(
            self.request,
            project_id=self.sapelli_project.geokey_project.id).render()
        self.assertEqual(response.status_code, 200)

        rendered = render_to_string(
            'sapelli/logs.html', {
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version(),
                'user': self.request.user,
                'sapelli_project': self.sapelli_project,
            })
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
Beispiel #8
0
    def test_get_with_regular_user(self):
        """Test GET with regular user."""
        self.request.user = self.regular_user
        response = self.view(
            self.request,
            project_id=self.sapelli_project.geokey_project.id).render()
        self.assertEqual(response.status_code, 200)

        rendered = render_to_string(
            'sapelli/logs.html', {
                'PLATFORM_NAME': get_current_site(self.request).name,
                'GEOKEY_VERSION': version.get_version(),
                'user': self.request.user,
                'error': 'Not found',
                'error_description': 'Sapelli project not found.',
            })
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
Beispiel #9
0
    def test_get_with_user(self):
        """Test GET with user."""
        user = UserFactory.create(**{'is_superuser': False})
        self.request.method = 'GET'
        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)
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
Beispiel #10
0
    def test_get_with_user(self):
        sapelli_project = create_horniman_sapelli_project(self.user)
        self.request.user = self.user

        response = self.view(
            self.request,
            project_id=sapelli_project.geokey_project.id).render()

        self.assertEqual(response.status_code, 200)

        rendered = render_to_string(
            'sapelli/upload_data_csv.html', {
                'GEOKEY_VERSION': version.get_version(),
                'PLATFORM_NAME': get_current_site(self.request).name,
                'user': self.user,
                'sapelli_project': sapelli_project,
            })
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
Beispiel #11
0
    def test_post_with_admin(self):
        """
        Updating with project admin should render the page with a success
        message
        """

        subset = SubsetFactory.create()
        user = subset.project.creator

        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()

        reference = Subset.objects.get(pk=subset.id)
        self.assertEqual(reference.name, 'Name')
        self.assertEqual(reference.description, 'Description')

        rendered = render_to_string(
            'subsets/subset_settings.html',
            {
                'project': reference.project,
                'subset': reference,
                '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)
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
Beispiel #12
0
    def test_get_with_superuser(self):
        """Test GET with superuser."""
        self.create_inactive()
        user = UserFactory.create(**{'is_superuser': True})
        self.request.method = 'GET'
        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,
                'inactive_users':
                [self.inactive_1, self.inactive_2, self.inactive_3]
            })

        self.assertEqual(response.status_code, 200)
        response = render_helpers.remove_csrf(response.content.decode('utf-8'))
        self.assertEqual(response, rendered)
Beispiel #13
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)
Beispiel #14
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)