| [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 |
|
|---|
| 18 | import unittest
|
|---|
| 19 | import json
|
|---|
| 20 |
|
|---|
| 21 | from . import BaseTestCase
|
|---|
| 22 |
|
|---|
| 23 | class 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 | def test_users_register(self):
|
|---|
| 60 | """Test case for users_register (Src)
|
|---|
| 61 | Register a new user
|
|---|
| 62 | """
|
|---|
| 63 | user_creation = {
|
|---|
| 64 | "username" : "jane_doe",
|
|---|
| 65 | "firstName" : "Jane",
|
|---|
| 66 | "lastName" : "Doe",
|
|---|
| 67 | "password" : "1234",
|
|---|
| 68 | "licenseAccepted" : True,
|
|---|
| 69 | "email" : "jane.doe@example.org"
|
|---|
| 70 | }
|
|---|
| 71 | headers = {
|
|---|
| 72 | 'Accept': 'application/json',
|
|---|
| 73 | }
|
|---|
| 74 | response = self.client.open(
|
|---|
| 75 | self.base_url,
|
|---|
| 76 | method='POST',
|
|---|
| 77 | headers=headers,
|
|---|
| 78 | data=json.dumps(user_creation),
|
|---|
| 79 | content_type='application/json'
|
|---|
| 80 | )
|
|---|
| 81 | assert response.status_code == 200
|
|---|
| 82 | data = json.loads(response.data)
|
|---|
| 83 | self.check_key("username", user_creation['username'], data)
|
|---|
| 84 | self.check_key("firstName", user_creation['firstName'], data)
|
|---|
| 85 | self.check_key("lastName", user_creation['lastName'], data)
|
|---|
| 86 | self.check_key("email", user_creation['email'], data)
|
|---|
| 87 | self.check_key("activated", False, data)
|
|---|
| 88 | self.check_key("licenseAccepted", True, data)
|
|---|
| 89 |
|
|---|
| 90 | assert 'apiKeys' in data
|
|---|
| 91 | assert len(data['apiKeys']) == 0
|
|---|
| 92 |
|
|---|
| 93 | if __name__ == '__main__':
|
|---|
| 94 | unittest.main()
|
|---|