File: test_test_project.py

package info (click to toggle)
djangorestframework-api-key 3.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 392 kB
  • sloc: python: 926; makefile: 53; sh: 3
file content (22 lines) | stat: -rw-r--r-- 744 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import pytest
from rest_framework.test import APIClient
from test_project.heroes.models import Hero
from test_project.heroes.permissions import HeroAPIKey


@pytest.mark.django_db
def test_test_project_routes() -> None:
    batman = Hero.objects.create(name="Batman")
    _, key = HeroAPIKey.objects.create_key(name="test", hero=batman)
    headers = {"HTTP_AUTHORIZATION": f"Api-Key {key}"}

    client = APIClient()

    response = client.get("/api/public/", format="json")
    assert response.status_code == 200

    response = client.get("/api/protected/", format="json", **headers)
    assert response.status_code == 200

    response = client.get("/api/protected/object/", format="json", **headers)
    assert response.status_code == 200