-
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
Showing
2 changed files
with
110 additions
and
18 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,64 @@ | ||
"""Basic tests for collections.""" | ||
|
||
from byte import Collection, Model, Property | ||
|
||
|
||
def test_simple_dynamic(): | ||
"""Test collection relations with dynamic models.""" | ||
class Artist(Model): | ||
class Options: | ||
collection = Collection() | ||
|
||
id = Property(int, primary_key=True) | ||
|
||
name = Property(str) | ||
|
||
class Album(Model): | ||
class Options: | ||
collection = Collection() | ||
|
||
id = Property(int, primary_key=True) | ||
artist = Property(Artist) | ||
|
||
title = Property(str) | ||
|
||
class Track(Model): | ||
class Options: | ||
collection = Collection() | ||
|
||
id = Property(int, primary_key=True) | ||
artist = Property(Artist) | ||
album = Property(Album) | ||
|
||
name = Property(str) | ||
|
||
# Create objects | ||
Artist.create( | ||
id=1, | ||
name='Daft Punk' | ||
) | ||
|
||
Album.create( | ||
id=1, | ||
artist_id=1, | ||
|
||
title='Discovery' | ||
) | ||
|
||
Track.create( | ||
id=1, | ||
artist_id=1, | ||
album_id=1, | ||
|
||
name='One More Time' | ||
) | ||
|
||
# Fetch track, and ensure relations can be resolved | ||
track = Track.Objects.get(1) | ||
|
||
assert track.id == 1 | ||
|
||
assert track.artist.id == 1 | ||
|
||
assert track.album.id == 1 | ||
assert track.album.artist.id == 1 |