Skip to content

Commit

Permalink
update test to reach 100% cover
Browse files Browse the repository at this point in the history
  • Loading branch information
william57m committed Nov 6, 2014
1 parent b33f053 commit 4600482
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 2 deletions.
4 changes: 2 additions & 2 deletions webserver/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@


# Address
def build_address(id, address="1010 Avenue de la banquise", zipcode="H1S1R1", city="Montreal", country=None):
def build_address(id, address="1010 Avenue de la banquise", zipcode="H1S1R1", city="Montreal", country=None, personne_id=None):
""" Builder to create an address in database """

if country is None:
country = build_country(id=id)

address = Address(id=id, address=address, zipcode=zipcode, city=city, country=country)
address = Address(id=id, address=address, zipcode=zipcode, city=city, country=country, personne_id=personne_id)
db.session.add(address)

return address
Expand Down
114 changes: 114 additions & 0 deletions webserver/tests/functional/address/test_list.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# -*- coding: utf-8 -*-

from webserver import db
from webserver.models import Entrepreneur
from webserver.tests import build_address, build_client
from webserver.tests import delete_addresses, delete_clients
from webserver.tests.functional import FunctionalTest


class Exists(FunctionalTest):
""" Check if the webservice exists """

@classmethod
def setup_class(cls):
""" Add database fixtures """

pass

@classmethod
def teardown_class(cls):
""" Clear database fixtures """

pass

def test_exists(self):
""" GET /addresses: exists """

# Check request
response = self.get('/addresses')
assert response.status_code != 404
assert response.status_code != 500


class Empty(FunctionalTest):
""" Check with no datas """

@classmethod
def setup_class(cls):
""" Add database fixtures """

pass

@classmethod
def teardown_class(cls):
""" Clear database fixtures """

pass

def test_empty(self):
""" GET /addresses: empty """

# Check request
response = self.get('/addresses')
assert response.status_code == 200

# Check length
result = self.parse(response.data)
assert len(result) == 0


class List(FunctionalTest):
""" Check with valid data """

@classmethod
def setup_class(cls):
""" Add database fixtures """

build_address(id=1)
build_address(id=2)

build_client(id=88)
build_address(id=4, personne_id=88)
db.session.commit()

@classmethod
def teardown_class(cls):
""" Clear database fixtures """

delete_addresses()
delete_clients()

db.session.commit()

def test_list(self):
""" GET /addresses: list """

# Check request
response = self.get('/addresses')
assert response.status_code == 200

# Check length
result = self.parse(response.data)
assert len(result) == 3

# Check id
result_id = [r['id'] for r in result]
assert 1 in result_id
assert 2 in result_id
assert 4 in result_id

def test_list_with_personne(self):
""" GET /addresses?personne_id=id: list with personne_id """

# Check request
response = self.get('/addresses?personne_id=88')
assert response.status_code == 200

# Check length
result = self.parse(response.data)
assert len(result) == 1

# Check id
result_id = [r['id'] for r in result]
assert 4 in result_id

0 comments on commit 4600482

Please sign in to comment.