source: src/mapservice/tests/test_waters.py@ 7be94aa

debian/bullseye
Last change on this file since 7be94aa was 7be94aa, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Added yapf style config (src/python-style.yapf)
    • Updated all files to the yapf formatted version
  • Property mode set to 100644
File size: 5.4 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
23
24class TestWaters(BaseTestCase):
25 @classmethod
26 def setUpClass(self):
27 self.base_url = '/mapservice/v1/waters'
28
29 def test_get(self):
30 """Test case getting waters (src)
31 """
32 headers = {}
33 response = self.client.open(
34 self.base_url, method='GET', headers=headers
35 )
36 assert response.status_code == 200
37 data = json.loads(response.data)
38 assert len(data) == 1
39 data = data[0]
40 self.check_key(
41 "manager", self.db_content.test_water.manager.username, data
42 )
43 self.check_key("name", self.db_content.test_water.name, data)
44 self.check_key("waterId", self.db_content.test_water.id, data)
45 self.check_key("osmId", self.db_content.test_water.osm_id, data)
46 self.check_key(
47 "osmType", self.db_content.test_water.osm_type.name, data
48 )
49
50 def test_get_by_name(self):
51 """Test case getting waters by name (src)
52 """
53 headers = {}
54
55 response = self.client.open(
56 '{}?name=Bla'.format(self.base_url), method='GET', headers=headers
57 )
58 assert response.status_code == 200
59 data = json.loads(response.data)
60 assert len(data) == 0
61
62 response = self.client.open(
63 '{}?name={}'.format(
64 self.base_url, self.db_content.test_water.name[:3]
65 ),
66 method='GET',
67 headers=headers
68 )
69 assert response.status_code == 200
70 data = json.loads(response.data)
71 assert len(data) == 1
72 data = data[0]
73 self.check_key(
74 "manager", self.db_content.test_water.manager.username, data
75 )
76 self.check_key("name", self.db_content.test_water.name, data)
77 self.check_key("waterId", self.db_content.test_water.id, data)
78 self.check_key("osmId", self.db_content.test_water.osm_id, data)
79 self.check_key(
80 "osmType", self.db_content.test_water.osm_type.name, data
81 )
82
83 def test_get_by_manager(self):
84 """Test case getting waters by manager (src)
85 """
86 headers = {}
87
88 response = self.client.open(
89 '{}?manager=not_existent'.format(self.base_url),
90 method='GET',
91 headers=headers
92 )
93 assert response.status_code == 404, '{} != {}'.format(
94 response.status_code, 404
95 )
96
97 response = self.client.open(
98 '{}?manager={}'.format(
99 self.base_url, self.db_content.test_user.username
100 ),
101 method='GET',
102 headers=headers
103 )
104 assert response.status_code == 200
105 data = json.loads(response.data)
106 assert len(data) == 1
107 data = data[0]
108 self.check_key(
109 "manager", self.db_content.test_water.manager.username, data
110 )
111 self.check_key("name", self.db_content.test_water.name, data)
112 self.check_key("waterId", self.db_content.test_water.id, data)
113 self.check_key("osmId", self.db_content.test_water.osm_id, data)
114 self.check_key(
115 "osmType", self.db_content.test_water.osm_type.name, data
116 )
117
118 def test_get_by_name_manager(self):
119 """Test case getting waters by manager and water name (src)
120 """
121 headers = {}
122
123 response = self.client.open(
124 '{}?manager={}&name=Bla'.format(
125 self.base_url, self.db_content.test_user.username
126 ),
127 method='GET',
128 headers=headers
129 )
130 assert response.status_code == 200
131
132 response = self.client.open(
133 '{}?manager=john&name={}'.format(
134 self.base_url, self.db_content.test_water.name[:3]
135 ),
136 method='GET',
137 headers=headers
138 )
139 assert response.status_code == 404
140
141 response = self.client.open(
142 '{}?name={}&manager={}'.format(
143 self.base_url, self.db_content.test_water.name,
144 self.db_content.test_user.username
145 ),
146 method='GET',
147 headers=headers
148 )
149 assert response.status_code == 200
150 data = json.loads(response.data)
151 assert len(data) == 1
152 data = data[0]
153 self.check_key(
154 "manager", self.db_content.test_water.manager.username, data
155 )
156 self.check_key("name", self.db_content.test_water.name, data)
157 self.check_key("waterId", self.db_content.test_water.id, data)
158 self.check_key("osmId", self.db_content.test_water.osm_id, data)
159 self.check_key(
160 "osmType", self.db_content.test_water.osm_type.name, data
161 )
162
163
164if __name__ == '__main__':
165 unittest.main()
Note: See TracBrowser for help on using the repository browser.