Skip to content

Commit ae66418

Browse files
committed
Expanded tests for #6
1 parent 676761a commit ae66418

File tree

4 files changed

+45
-0
lines changed

4 files changed

+45
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
![GitHub License](https://img.shields.io/github/license/Veinar/dracan?style=flat)
55
![Code style](https://img.shields.io/badge/code%20style-black-black)
6+
[![codecov](https://codecov.io/github/Veinar/dracan/graph/badge.svg?token=LNPKYPY8RB)](https://codecov.io/github/Veinar/dracan)
67
![Docker Image Size](https://img.shields.io/docker/image-size/veinar/dracan)
78
![Docker Pulls](https://img.shields.io/docker/pulls/veinar/dracan?color=yellow)
89
![Contrib Welcome](https://img.shields.io/badge/contributions-welcome-blue)

rules_config.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
},
1616
"uri_validation_enabled": true,
1717
"allowed_uris": [
18+
"/",
1819
"/health",
1920
"/data",
2021
"/update",

tests/destination_mock.py

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

33
app = Flask(__name__)
44

5+
# Root endpoint to test the base proxy route without a sub-path
6+
@app.route('/', methods=['GET', 'POST', 'PUT', 'DELETE'])
7+
def root_endpoint():
8+
if request.method == 'GET':
9+
return jsonify({'status': 'root accessed', 'method': 'GET'}), 200
10+
elif request.method == 'POST':
11+
data = request.get_json()
12+
return jsonify({'status': 'root accessed', 'method': 'POST', 'received_data': data}), 201
13+
elif request.method == 'PUT':
14+
data = request.get_json()
15+
return jsonify({'status': 'root accessed', 'method': 'PUT', 'update_info': data}), 200
16+
elif request.method == 'DELETE':
17+
return jsonify({'status': 'root accessed', 'method': 'DELETE', 'message': 'Resource deleted'}), 204
18+
519
# Simple /health endpoint to return a health status
620
@app.route('/health', methods=['GET'])
721
def health_check():

tests/test_dracan.py

+29
Original file line numberDiff line numberDiff line change
@@ -215,3 +215,32 @@ def test_unsupported_methods_on_data(run_dracan_server):
215215
# CONNECT
216216
response = requests.request("CONNECT", url, headers=headers, timeout=5)
217217
assert response.status_code == 405 # Method Not Allowed
218+
219+
def test_root_get_request(run_dracan_server):
220+
headers = {"Content-Type": "application/json", "X-API-KEY": "test_key", "Authorization": "Bearer token123.abc.xyz"}
221+
response = requests.get("http://127.0.0.1:5000/", headers=headers, timeout=5)
222+
assert response.status_code == 200
223+
assert response.json() == {'status': 'root accessed', 'method': 'GET'}
224+
225+
def test_root_post_request(run_dracan_server):
226+
headers = {"Content-Type": "application/json", "X-API-KEY": "test_key", "Authorization": "Bearer token123.abc.xyz"}
227+
data = {"name": "Jane", "age": 28}
228+
response = requests.post("http://127.0.0.1:5000/", json=data, headers=headers, timeout=5)
229+
assert response.status_code == 201
230+
assert response.json() == {'status': 'root accessed', 'method': 'POST', 'received_data': data}
231+
232+
def test_root_put_request(run_dracan_server):
233+
headers = {"Content-Type": "application/json", "X-API-KEY": "test_key", "Authorization": "Bearer token123.abc.xyz"}
234+
data = {"name": "Jane", "age": 29}
235+
response = requests.put("http://127.0.0.1:5000/", json=data, headers=headers, timeout=5)
236+
assert response.status_code == 200
237+
assert response.json() == {'status': 'root accessed', 'method': 'PUT', 'update_info': data}
238+
239+
def test_root_delete_request(run_dracan_server):
240+
headers = {"Content-Type": "application/json", "X-API-KEY": "test_key", "Authorization": "Bearer token123.abc.xyz"}
241+
response = requests.delete("http://127.0.0.1:5000/", headers=headers, timeout=5)
242+
243+
def test_root_delete_request(run_dracan_server):
244+
headers = {"Content-Type": "application/json", "X-API-KEY": "test_key", "Authorization": "Bearer token123.abc.xyz"}
245+
response = requests.delete("http://127.0.0.1:5000/", headers=headers, timeout=5)
246+
assert response.status_code == 204

0 commit comments

Comments
 (0)