-
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.
Added a prototype for the model cache version calculation.
- Loading branch information
Showing
5 changed files
with
52 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
class ModelCacheVersionCalculator(object): | ||
def get_version(model): | ||
pass |
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,19 @@ | ||
import hashlib | ||
from inspect_model import InspectModel | ||
|
||
def get_model_cache_version(model): | ||
inspected_model = InspectModel(model) | ||
|
||
fields_and_types = {} | ||
|
||
for field in inspected_model.fields: | ||
fields_and_types[field] = getattr(model, field) | ||
|
||
for field in inspected_model.relation_fields: | ||
fields_and_types[field] = getattr(model, field) | ||
|
||
|
||
for field in inspected_model.many_fields: | ||
fields_and_types[field] = getattr(model, field) | ||
|
||
return hashlib.sha1(str(fields_and_types)).hexdigest() |
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,2 +1,3 @@ | ||
Django>=1.4 | ||
django-inspect-model>=0.7.0 | ||
django-compat>=1.0.2 |
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,2 +1,4 @@ | ||
pytest>=2.7.0 | ||
pytest-django>=2.8.0 | ||
pytest-describe>=0.10.0 | ||
pytest-mock>=0.4.1 |
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 @@ | ||
import pytest | ||
import mock | ||
|
||
from cache_version.models import get_model_cache_version | ||
|
||
def describe_get_model_cache_version(): | ||
@pytest.fixture | ||
def model(): | ||
return mock.sentinel.MODEL | ||
|
||
@pytest.fixture | ||
def mocked_inspect_model(mocker): | ||
return mocker.patch('cache_version.models.InspectModel') | ||
|
||
@pytest.fixture | ||
def mocked_hashlib(mocker): | ||
return mocker.patch('cache_version.models.hashlib') | ||
|
||
def it_should_inspect_the_target_model(model, mocked_inspect_model): | ||
get_model_cache_version(model) | ||
|
||
mocked_inspect_model.assert_called_once_with(model) | ||
|
||
def it_should_return_a_hash_of_all_field_names_and_field_types(model, mocked_inspect_model, mocked_hashlib): | ||
get_model_cache_version(model) | ||
|
||
mocked_hashlib.sha1(mock.ANY).hexdigest.assert_called_once_with() |