source: src/mapservice/tests/test_waters.py@ 5c9c247

debian/bullseye
Last change on this file since 5c9c247 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
RevLine 
[be25db1]1'''
[ec9e811]2 Copyright (C) 2019 - 2020 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
[be25db1]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
[ae2ff15]21from . import BaseTestCase
[be25db1]22
23class TestWaters(BaseTestCase):
[ec9e811]24 @classmethod
25 def setUpClass(self):
[ae2ff15]26 self.base_url = '/mapservice/v1/waters'
[be25db1]27
28
[ec9e811]29 def test_get(self):
30 """Test case getting waters (src)
31 """
[be25db1]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
[ae2ff15]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)
[041e464]46
[ec9e811]47 def test_get_by_name(self):
48 """Test case getting waters by name (src)
49 """
[be25db1]50 headers = {}
51
52 response = self.client.open(
53 '{}?name=Bla'.format(self.base_url),
54 method='GET',
55 headers=headers)
[ae2ff15]56 assert response.status_code == 200
57 data = json.loads(response.data)
58 assert len(data) == 0
[be25db1]59
60 response = self.client.open(
[ae2ff15]61 '{}?name={}'.format(self.base_url, self.db_content.test_water.name[:3]),
[be25db1]62 method='GET',
63 headers=headers)
64 assert response.status_code == 200
65 data = json.loads(response.data)
66 assert len(data) == 1
[ae2ff15]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)
[be25db1]73
[ec9e811]74 def test_get_by_manager(self):
75 """Test case getting waters by manager (src)
76 """
[be25db1]77 headers = {}
78
79 response = self.client.open(
[ae2ff15]80 '{}?manager=not_existent'.format(self.base_url),
[be25db1]81 method='GET',
82 headers=headers)
[ae2ff15]83 assert response.status_code == 404, '{} != {}'.format(response.status_code, 404)
[be25db1]84
85 response = self.client.open(
[ae2ff15]86 '{}?manager={}'.format(self.base_url, self.db_content.test_user.username),
[be25db1]87 method='GET',
88 headers=headers)
89 assert response.status_code == 200
90 data = json.loads(response.data)
91 assert len(data) == 1
[ae2ff15]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)
[be25db1]98
[ec9e811]99 def test_get_by_name_manager(self):
100 """Test case getting waters by manager and water name (src)
101 """
[be25db1]102 headers = {}
103
104 response = self.client.open(
[ae2ff15]105 '{}?manager={}&name=Bla'.format(self.base_url, self.db_content.test_user.username),
[be25db1]106 method='GET',
107 headers=headers)
[ae2ff15]108 assert response.status_code == 200
[be25db1]109
110 response = self.client.open(
[ae2ff15]111 '{}?manager=john&name={}'.format(self.base_url, self.db_content.test_water.name[:3]),
[be25db1]112 method='GET',
113 headers=headers)
[ae2ff15]114 assert response.status_code == 404
[be25db1]115
116 response = self.client.open(
[ae2ff15]117 '{}?name={}&manager={}'.format(self.base_url, self.db_content.test_water.name, self.db_content.test_user.username),
[be25db1]118 method='GET',
119 headers=headers)
120 assert response.status_code == 200
121 data = json.loads(response.data)
122 assert len(data) == 1
[ae2ff15]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)
[fc99a86]129
[be25db1]130if __name__ == '__main__':
131 unittest.main()
Note: See TracBrowser for help on using the repository browser.