File: test_json_response.py

package info (click to toggle)
pytest-flask 1.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 280 kB
  • sloc: python: 553; makefile: 161; sh: 5
file content (21 lines) | stat: -rw-r--r-- 965 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
import pytest
from flask import url_for


class TestJSONResponse:
    def test_json_response(self, client, accept_json):
        res = client.get(url_for("ping"), headers=accept_json)
        assert res.json == {"ping": "pong"}

    def test_json_response_compare_to_status_code(self, client, accept_json):
        assert client.get(url_for("ping"), headers=accept_json) == 200
        assert client.get("fake-route", headers=accept_json) == 404
        assert client.get("fake-route", headers=accept_json) != "404"
        res = client.get(url_for("ping"), headers=accept_json)
        assert res == res

    def test_mismatching_eq_comparison(self, client, accept_json):
        with pytest.raises(AssertionError, match=r"Mismatch in status code"):
            assert client.get("fake-route", headers=accept_json) == 200
        with pytest.raises(AssertionError, match=r"404 NOT FOUND"):
            assert client.get("fake-route", headers=accept_json) == "200"