Skip to content

Commit 79f1339

Browse files
committed
Get coverage near 100% fix bugs
1 parent 7d91377 commit 79f1339

File tree

5 files changed

+51
-7
lines changed

5 files changed

+51
-7
lines changed

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ prompt unuo to checkout the required Git repo and using the Dockerfile make a
66
container. If you like it can push the container on build to a Docker registry.
77

88

9+
# Install
10+
11+
Installing is pretty simple:
12+
13+
1. make a virtual environment and activate it
14+
1. ```pip install -r requirements.txt```
15+
16+
17+
# Running
18+
19+
To run the app ```python unuo/app.py```
20+
21+
922
# Unit Tests
1023

11-
python setup.py test
24+
First install dependencies: ```pip install -r requirements_test.txt```
25+
26+
To run the unit tests: ```python setup.py test```
27+
28+
or if you want to run them and get test coverage: ```./coverage.sh```

tests/basic.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def test_get_logger(self):
1010
import logging
1111
import tempfile
1212
import shutil
13+
import os
1314

1415
logs_folder = tempfile.mkdtemp()
1516
logmanager = FileLoggerManager(logs_folder)
@@ -18,6 +19,8 @@ def test_get_logger(self):
1819
l = logmanager.get_logger(build)
1920

2021
# check that folder named test exists in temp folder
22+
huh = os.path.exists(logs_folder)
23+
self.assertTrue(huh)
2124

2225
# check that there is one file handler
2326
handlers = l.handlers
@@ -39,3 +42,11 @@ def test_close_handlers(self):
3942
l = logsmanager.get_logger(build)
4043
logsmanager.close_handlers(l)
4144
shutil.rmtree(logs_folder)
45+
46+
def test_api_error(self):
47+
from unuo.errors import ApiError
48+
error = ApiError('ooops', 200)
49+
d = error.to_dict()
50+
self.assertIsNotNone(d)
51+
j = error.to_json()
52+
self.assertIsNotNone(j)

tests/unuo_tests.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ def test_profiles(self):
4545
self.assertTrue('dockertag' in j)
4646
self.assertTrue('push' in j)
4747

48+
# Get all profiles
49+
rv = self.app.get('/profile')
50+
self.assertEquals(200, rv.status_code)
51+
j = json.loads(rv.data)
52+
self.assertEquals(1, len(j['builds']))
53+
4854
# Get the profile
4955
rv = self.app.get('/profile/test')
5056
self.assertEquals(200, rv.status_code)
@@ -53,7 +59,18 @@ def test_profiles(self):
5359
self.assertTrue('dockertag' in j)
5460
self.assertTrue('push' in j)
5561

56-
# Run a build (mock out docker commands)
62+
# Get a non-existing profile
63+
rv = self.app.get('/profile/nope')
64+
self.assertEquals(404, rv.status_code)
65+
66+
# Run a build
5767
rv = self.app.post('/build/test')
5868
self.assertEquals(200, rv.status_code)
5969
self.assertTrue('line1' in rv.data)
70+
71+
# Post bad profile
72+
rv = self.app.post(
73+
'/profile/ooops',
74+
data=json.dumps(dict(joe='shmoe')),
75+
content_type='application/json')
76+
self.assertEquals(400, rv.status_code)

unuo/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ class ApiError(Exception):
1111
"""
1212
code = 400
1313

14-
def __init__(self, description, code=None, payload=None):
14+
def __init__(self, description, code=None):
1515
Exception.__init__(self)
1616
self.description = description
1717
if code is not None:
1818
self.code = code
1919

2020
def to_dict(self):
21-
return {'message': self.description, 'status_code': self.status_code}
21+
return {'message': self.description, 'status_code': self.code}
2222

2323
def to_json(self):
2424
return json.dumps(self.to_dict())

unuo/filebackend.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def get_all_profiles(self):
6565
builds = []
6666
for phile in listdir(self.builds_folder):
6767
fp = os.path.join(self.builds_folder, phile)
68-
if not os.path.isfile(fp):
69-
continue
70-
builds.append(phile)
68+
if os.path.isfile(fp):
69+
builds.append(phile)
7170
return builds

0 commit comments

Comments
 (0)