Skip to content

Commit

Permalink
Merge pull request #43 from jacobb/cache_key_proeprty
Browse files Browse the repository at this point in the history
Add basic cache_key property on Resource objects
  • Loading branch information
jacobb committed May 22, 2014
2 parents e993e86 + 217487d commit 520507d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions nap/resources.py
Expand Up @@ -149,6 +149,16 @@ def to_python(self, for_read=False):

return obj_dict

@property
def cache_key(self):

# This really needs to be cleaned up
lookup_url = self.objects.get_lookup_url(self)
full_url = self.objects.get_full_url(lookup_url)
cache_key = self.objects.cache.get_cache_key(self.__class__, full_url)

return cache_key

# properties
@property
def full_url(self):
Expand Down
5 changes: 5 additions & 0 deletions tests/test_resources.py
Expand Up @@ -138,6 +138,11 @@ def test_eq(self):
assert dm != dm3
assert dm != object()

def test_cache_key_method(self):
dm = SampleResourceModel(slug='some-slug')

assert dm.cache_key == "note::http://foo.com/v1/note/some-slug/"


class TestResourceAuth(object):

Expand Down

0 comments on commit 520507d

Please sign in to comment.