-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* prototype for `UpdateSelf` * fleshed out implementation * add tests * update docstring - use `Band` table as an example * improve docs * finish docs
- Loading branch information
1 parent
df86c2e
commit e36a9ed
Showing
4 changed files
with
162 additions
and
9 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
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,27 @@ | ||
from piccolo.testing.test_case import AsyncTableTest | ||
from tests.example_apps.music.tables import Band, Manager | ||
|
||
|
||
class TestUpdateSelf(AsyncTableTest): | ||
|
||
tables = [Band, Manager] | ||
|
||
async def test_update_self(self): | ||
band = Band({Band.name: "Pythonistas", Band.popularity: 1000}) | ||
|
||
# Make sure we get a ValueError if it's not in the database yet. | ||
with self.assertRaises(ValueError): | ||
await band.update_self({Band.popularity: Band.popularity + 1}) | ||
|
||
# Save it, so it's in the database | ||
await band.save() | ||
|
||
# Make sure we can successfully update the object | ||
await band.update_self({Band.popularity: Band.popularity + 1}) | ||
|
||
# Make sure the value was updated on the object | ||
assert band.popularity == 1001 | ||
|
||
# Make sure the value was updated in the database | ||
await band.refresh() | ||
assert band.popularity == 1001 |