source: src/gnuboat/mapservice_impl/tests/test_users.py

debian/bullseye
Last change on this file was 9f0f35e, checked in by Joachim Langenbach <joachim.langenbach@…>, 7 years ago
  • Switched from CamelCase to camel_case naming
    • Added mapservice-webclient to configure script (Closes #33)
    • Switched from unittest to pytest tests
    • Fixed testing errors with post datas by introducing x-fail vendor extension
    • Added x-vendor extension to mark a dependency on mapservice for an operation and the controller_test.mustache adds needed fixtures
    • Copying conftest.py from *_impl/tests into */test (it's a workaround to get the flask app fixtures)
    • Fixed controller_test.mustache, to test the first response with set status code
  • Property mode set to 100644
File size: 2.7 KB
Line 
1'''
2 Copyright (C) 2019 - 2020 EngSaS - 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 pytest
19import json
20
21from . import check_key
22
23base_url = '/mapservice/v1/user'
24
25
26def test_users_get(client):
27 """Test case for getting users (src)
28 """
29 headers = {}
30 response = client.open(
31 base_url, method='GET', headers=headers
32 )
33 assert response.status_code == 401
34
35 response = client.open(
36 base_url, method='GET', headers={'X-API-KEY': 'test_key'}
37 )
38 assert response.status_code == 200
39 data = response.json
40 check_key("username", "autotests", data)
41 check_key("firstName", "Autotests", data)
42 check_key("lastName", "", data)
43 check_key("email", "auto@example.org", data)
44 check_key("activated", True, data)
45 check_key("licenseAccepted", True, data)
46
47 assert "apiKeys" in data
48 assert data["apiKeys"][0] == "test_key"
49 assert data["apiKeys"][1] == "test_key_delete"
50
51 assert "password" not in data
52 assert "salt" not in data
53 assert "activationCode" not in data
54
55
56def test_impl_users_register(client):
57 """Test case for users_register (Src)
58 Register a new user
59 """
60 user_creation = {
61 "username": "jane_doe",
62 "firstName": "Jane",
63 "lastName": "Doe",
64 "password": "1234",
65 "licenseAccepted": True,
66 "email": "jane.doe@example.org"
67 }
68 headers = {
69 'Accept': 'application/json',
70 }
71 response = client.open(
72 base_url,
73 method='POST',
74 headers=headers,
75 data=json.dumps(user_creation),
76 content_type='application/json'
77 )
78 assert response.status_code == 200
79 data = response.json
80 check_key("username", user_creation['username'], data)
81 check_key("firstName", user_creation['firstName'], data)
82 check_key("lastName", user_creation['lastName'], data)
83 check_key("email", user_creation['email'], data)
84 check_key("activated", False, data)
85 check_key("licenseAccepted", True, data)
86
87 assert 'apiKeys' in data
88 assert len(data['apiKeys']) == 0
Note: See TracBrowser for help on using the repository browser.