Beispiel #1
0
    def test_multiple(self):
        blog = Blog.objects.create(slug="blog")
        post = Post.objects.create(blog=blog, slug="slug")

        request = RequestFactory().get("/")
        request.META["HTTP_AUTHORIZATION"] = authorization()

        response = blog_multiple(request)

        self.assertEqual(response.status_code, 200)

        data = deserialize("json", response.content)

        self.assertEqual(next(data).object, blog)
        self.assertEqual(next(data).object, post)
Beispiel #2
0
    def test_single(self):
        blog = Blog.objects.create(slug="blog")

        request = RequestFactory().get("/")
        request.META["HTTP_AUTHORIZATION"] = authorization()

        response = blog_single(request)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            response._headers["content-type"][1],
            "application/json",
        )

        data = deserialize("json", response.content)
        self.assertEqual(next(data).object, blog)
Beispiel #3
0
    def test_bad_authorization(self):
        request = RequestFactory().get("/")
        request.META["HTTP_AUTHORIZATION"] = authorization(token="bad")

        response = self.client.get("/blog-single/")
        self.assertEqual(response.status_code, 401)