Skip to content

Commit

Permalink
Merge pull request #57 from Keep-Current/bugfix/56-app-crashes-on
Browse files Browse the repository at this point in the history
changed the initialization to run the app
  • Loading branch information
liadmagen committed Sep 24, 2018
2 parents ceb72c2 + ed62b3e commit cf2d1c3
Show file tree
Hide file tree
Showing 10 changed files with 565 additions and 237 deletions.
6 changes: 4 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ gunicorn = "*"
"flake8" = "*"
Flask = "*"
Sphinx = "*"
pylint = "*"
black = "*"
requests = "*"

[dev-packages]
pylint = "*"
black = "*"
responses = "*"

[requires]
python_version="3.6"
Expand Down
405 changes: 237 additions & 168 deletions Pipfile.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Executes the app when running using gunicorn
"""


from webminer.external_interfaces.flask_server.app import create_app
app = create_app()

if __name__ == '__main__':
app = create_app()
app.run()
3 changes: 2 additions & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ pytest-flask
codecov
gunicorn
flake8
Sphinx
Sphinx
responses
7 changes: 5 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""This tests the basic configuration and creating an app
"""

import pytest


from webminer.external_interfaces.flask_server.app import create_app
from webminer.external_interfaces.flask_server.settings import TestConfig


@pytest.yield_fixture(scope='function')
@pytest.fixture(scope='function')
def app():
return create_app(TestConfig)
return create_app(TestConfig)
52 changes: 33 additions & 19 deletions tests/entities/test_arxiv_document.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
"""Tests the arxiv model
"""

import uuid
from webminer.entities import arxiv_document as ad

test_url = "https://arxiv.org/abs/1801.06605"
test_title = "A Collaborative Filtering Recommender System"
test_abstract = "The use of relevant metrics of software systems could improve various software engineering tasks, but"
test_abstract = "The use of relevant metrics of software systems " + \
"could improve various software engineering tasks, but"
test_authors = ["Maral Azizi", "Hyunsook Do"]
test_publish_date = "Sat, 20 Jan 2018 00:11:42"
test_pdf_url = "https://arxiv.org/pdf/1801.06605"


def test_arxivDoc_model_init():
def test_arxiv_doc_model_init():
"""Tests a successful creation of a arxiv doc model
"""

code = uuid.uuid4()
arxivDoc = ad.ArxivDocument(
arxiv_doc = ad.ArxivDocument(
doc_id=code,
url=test_url,
title=test_title,
Expand All @@ -20,18 +27,21 @@ def test_arxivDoc_model_init():
publish_date=test_publish_date,
pdf_url=test_pdf_url,
)
assert arxivDoc.doc_id == code
assert arxivDoc.url == test_url
assert arxivDoc.title == test_title
assert arxivDoc.abstract == test_abstract
assert arxivDoc.authors == test_authors
assert arxivDoc.publish_date == test_publish_date
assert arxivDoc.pdf_url == test_pdf_url
assert_equal(arxiv_doc.doc_id, code)
assert_equal(arxiv_doc.url, test_url)
assert_equal(arxiv_doc.title, test_title)
assert_equal(arxiv_doc.abstract, test_abstract)
assert_equal(arxiv_doc.authors, test_authors)
assert_equal(arxiv_doc.publish_date, test_publish_date)
assert_equal(arxiv_doc.pdf_url, test_pdf_url)


def test_arxivDoc_model_from_dict():
def test_arxiv_doc_model_from_dict():
"""Tests a successful creation of a arxiv doc model from a
dictionary object
"""
code = uuid.uuid4()
arxivDoc = ad.ArxivDocument.from_dict(
arxiv_doc = ad.ArxivDocument.from_dict(
{
"doc_id": code,
"url": test_url,
Expand All @@ -42,10 +52,14 @@ def test_arxivDoc_model_from_dict():
"links": [{"title": "pdf", "href": "https://arxiv.org/pdf/1801.06605"}],
}
)
assert arxivDoc.doc_id == code
assert arxivDoc.url == test_url
assert arxivDoc.title == test_title
assert arxivDoc.abstract == test_abstract
assert arxivDoc.authors == test_authors
assert arxivDoc.publish_date == test_publish_date
assert arxivDoc.pdf_url == test_pdf_url
assert_equal(arxiv_doc.doc_id, code)
assert_equal(arxiv_doc.url, test_url)
assert_equal(arxiv_doc.title, test_title)
assert_equal(arxiv_doc.abstract, test_abstract)
assert_equal(arxiv_doc.authors, test_authors)
assert_equal(arxiv_doc.publish_date, test_publish_date)
assert_equal(arxiv_doc.pdf_url, test_pdf_url)

def assert_equal(arg1, arg2):
if arg1 != arg2:
raise AssertionError("Assert equal failed - values are not equal")
69 changes: 53 additions & 16 deletions tests/interface_adapters/test_process_arxiv_request.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import pytest
"""Testing the serialization of the use-case ouput
"""

from unittest import mock
import pytest

from webminer.entities.arxiv_document import ArxivDocument
from webminer.interface_adapters.rest_adapters import response_object as res
Expand All @@ -8,7 +11,10 @@


@pytest.fixture
def domain_storagerooms():
def domain_arxivdocs():
"""Creates a fixture for the returned objects
"""

arxiv_doc_1 = ArxivDocument(
doc_id="url_1",
url="url_1",
Expand Down Expand Up @@ -52,24 +58,43 @@ def domain_storagerooms():
return [arxiv_doc_1, arxiv_doc_2, arxiv_doc_3, arxiv_doc_4]


def test_arxiv_doc_list_without_parameters(domain_storagerooms):
def test_arxiv_doc_list_without_parameters(domain_arxivdocs):
"""Tests calling the ProcessArxivDocuments method without any params
Args:
domain_arxivdocs ([type]): the expected results
Raises:
AssertionError: If nothing was returned
AssertionError: If the response is not the expected one
"""

repo = mock.Mock()
repo.list.return_value = domain_storagerooms
repo.list.return_value = domain_arxivdocs

arxiv_doc_list_use_case = uc.ProcessArxivDocuments(repo)
request_object = req.ArxivDocumentListRequestObject.from_dict({})

response_object = arxiv_doc_list_use_case.execute(request_object)

assert bool(response_object) is True
if not bool(response_object):
raise AssertionError("response_object is empty")
repo.list.assert_called_with(filters=None)

assert response_object.value == domain_storagerooms
if response_object.value != domain_arxivdocs:
raise AssertionError("respons differs form expected")


def test_arxiv_doc_list_with_filters(domain_arxivdocs):
"""Tests calling the usecase filter with parameters
TODO - implement that part.
Args:
domain_arxivdocs ([type]): The expected filtered documents
"""

def test_arxiv_doc_list_with_filters(domain_storagerooms):
repo = mock.Mock()
repo.list.return_value = domain_storagerooms
repo.list.return_value = domain_arxivdocs

arxiv_doc_list_use_case = uc.ProcessArxivDocuments(repo)
qry_filters = {"a": 5}
Expand All @@ -79,12 +104,17 @@ def test_arxiv_doc_list_with_filters(domain_storagerooms):

response_object = arxiv_doc_list_use_case.execute(request_object)

assert bool(response_object) is True
if not bool(response_object):
raise AssertionError("response_object is empty")
repo.list.assert_called_with(filters=qry_filters)
assert response_object.value == domain_storagerooms
if response_object.value != domain_arxivdocs:
raise AssertionError("respons differs form expected")


def test_arxiv_doc_list_handles_generic_error():
"""Tests handling of a generic error when the request is empty
"""

repo = mock.Mock()
repo.list.side_effect = Exception("Just an error message")

Expand All @@ -93,23 +123,30 @@ def test_arxiv_doc_list_handles_generic_error():

response_object = arxiv_doc_list_use_case.execute(request_object)

assert bool(response_object) is False
assert response_object.value == {
if bool(response_object):
raise AssertionError("response_object supposed to be empty")
if response_object.value != {
"type": res.ResponseFailure.SYSTEM_ERROR,
"message": "Exception: Just an error message",
}
}:
raise AssertionError("error response differs from expected")


def test_arxiv_doc_list_handles_bad_request():
"""Tests handling a usecase with a bad request
"""

repo = mock.Mock()

arxiv_doc_list_use_case = uc.ProcessArxivDocuments(repo)
request_object = req.ArxivDocumentListRequestObject.from_dict({"filters": 5})

response_object = arxiv_doc_list_use_case.execute(request_object)

assert bool(response_object) is False
assert response_object.value == {
if bool(response_object):
raise AssertionError("response_object supposed to be empty")
if response_object.value != {
"type": res.ResponseFailure.PARAMETERS_ERROR,
"message": "filters: Is not iterable",
}
}:
raise AssertionError("error response differs from expected")
Loading

0 comments on commit cf2d1c3

Please sign in to comment.