source: src/mapservice/tests/test_users.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: 2.8 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 TestUsers(BaseTestCase):
24 @classmethod
25 def setUpClass(self):
26 self.base_url = '/mapservice/v1/user'
27
28 def test_users_get(self):
29 """Test case for getting users (src)
30 """
31 headers = {}
32 response = self.client.open(
33 self.base_url,
34 method='GET',
35 headers=headers)
36 assert response.status_code == 401
37
38 response = self.client.open(
39 self.base_url,
40 method='GET',
41 headers={'X-API-KEY': 'test_key'})
42 assert response.status_code == 200
43 data = json.loads(response.data)
44 self.check_key("username", "autotests", data)
45 self.check_key("firstName", "Autotests", data)
46 self.check_key("lastName", "", data)
47 self.check_key("email", "auto@example.org", data)
48 self.check_key("activated", True, data)
49 self.check_key("licenseAccepted", True, data)
50
51 assert "apiKeys" in data
52 assert data["apiKeys"][0] == "test_key"
53 assert data["apiKeys"][1] == "test_key_delete"
54
55 assert "password" not in data
56 assert "salt" not in data
57 assert "activationCode" not in data
58
59 @unittest.skip("Template not found in test environment")
60 def test_users_register(self):
61 """Test case for users_register (Src)
62 Register a new user
63 """
64 user_creation = {
65 "username" : "jane_doe",
66 "firstName" : "Jane",
67 "lastName" : "Doe",
68 "password" : "1234",
69 "licenseAccepted" : True,
70 "email" : "jane.doe@example.org"
71 }
72 headers = {
73 'Accept': 'application/json',
74 }
75 response = self.client.open(
76 self.base_url,
77 method='POST',
78 headers=headers,
79 data=json.dumps(user_creation),
80 content_type='application/json'
81 )
82 assert response.status_code == 200
83 data = json.loads(response.data)
84 self.check_key("username", user_creation['username'], data)
85 self.check_key("firstName", user_creation['firstName'], data)
86 self.check_key("lastName", user_creation['lastName'], data)
87 self.check_key("email", user_creation['email'], data)
88 self.check_key("activated", False, data)
89 self.check_key("licenseAccepted", True, data)
90
91 assert 'apiKeys' in data
92 assert len(data['apiKeys']) == 0
93
94if __name__ == '__main__':
95 unittest.main()
Note: See TracBrowser for help on using the repository browser.