Beispiel #1
0
    def test_get_with_anonymous(self):
        """Test GET with anonymous user."""
        view = PlatformSettings.as_view()
        request = APIRequestFactory().get(self.url)
        request.user = AnonymousUser()
        view.request = request
        response = view(request)

        self.assertTrue(isinstance(response, HttpResponseRedirect))
Beispiel #2
0
    def test_get_with_superuser(self):
        """Test GET with superuser."""
        view = PlatformSettings.as_view()
        request = APIRequestFactory().get(self.url)
        request.user = UserFactory.create(**{"is_superuser": True})
        response = view(request).render()

        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response, "No rights to access superuser tools.")
Beispiel #3
0
    def test_get_with_anonymous(self):
        """Test GET with anonymous user."""
        view = PlatformSettings.as_view()
        request = APIRequestFactory().get(self.url)
        request.user = AnonymousUser()
        view.request = request
        response = view(request)

        self.assertTrue(isinstance(response, HttpResponseRedirect))
Beispiel #4
0
    def test_get_with_superuser(self):
        """Test GET with superuser."""
        view = PlatformSettings.as_view()
        request = APIRequestFactory().get(self.url)
        request.user = UserFactory.create(**{'is_superuser': True})
        response = view(request).render()

        self.assertEqual(response.status_code, 200)
        self.assertNotContains(response,
                               'No rights to access superuser tools.')
Beispiel #5
0
    def test_post_with_anonymous(self):
        """Test POST with anonymous user."""
        data = {"name": "New Name", "domain": "http://new-domain.org.uk"}
        view = PlatformSettings.as_view()
        request = APIRequestFactory().post(self.url, data)
        request.user = AnonymousUser()
        view.request = request
        response = view(request)

        self.assertTrue(isinstance(response, HttpResponseRedirect))

        reference = Site.objects.latest("id")
        self.assertNotEqual(reference.name, data.get("name"))
        self.assertNotEqual(reference.domain, data.get("domain"))
Beispiel #6
0
    def test_post_with_anonymous(self):
        """Test POST with anonymous user."""
        data = {'name': 'New Name', 'domain': 'http://new-domain.org.uk'}
        view = PlatformSettings.as_view()
        request = APIRequestFactory().post(self.url, data)
        request.user = AnonymousUser()
        view.request = request
        response = view(request)

        self.assertTrue(isinstance(response, HttpResponseRedirect))

        reference = Site.objects.latest('id')
        self.assertNotEqual(reference.name, data.get('name'))
        self.assertNotEqual(reference.domain, data.get('domain'))
Beispiel #7
0
    def test_post_with_user(self):
        """Test POST with user."""
        data = {"name": "New Name", "domain": "http://new-domain.org.uk"}
        view = PlatformSettings.as_view()
        request = APIRequestFactory().post(self.url, data)
        request.user = UserFactory.create(**{"is_superuser": False})
        view.request = request
        response = view(request).render()

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "No rights to access superuser tools.")

        reference = Site.objects.latest("id")
        self.assertNotEqual(reference.name, data.get("name"))
        self.assertNotEqual(reference.domain, data.get("domain"))
Beispiel #8
0
    def test_post_with_user(self):
        """Test POST with user."""
        data = {'name': 'New Name', 'domain': 'http://new-domain.org.uk'}
        view = PlatformSettings.as_view()
        request = APIRequestFactory().post(self.url, data)
        request.user = UserFactory.create(**{'is_superuser': False})
        view.request = request
        response = view(request).render()

        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'No rights to access superuser tools.')

        reference = Site.objects.latest('id')
        self.assertNotEqual(reference.name, data.get('name'))
        self.assertNotEqual(reference.domain, data.get('domain'))
Beispiel #9
0
    def test_post_with_superuser(self):
        """Test POST with superuser."""
        data = {"name": "New Name", "domain": "http://new-domain.org.uk"}
        view = PlatformSettings.as_view()
        request = APIRequestFactory().post(self.url, data)
        request.user = UserFactory.create(**{"is_superuser": True})

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

        response = view(request).render()
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Platform settings have been updated.")

        reference = Site.objects.latest("id")
        self.assertEqual(reference.name, data.get("name"))
        self.assertEqual(reference.domain, data.get("domain"))
Beispiel #10
0
    def test_post_with_superuser(self):
        """Test POST with superuser."""
        data = {'name': 'New Name', 'domain': 'http://new-domain.org.uk'}
        view = PlatformSettings.as_view()
        request = APIRequestFactory().post(self.url, data)
        request.user = UserFactory.create(**{'is_superuser': True})

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

        response = view(request).render()
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Platform settings have been updated.')

        reference = Site.objects.latest('id')
        self.assertEqual(reference.name, data.get('name'))
        self.assertEqual(reference.domain, data.get('domain'))
Beispiel #11
0
    def test_post_with_superuser(self):
        """Test POST with superuser."""
        data = {
            'name': 'New Name',
            'domain': 'http://new-domain.org.uk'
        }
        view = PlatformSettings.as_view()
        request = APIRequestFactory().post(self.url, data)
        request.user = UserFactory.create(**{'is_superuser': True})

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

        response = view(request).render()
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, 'Platform settings have been updated.')

        reference = Site.objects.latest('id')
        self.assertEqual(reference.name, data.get('name'))
        self.assertEqual(reference.domain, data.get('domain'))
Beispiel #12
0
    def test_post_with_user(self):
        """Test POST with user."""
        data = {
            'name': 'New Name',
            'domain': 'http://new-domain.org.uk'
        }
        view = PlatformSettings.as_view()
        request = APIRequestFactory().post(self.url, data)
        request.user = UserFactory.create(**{'is_superuser': False})
        view.request = request
        response = view(request).render()

        self.assertEqual(response.status_code, 200)
        self.assertContains(
            response,
            'No rights to access superuser tools.'
        )

        reference = Site.objects.latest('id')
        self.assertNotEqual(reference.name, data.get('name'))
        self.assertNotEqual(reference.domain, data.get('domain'))