1 ################################################################################
2 # Copyright (c) 2020 AT&T Intellectual Property. #
4 # Licensed under the Apache License, Version 2.0 (the "License"); #
5 # you may not use this file except in compliance with the License. #
6 # You may obtain a copy of the License at #
8 # http://www.apache.org/licenses/LICENSE-2.0 #
10 # Unless required by applicable law or agreed to in writing, software #
11 # distributed under the License is distributed on an "AS IS" BASIS, #
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
13 # See the License for the specific language governing permissions and #
14 # limitations under the License. #
15 ################################################################################
17 from http import HTTPStatus
18 from tests.constants import mock_json_body, mock_json_body_url_without_controls, mock_json_body_url, mock_json_body_without_controls, helm_repo_index_response
21 def test_health(client):
22 response = client.get('/api/v1/health')
23 assert response.status_code == HTTPStatus.OK, 'Wrong status code'
24 assert response.json == {'status': 'OK'}, 'Improper response'
26 def test_get_charts(client):
27 response = client.get('/api/v1/charts')
28 assert response.status_code == HTTPStatus.OK, 'Wrong status code'
29 assert response.content_type == 'application/json', 'Content type error'
30 assert sorted([repr(x) for x in response.json]) == sorted([repr(x) for x in helm_repo_index_response['entries']])
32 def test_get_test_xapp_charts(client):
33 response = client.get('/api/v1/charts/xapp/test_xapp')
34 assert response.status_code == HTTPStatus.OK, 'Wrong status code'
35 assert response.content_type == 'application/json', 'Content type error'
36 assert sorted([repr(x) for x in response.json]) == sorted([repr(x) for x in helm_repo_index_response['entries']['test_xapp']])
38 def test_get_test_xapp_charts_package(client):
39 response = client.get('/api/v1/charts/xapp/test_xapp/ver/1.0.0')
40 assert response.status_code == HTTPStatus.OK, 'Wrong status code'
41 assert response.content_type == 'application/gzip', 'Content type error'
43 def test_get_test_xapp_charts_values_yaml(client):
44 response = client.get('/api/v1/charts/xapp/test_xapp/ver/1.0.0/values.yaml')
45 assert response.status_code == HTTPStatus.OK, 'Wrong status code'
46 assert response.content_type == 'text/x-yaml', 'Content type error'
48 def test_onboard_post(client):
49 url = '/api/v1/onboard'
50 response = client.post(url, json=mock_json_body)
51 assert response.status_code == HTTPStatus.CREATED, 'Wrong status code'
52 assert response.content_type == 'application/json', 'Content type error'
53 assert response.json == {'status': 'Created'}, 'Onboard failed'
55 def test_onboard_without_controls_post(client):
56 url = '/api/v1/onboard'
57 response = client.post(url, json=mock_json_body_without_controls)
58 assert response.status_code == HTTPStatus.BAD_REQUEST, 'Wrong status code'
59 assert response.content_type == 'application/json', 'Content type error'
60 assert response.json == {'error_message': "'__empty_control_section__' is a required property",
61 'error_source': 'config-file.json',
62 'status': 'Input payload validation failed'}, 'Onboard failed'
65 def test_onboard_download_post(client):
66 url = '/api/v1/onboard/download'
67 response = client.post(url, json=mock_json_body_url)
68 assert response.status_code == HTTPStatus.CREATED, 'Wrong status code'
69 assert response.content_type == 'application/json', 'Content type error'
70 assert response.json == {'status': 'Created'}, 'Onboard failed'
73 def test_onboard_download_without_controls_post(client):
74 url = '/api/v1/onboard/download'
75 response = client.post(url, json=mock_json_body_url_without_controls)
76 assert response.status_code == HTTPStatus.BAD_REQUEST, 'Wrong status code'
77 assert response.content_type == 'application/json', 'Content type error'
78 assert response.json == {'error_message': "'__empty_control_section__' is a required property",
79 'error_source': 'config-file.json',
80 'status': 'Input payload validation failed'}, 'Onboard failed'