forked from thanethomson/statik
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
database.py: Allow for multiple foreign keys in same document
Allow for multiple foreign keys in the same document by telling SQLAlchemy which foreign key to look for. Closes thanethomson#27
- Loading branch information
Showing
6 changed files
with
28 additions
and
1 deletion.
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,2 @@ | ||
street: Adanac | ||
postal_code: V5K 2S6 |
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,2 @@ | ||
street: Washington | ||
postal_code: V5M 2H9 |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
first-name: Gary | ||
last-name: Merriweather | ||
email: [email protected] | ||
home_address: adanac | ||
business_address: washington |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
first-name: Michael | ||
last-name: Anderson | ||
email: [email protected] | ||
home_address: adanac | ||
business_address: washington |
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 |
---|---|---|
|
@@ -10,9 +10,15 @@ | |
from statik.models import * | ||
from statik.database import * | ||
|
||
ADDRESS_MODEL = """street: String | ||
postal_code: String | ||
""" | ||
|
||
GUEST_MODEL = """first-name: String | ||
last-name: String | ||
email: String | ||
home_address: Address | ||
business_address: Address | ||
""" | ||
|
||
GUESTHOUSE_MODEL = """guesthouse-name: String | ||
|
@@ -33,9 +39,10 @@ | |
to-date: DateTime | ||
""" | ||
|
||
MOCK_MODEL_NAMES = ['Guest', 'Guesthouse', 'GuesthouseRoom', 'Booking', 'RoomTag'] | ||
MOCK_MODEL_NAMES = ['Address', 'Guest', 'Guesthouse', 'GuesthouseRoom', 'Booking', 'RoomTag'] | ||
|
||
MOCK_MODELS = { | ||
'Address': StatikModel(name='Address', from_string=ADDRESS_MODEL, model_names=MOCK_MODEL_NAMES), | ||
'Guest': StatikModel(name='Guest', from_string=GUEST_MODEL, model_names=MOCK_MODEL_NAMES), | ||
'Guesthouse': StatikModel(name='Guesthouse', from_string=GUESTHOUSE_MODEL, model_names=MOCK_MODEL_NAMES), | ||
'GuesthouseRoom': StatikModel(name='GuesthouseRoom', from_string=GUESTHOUSE_ROOM_MODEL, model_names=MOCK_MODEL_NAMES), | ||
|
@@ -57,25 +64,35 @@ def setUp(self): | |
def test_database(self): | ||
data_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'data_test_database') | ||
db = StatikDatabase(data_path, MOCK_MODELS) | ||
Address = db.tables['Address'] | ||
Guest = db.tables['Guest'] | ||
Guesthouse = db.tables['Guesthouse'] | ||
GuesthouseRoom = db.tables['GuesthouseRoom'] | ||
Booking = db.tables['Booking'] | ||
RoomTag = db.tables['RoomTag'] | ||
|
||
addresses = db.session.query(Address).order_by(Address.street).all() | ||
guests = db.session.query(Guest).order_by(Guest.last_name).all() | ||
self.assertEqual(2, len(guests)) | ||
self.assertInstanceEqual({ | ||
'first_name': 'Michael', | ||
'last_name': 'Anderson', | ||
'pk': 'manderson', | ||
'email': '[email protected]', | ||
'home_address': addresses[0], | ||
'home_address_id': addresses[0].pk, | ||
'business_address': addresses[1], | ||
'business_address_id': addresses[1].pk, | ||
}, guests[0]) | ||
self.assertInstanceEqual({ | ||
'first_name': 'Gary', | ||
'last_name': 'Merriweather', | ||
'pk': 'gmerriweather', | ||
'email': '[email protected]', | ||
'home_address': addresses[0], | ||
'home_address_id': addresses[0].pk, | ||
'business_address': addresses[1], | ||
'business_address_id': addresses[1].pk, | ||
}, guests[1]) | ||
|
||
guesthouses = db.session.query(Guesthouse).order_by(Guesthouse.guesthouse_name).all() | ||
|