Skip to content

Commit 3f6ab05

Browse files
authored
Merge pull request #1 from kviktor/test
fix tests
2 parents 472303f + a601d86 commit 3f6ab05

File tree

9 files changed

+26
-9
lines changed

9 files changed

+26
-9
lines changed

.travis.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@ language: python
22
python:
33
- "3.8"
44

5+
services:
6+
- redis-server
7+
58
install:
6-
- pip install flake8
9+
- pip install -r server/requirements.txt
710
- npm -g install jshint
811

912
script:
10-
- flake8 server/ --max-line-length=85
1113
- jshint clients/chrome/ --exclude="clients/chrome/js/jquery.js"
14+
- cd server
15+
- cp .env.test .env
16+
- flake8
17+
- ./manage.py test

server/.env.test

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
DEBUG=True
2+
SECRET_KEY=secret
3+
4+
MODEL_DEF_PATH=test
5+
PRETRAINED_MODEL_PATH=test
6+
DATABASE_URL=sqlite::memory:
7+
REDIS_URL=redis://localhost:6379/0

server/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ django-dramatiq==0.9.1
44
django-environ==0.4.5
55
django-redis==4.11.0
66
dramatiq[redis,watch]
7+
flake8
78
lxml
9+
model-mommy
810
redis==2.10.5
911
requests==2.23.0

server/setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
exclude = .git,*migrations*
3+
max-line-length = 90

server/velvet/tasks.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
from io import BytesIO
44

55
import dramatiq
6-
import numpy as np
76
import requests
87
from bs4 import BeautifulSoup as bs
9-
from PIL import Image as PIL_Image
108

119
from django.db import transaction
1210
from django.conf import settings
@@ -114,6 +112,8 @@ def resize_image(data, sz=(256, 256)):
114112
:returns bytearray:
115113
A byte array with the resized image
116114
"""
115+
from PIL import Image as PIL_Image
116+
117117
im = PIL_Image.open(BytesIO(data))
118118
if im.mode != "RGB":
119119
im = im.convert('RGB')
@@ -171,6 +171,7 @@ def caffe_preprocess_and_compute(pimg, caffe_transformer=None, caffe_net=None,
171171

172172
def classify_image(url):
173173
import caffe # noqa
174+
import numpy as np # noqa
174175

175176
response = requests.get(url)
176177
if not (200 <= response.status_code < 300):

server/velvet/tests/__init__.py

Whitespace-only changes.

server/velvet/tests/model_tests.py renamed to server/velvet/tests/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ def test_score_with_multiple_images(self):
2323
)
2424

2525
def test_score_without_images(self):
26-
article = mommy.make(Article)
26+
mommy.make(Article)
2727
self.assertEqual(0, Article.objects.get().score)
File renamed without changes.

server/velvet/tests/view_tests.py renamed to server/velvet/tests/test_views.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import json
21
from unittest import mock
32
from model_mommy import mommy
43

@@ -42,10 +41,9 @@ def test_no_cache_hit_in_db(self, p_cache):
4241
self.assertEqual({
4342
'a_1': 0.0,
4443
'a_2': 0.0,
45-
},response.json())
44+
}, response.json())
4645
p_cache.set.assert_called_once_with(mock.ANY, mock.ANY, timeout=600)
4746

48-
4947
@mock.patch('velvet.views.cache')
5048
def test_no_cache_hit_not_in_db(self, p_cache):
5149
p_cache.get.return_value = None
@@ -57,5 +55,5 @@ def test_no_cache_hit_not_in_db(self, p_cache):
5755

5856
self.assertEqual({
5957
'a_1': 0.0,
60-
},response.json())
58+
}, response.json())
6159
p_cache.set.assert_called_once_with(mock.ANY, mock.ANY, timeout=15)

0 commit comments

Comments
 (0)