Skip to content

Commit

Permalink
Merge pull request #1 from kviktor/test
Browse files Browse the repository at this point in the history
fix tests
  • Loading branch information
kviktor authored Apr 18, 2020
2 parents 472303f + a601d86 commit 3f6ab05
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 9 deletions.
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@ language: python
python:
- "3.8"

services:
- redis-server

install:
- pip install flake8
- pip install -r server/requirements.txt
- npm -g install jshint

script:
- flake8 server/ --max-line-length=85
- jshint clients/chrome/ --exclude="clients/chrome/js/jquery.js"
- cd server
- cp .env.test .env
- flake8
- ./manage.py test
7 changes: 7 additions & 0 deletions server/.env.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
DEBUG=True
SECRET_KEY=secret

MODEL_DEF_PATH=test
PRETRAINED_MODEL_PATH=test
DATABASE_URL=sqlite::memory:
REDIS_URL=redis://localhost:6379/0
2 changes: 2 additions & 0 deletions server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ django-dramatiq==0.9.1
django-environ==0.4.5
django-redis==4.11.0
dramatiq[redis,watch]
flake8
lxml
model-mommy
redis==2.10.5
requests==2.23.0
3 changes: 3 additions & 0 deletions server/setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
exclude = .git,*migrations*
max-line-length = 90
5 changes: 3 additions & 2 deletions server/velvet/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
from io import BytesIO

import dramatiq
import numpy as np
import requests
from bs4 import BeautifulSoup as bs
from PIL import Image as PIL_Image

from django.db import transaction
from django.conf import settings
Expand Down Expand Up @@ -114,6 +112,8 @@ def resize_image(data, sz=(256, 256)):
:returns bytearray:
A byte array with the resized image
"""
from PIL import Image as PIL_Image

im = PIL_Image.open(BytesIO(data))
if im.mode != "RGB":
im = im.convert('RGB')
Expand Down Expand Up @@ -171,6 +171,7 @@ def caffe_preprocess_and_compute(pimg, caffe_transformer=None, caffe_net=None,

def classify_image(url):
import caffe # noqa
import numpy as np # noqa

response = requests.get(url)
if not (200 <= response.status_code < 300):
Expand Down
Empty file added server/velvet/tests/__init__.py
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def test_score_with_multiple_images(self):
)

def test_score_without_images(self):
article = mommy.make(Article)
mommy.make(Article)
self.assertEqual(0, Article.objects.get().score)
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from unittest import mock
from model_mommy import mommy

Expand Down Expand Up @@ -42,10 +41,9 @@ def test_no_cache_hit_in_db(self, p_cache):
self.assertEqual({
'a_1': 0.0,
'a_2': 0.0,
},response.json())
}, response.json())
p_cache.set.assert_called_once_with(mock.ANY, mock.ANY, timeout=600)


@mock.patch('velvet.views.cache')
def test_no_cache_hit_not_in_db(self, p_cache):
p_cache.get.return_value = None
Expand All @@ -57,5 +55,5 @@ def test_no_cache_hit_not_in_db(self, p_cache):

self.assertEqual({
'a_1': 0.0,
},response.json())
}, response.json())
p_cache.set.assert_called_once_with(mock.ANY, mock.ANY, timeout=15)

0 comments on commit 3f6ab05

Please sign in to comment.