-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
William MURA
authored and
William MURA
committed
Nov 5, 2014
1 parent
f278d21
commit 5d2f7b4
Showing
7 changed files
with
373 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from webserver.models import Base | ||
from sqlalchemy import Column, Integer, String | ||
from sqlalchemy.orm import relationship | ||
|
||
class Address(Base): | ||
__tablename__ = 'address' | ||
|
||
id = Column(Integer, primary_key=True) | ||
address = Column(String(100), nullable=False) | ||
zipcode = Column(String(100), nullable=False) | ||
city = Column(String(100), nullable=False) | ||
country_id = Column(Integer, ForeignKey('country.id')) | ||
country = relationship("Country") | ||
|
||
def to_dict(self): | ||
my_dict = dict() | ||
|
||
my_dict['address'] = self.address | ||
my_dict['zipcode'] = self.zipcode | ||
my_dict['city'] = self.city | ||
|
||
if self.country: | ||
my_dict['country_id'] = self.country_id | ||
my_dict['country'] = self.country.to_dict() | ||
|
||
return my_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from webserver import db | ||
from webserver.models import LineOrder, Order | ||
from webserver.tests import build_order, build_line_order, build_dish | ||
from webserver.tests import delete_orders, delete_lines_order, delete_dishes | ||
from webserver.tests.functional import FunctionalTest | ||
|
||
|
||
class Exists(FunctionalTest): | ||
""" Check if the webservice exists """ | ||
|
||
@classmethod | ||
def setup_class(cls): | ||
""" Add database fixtures """ | ||
|
||
build_order(id=5) | ||
db.session.commit() | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
""" Clear database fixtures """ | ||
|
||
delete_orders() | ||
db.session.commit() | ||
|
||
def test_exists(self): | ||
""" DELETE /orders/id: exists """ | ||
|
||
# Check request | ||
response = self.delete('/orders/5') | ||
assert response.status_code != 404 | ||
assert response.status_code != 500 | ||
|
||
|
||
class UnknownParameters(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_unkown_id(self): | ||
""" DELETE /orders/id: with unkown id """ | ||
|
||
# Check request | ||
response = self.delete('/orders/5') | ||
assert response.status_code == 404 | ||
assert response.data == "La commande n'existe pas." | ||
|
||
|
||
class Delete(FunctionalTest): | ||
""" Check with valid data """ | ||
|
||
@classmethod | ||
def setup_class(cls): | ||
""" Add database fixtures """ | ||
|
||
build_order(id=5) | ||
build_order(id=10) | ||
|
||
build_line_order(id=20, order_id=10) | ||
build_line_order(id=21, order_id=10) | ||
|
||
db.session.commit() | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
""" Clear database fixtures """ | ||
|
||
delete_orders() | ||
delete_lines_order() | ||
|
||
db.session.commit() | ||
|
||
def test_delete(self): | ||
""" DELETE /orders/id: with valid data """ | ||
|
||
# Check request | ||
response = self.delete('/orders/5') | ||
assert response.status_code == 200 | ||
|
||
# Check response | ||
result = self.parse(response.data) | ||
assert 'id' in result | ||
|
||
# Check in database | ||
order = db.session.query(Order).get(result['id']) | ||
assert order is None | ||
|
||
def test_delete_with_dishes(self): | ||
""" DELETE /orders/id: with dishes """ | ||
|
||
# Check request | ||
response = self.delete('/orders/10') | ||
assert response.status_code == 200 | ||
|
||
# Check response | ||
result = self.parse(response.data) | ||
assert 'id' in result | ||
|
||
# Check in database | ||
order = db.session.query(Order).get(result['id']) | ||
assert order is None | ||
|
||
lo1 = db.session.query(LineOrder).get(20) | ||
assert lo1 is None | ||
|
||
lo2 = db.session.query(LineOrder).get(21) | ||
assert lo2 is None |
Oops, something went wrong.