File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ import pytest
2
+ from flask import Flask
3
+ from tenantfirstaid .citations import get_citation , SECTIONS
4
+
5
+
6
+ @pytest .fixture
7
+ def app ():
8
+ app = Flask (__name__ )
9
+ app .add_url_rule ("/api/citation" , view_func = get_citation , methods = ["GET" ])
10
+ return app
11
+
12
+
13
+ @pytest .fixture
14
+ def client (app ):
15
+ return app .test_client ()
16
+
17
+
18
+ def test_get_citation_success (client ):
19
+ # Use a valid section from SECTIONS
20
+ section = next (iter (SECTIONS ))
21
+ response = client .get (f"/api/citation?section={ section } " )
22
+ assert response .status_code == 200
23
+ data = response .get_json ()
24
+ assert data ["section" ] == section
25
+ assert data ["text" ] == SECTIONS [section ]
26
+
27
+
28
+ def test_get_citation_missing_param (client ):
29
+ response = client .get ("/api/citation" )
30
+ assert response .status_code == 400
31
+ assert b"missing query param" in response .data
32
+
33
+
34
+ def test_get_citation_unknown_section (client ):
35
+ response = client .get ("/api/citation?section=notarealsection" )
36
+ assert response .status_code == 404
37
+ assert b"not found" in response .data
38
+
39
+
40
+ def test_get_citation_empty_section_param (client ):
41
+ response = client .get ("/api/citation?section=" )
42
+ assert response .status_code == 400
43
+ assert b"missing query param" in response .data
You can’t perform that action at this time.
0 commit comments