Skip to content

Commit a2df8d0

Browse files
committed
add setup.py, requirements, and tests/* that were dropped with move from RosiePiApp
1 parent 2e0850e commit a2df8d0

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
node_modules
2+
.env
3+
4+
__pycache__/
5+
*.pyc
6+
7+
instance/
8+
9+
.venv/
10+
11+
.pytest_cache/
12+
13+
dist/
14+
build/
15+
*.egg-info/

requirements.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
jinja2
2+
flask
3+
redis
4+
rq

setup.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from setuptools import find_packages, setup
2+
3+
setup(
4+
name='rosiepi_node_server',
5+
version='0.0.1',
6+
packages=find_packages(),
7+
include_package_data=True,
8+
zip_safe=False,
9+
install_requires=[
10+
'flask',
11+
'jinja2',
12+
'rq',
13+
'redis'
14+
]
15+
)

tests/conftest.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import os
2+
3+
import pytest
4+
5+
from node_server import create_app
6+
7+
@pytest.fixture
8+
def app():
9+
""" Create and configure a new app instance for each test.
10+
"""
11+
app = create_app({'TESTING': True})
12+
13+
yield app
14+
15+
@pytest.fixture
16+
def client(app):
17+
""" A test client for the app.
18+
"""
19+
return app.test_client()

tests/test_nodeserver_api.py

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# The MIT License (MIT)
2+
#
3+
# Copyright (c) 2019 Michael Schroeder
4+
#
5+
# Permission is hereby granted, free of charge, to any person obtaining a copy
6+
# of this software and associated documentation files (the "Software"), to deal
7+
# in the Software without restriction, including without limitation the rights
8+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
# copies of the Software, and to permit persons to whom the Software is
10+
# furnished to do so, subject to the following conditions:
11+
#
12+
# The above copyright notice and this permission notice shall be included in
13+
# all copies or substantial portions of the Software.
14+
#
15+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
# THE SOFTWARE.
22+
#
23+
24+
from datetime import datetime
25+
import json
26+
27+
import pytest
28+
29+
from flask import jsonify
30+
31+
req_headers = {
32+
'Authorization':'Signature key-id=test-key,algorithm="hmac-sha256",headers="(request-target) date",signature=foob4r=',
33+
'Date': datetime.now().strftime('%Y-%m-%dT%H:%M:%S%Z')
34+
}
35+
36+
def test_node_deny_no_http_signature(client):
37+
""" Test node that does not have the required HTTP Signature
38+
in the Authorization header.
39+
"""
40+
41+
response = client.get('/')
42+
43+
assert response.status_code == 401
44+
45+
def test_node_status_returns_json(client):
46+
""" Test node status returning valid json.
47+
"""
48+
49+
response = client.get('/status', headers=req_headers)
50+
ret_json = response.get_json()
51+
52+
assert json.dumps(ret_json)
53+
54+
def test_node_status_return_info(client):
55+
""" Test node status returns proper info.
56+
"""
57+
response = client.get('/status', headers=req_headers)
58+
ret_json = response.get_json()
59+
60+
for item in ['node_name', 'busy', 'job_count']:
61+
assert item in ret_json
62+
63+
def test_node_runtest_get_verb(client):
64+
""" Test node RunTest GET verb
65+
"""
66+
67+
response = client.get('/run-test', headers=req_headers)
68+
69+
assert response.status_code == 405
70+
71+
def test_node_runtest_post_success(client):
72+
""" Test node RunTest with valid POST verb
73+
"""
74+
75+
payload = {
76+
'commit_sha': '123456abcdefg'
77+
}
78+
79+
response = client.post('/run-test', json=payload, headers=req_headers)
80+
81+
assert response.status_code == 200
82+
83+
def test_node_runtest_post_non_json(client):
84+
""" Test node RunTest with invalid POST verb
85+
"""
86+
87+
payload = 'null'
88+
89+
response = client.post('/run-test', data=payload, headers=req_headers)
90+
91+
assert response.status_code == 406
92+
93+
def test_node_runtest_post_no_commit_sha(client):
94+
""" Test node RunTest POST with JSON payload not containing a
95+
'commit_sha' field.
96+
"""
97+
98+
payload = {
99+
'null': 'null'
100+
}
101+
102+
response = client.post('/run-test', json=payload, headers=req_headers)
103+
104+
assert response.status_code == 400

0 commit comments

Comments
 (0)