-
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.
Add json model snapshots + tests (#32)
* add json model snapshots + tests * remove python 3.11
- Loading branch information
Showing
5 changed files
with
108 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,7 @@ name = django-ckc | |
author = Eric Carmichael | ||
author_email = [email protected] | ||
description = tools, utilities, etc. we use across projects @ ckc | ||
version = 0.0.8 | ||
version = 0.0.9 | ||
url = https://github.com/ckcollab/django-ckc | ||
keywords = | ||
django | ||
|
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,42 @@ | ||
import pytest | ||
from rest_framework.test import APITestCase | ||
|
||
from testapp.models import SnapshottedModel, SnapshottedModelMissingOverride | ||
|
||
|
||
class TestJsonSnapshottedModels(APITestCase): | ||
def test_snapshot_model_asserts_method_must_be_implemented_if_it_is_missing(self): | ||
instance = SnapshottedModelMissingOverride() | ||
|
||
# make sure proper error raised when we try to snapshot with a missing method | ||
with pytest.raises(NotImplementedError): | ||
instance.take_snapshot() | ||
|
||
def test_snapshot_model_save_actually_saves_to_databse(self): | ||
instance = SnapshottedModel() | ||
instance.take_snapshot() | ||
|
||
# Snapshot was written to model... | ||
assert instance.snapshot == {"test": "snapshot"} | ||
|
||
instance.save() | ||
|
||
# Snapshot was saved to database, forreal | ||
assert SnapshottedModel.objects.get(snapshot__test="snapshot") | ||
|
||
def test_snapshotting_an_already_snapshotted_model_raises_exception_unless_forced(self): | ||
instance = SnapshottedModel() | ||
instance.take_snapshot() | ||
|
||
# trying to snapshot already snapshotted model -> shit the bed | ||
with pytest.raises(Exception): | ||
instance.take_snapshot() | ||
|
||
# Clear snapshot to see if we can re-set it.. | ||
instance.snapshot = None | ||
|
||
# No exception raised here! And data was properly written | ||
instance.take_snapshot(force=True) | ||
|
||
# We were able to re-snapshot | ||
assert instance.snapshot == {"test": "snapshot"} |