source: src/mapservice/tests/test_waters.py@ ae2ff15

debian/bullseye
Last change on this file since ae2ff15 was ae2ff15, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Fixed testing environment
    • Fixed some issues in the API and it's serving
  • Property mode set to 100644
File size: 4.5 KB
Line 
1'''
2 Copyright (C) 2019 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16'''
17
18import unittest
19import json
20
21from . import BaseTestCase
22
23class TestWaters(BaseTestCase):
24 @classmethod
25 def setUpClass(self):
26 self.base_url = '/mapservice/v1/waters'
27
28
29 def test_get(self):
30 """Test case getting waters (src)
31 """
32 headers = {}
33 response = self.client.open(
34 self.base_url,
35 method='GET',
36 headers=headers)
37 assert response.status_code == 200
38 data = json.loads(response.data)
39 assert len(data) == 1
40 data = data[0]
41 self.check_key("manager", self.db_content.test_water.manager.username, data)
42 self.check_key("name", self.db_content.test_water.name, data)
43 self.check_key("waterId", self.db_content.test_water.id, data)
44 self.check_key("osmId", self.db_content.test_water.osm_id, data)
45 self.check_key("osmType", self.db_content.test_water.osm_type.name, data)
46
47 def test_get_by_name(self):
48 """Test case getting waters by name (src)
49 """
50 headers = {}
51
52 response = self.client.open(
53 '{}?name=Bla'.format(self.base_url),
54 method='GET',
55 headers=headers)
56 assert response.status_code == 200
57 data = json.loads(response.data)
58 assert len(data) == 0
59
60 response = self.client.open(
61 '{}?name={}'.format(self.base_url, self.db_content.test_water.name[:3]),
62 method='GET',
63 headers=headers)
64 assert response.status_code == 200
65 data = json.loads(response.data)
66 assert len(data) == 1
67 data = data[0]
68 self.check_key("manager", self.db_content.test_water.manager.username, data)
69 self.check_key("name", self.db_content.test_water.name, data)
70 self.check_key("waterId", self.db_content.test_water.id, data)
71 self.check_key("osmId", self.db_content.test_water.osm_id, data)
72 self.check_key("osmType", self.db_content.test_water.osm_type.name, data)
73
74 def test_get_by_manager(self):
75 """Test case getting waters by manager (src)
76 """
77 headers = {}
78
79 response = self.client.open(
80 '{}?manager=not_existent'.format(self.base_url),
81 method='GET',
82 headers=headers)
83 assert response.status_code == 404, '{} != {}'.format(response.status_code, 404)
84
85 response = self.client.open(
86 '{}?manager={}'.format(self.base_url, self.db_content.test_user.username),
87 method='GET',
88 headers=headers)
89 assert response.status_code == 200
90 data = json.loads(response.data)
91 assert len(data) == 1
92 data = data[0]
93 self.check_key("manager", self.db_content.test_water.manager.username, data)
94 self.check_key("name", self.db_content.test_water.name, data)
95 self.check_key("waterId", self.db_content.test_water.id, data)
96 self.check_key("osmId", self.db_content.test_water.osm_id, data)
97 self.check_key("osmType", self.db_content.test_water.osm_type.name, data)
98
99 def test_get_by_name_manager(self):
100 """Test case getting waters by manager and water name (src)
101 """
102 headers = {}
103
104 response = self.client.open(
105 '{}?manager={}&name=Bla'.format(self.base_url, self.db_content.test_user.username),
106 method='GET',
107 headers=headers)
108 assert response.status_code == 200
109
110 response = self.client.open(
111 '{}?manager=john&name={}'.format(self.base_url, self.db_content.test_water.name[:3]),
112 method='GET',
113 headers=headers)
114 assert response.status_code == 404
115
116 response = self.client.open(
117 '{}?name={}&manager={}'.format(self.base_url, self.db_content.test_water.name, self.db_content.test_user.username),
118 method='GET',
119 headers=headers)
120 assert response.status_code == 200
121 data = json.loads(response.data)
122 assert len(data) == 1
123 data = data[0]
124 self.check_key("manager", self.db_content.test_water.manager.username, data)
125 self.check_key("name", self.db_content.test_water.name, data)
126 self.check_key("waterId", self.db_content.test_water.id, data)
127 self.check_key("osmId", self.db_content.test_water.osm_id, data)
128 self.check_key("osmType", self.db_content.test_water.osm_type.name, data)
129
130if __name__ == '__main__':
131 unittest.main()
Note: See TracBrowser for help on using the repository browser.