Beispiel #1
0
    def test_get(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request_obj = factories.RequestFactory()

        response = admin.request_admin_edit(request, request_obj.pk)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.context_data["form"].instance, request_obj)
        self.assertEqual(models.Request.objects.count(), 1)

        with self.assertRaises(Http404):
            admin.request_admin_edit(request, 0)

        self.assertEqual(models.Request.objects.count(), 1)
Beispiel #2
0
    def test_post_invalid(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"succeeded": None}
        request_obj = factories.RequestFactory(requester=self.user)

        response = admin.request_admin_edit(request, request_obj.pk)
        self.assertEqual(response.status_code, 200)

        request_obj.refresh_from_db()
        self.assertEqual(request_obj.succeeded, None)
        self.assertEqual(request_obj.authorizer, None)
        self.assertEqual(request_obj.date_decided, None)
Beispiel #3
0
    def test_url(self):
        assert self.client.login(username=self.user.username, password="******", request=MockRequest(self.user)),\
                "Could not log in"

        grant_otp(self.client, self.user)
        grant_sudo(self.client)
        request_obj = factories.RequestFactory()

        response = self.client.get(
            urlresolvers.reverse("admin:requests:edit",
                                 kwargs={"request_pk": request_obj.pk}))
        self.assertEqual(response.resolver_match.func,
                         admin.request_admin_edit)
        self.assertEqual(response.status_code, 200)
Beispiel #4
0
    def test_post_rejected(self):
        request = MockRequest(self.user, has_otp=True, has_sudo=True)
        request.method = "POST"
        request.POST = {"succeeded": False}
        request_obj = factories.RequestFactory(requester=self.user)
        # also pre-create profile
        pool_amount = request_obj.requester.inboxenprofile.pool_amount

        response = admin.request_admin_edit(request, request_obj.pk)
        self.assertEqual(response.status_code, 302)
        self.assertEqual(response["Location"],
                         urlresolvers.reverse("admin:requests:index"))

        request_obj.refresh_from_db()
        self.assertEqual(request_obj.succeeded, False)
        self.assertEqual(request_obj.authorizer, self.user)
        self.assertNotEqual(request_obj.date_decided, None)

        self.user.inboxenprofile.refresh_from_db()
        self.assertEqual(self.user.inboxenprofile.pool_amount, pool_amount)