source: src/mapservice/tests/test_users.py@ 3db3d13

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