-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:bernardopires/django-tenant-schemas
- Loading branch information
Showing
6 changed files
with
81 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from django.db import connection | ||
|
||
|
||
def make_key(key, key_prefix, version): | ||
""" | ||
Tenant aware function to generate a cache key. | ||
Constructs the key used by all other methods. Prepends the tenant | ||
`schema_name` and `key_prefix'. | ||
""" | ||
return '%s:%s:%s:%s' % (connection.schema_name, key_prefix, version, key) | ||
|
||
|
||
def reverse_key(key): | ||
""" | ||
Tenant aware function to reverse a cache key. | ||
Required for django-redis REVERSE_KEY_FUNCTION setting. | ||
""" | ||
return key.split(':', 3)[3] |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
from test_routes import * | ||
from test_tenants import * | ||
from test_cache import * |
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,13 @@ | ||
from tenant_schemas.cache import make_key, reverse_key | ||
from tenant_schemas.test.cases import TenantTestCase | ||
|
||
|
||
class CacheHelperTestCase(TenantTestCase): | ||
def test_make_key(self): | ||
key = make_key(key='foo', key_prefix='', version=1) | ||
tenant_prefix = key.split(':')[0] | ||
self.assertEqual(self.tenant.schema_name, tenant_prefix) | ||
|
||
def test_reverse_key(self): | ||
key = 'foo' | ||
self.assertEqual(key, reverse_key(make_key(key=key, key_prefix='', version=1))) |