Commit c3928689 authored by Baumgärtner Lea's avatar Baumgärtner Lea

Added two small route tests

parent 1d81732f
......@@ -3,12 +3,17 @@ FROM python:3
WORKDIR /webapp
COPY . /webapp
RUN pip install --upgrade pip
RUN pip install flask
RUN pip install ibm_watson
RUN pip install flask_cors
RUN pip install PILLOW
RUN pip install flask-Testing
RUN pip install pytest
EXPOSE 4000
CMD ["python", "app.py"]
This diff is collapsed.
from flask import Flask, jsonify
from app import app
import json
import flask_testing
import pytest
test_image = open("encoded_kevin.txt", "w+")
@pytest.fixture
def client():
app.config['TESTING'] = True
client = app.test_client()
return client
@pytest.fixture
def fake_image():
data = {"image": test_image}
return data
def test_get_route(client):
url = '/'
response = client.get(url)
assert response.status_code == 200
def test_post_route(client, fake_image):
url = '/advice'
client.get(url)
d = {"image": test_image}
assert fake_image['image'] == d['image']
......@@ -2,7 +2,7 @@ import visual_recognition
import json
import random
local_image = 'kevin.jpg'
local_image = 'test/kevin.jpg'
with open('util/advices.json') as json_file:
advices = json.load(json_file)
......@@ -22,7 +22,6 @@ def predict_mood(image):
classifier_ids='DefaultCustomModel_1997094634').get_result()
def get_emotion_json(result_of_image):
data = json.loads(result_of_image)
first_dict = data['images']
......
from flask import Flask, jsonify
from sqlalchemy.testing.pickleable import User
from flask_testing import TestCase
from flask_testing import LiveServerTestCase
import urllib3
from app import create_app, db
import unittest
class MyTest(TestCase):
def create_app(self):
app = Flask(__name__)
app.config['TESTING'] = True
return app
class MyTest(LiveServerTestCase):
def create_app(self):
app = Flask(__name__)
app.config['TESTING'] = True
# Set to 0 to have the OS pick the port.
app.config['LIVESERVER_PORT'] = 0
return app
def test_server_is_up_and_running(self):
response = urllib3.urlopen(self.get_server_url())
self.assertEqual(response.code, 200)
@app.route("/ajax/")
def some_json():
return jsonify(success=True)
class TestViews(TestCase):
def test_some_json(self):
response = self.client.get("/ajax/")
self.assertEquals(response.json, dict(success=True))
class TestNotRenderTemplates(TestCase):
render_templates = False
def test_assert_mytemplate_used(self):
response = self.client.get("/template/")
self.assert_template_used('index.html')
class MyTest(TestCase):
SQLALCHEMY_DATABASE_URI = "sqlite://"
TESTING = True
def create_app(self):
# pass in test configuration
return create_app(self)
def setUp(self):
db.create_all()
def tearDown(self):
db.session.remove()
db.drop_all()
class SomeTest(MyTest):
def test_something(self):
user = User()
db.session.add(user)
db.session.commit()
# this works
assert user in db.session
response = self.client.get("/")
# this raises an AssertionError
assert user in db.session
# your test cases
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment