-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
100 additions
and
24 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -3,3 +3,4 @@ model-mommy | |
freezegun | ||
coverage | ||
tox>=1.7.0 | ||
mock |
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,58 @@ | ||
from django.utils.http import urlencode | ||
from affiliate.settings import PARAM_NAME | ||
|
||
|
||
def get_aid_url(url, aid_code): | ||
return '?'.join([url, urlencode({PARAM_NAME: aid_code})]) | ||
|
||
|
||
try: | ||
from django.test import modify_settings | ||
except ImportError: | ||
from django.test.utils import override_settings, settings, six | ||
|
||
class modify_settings(override_settings): | ||
""" | ||
Like override_settings, but makes it possible to append, prepend or remove | ||
items instead of redefining the entire list. | ||
""" | ||
def __init__(self, *args, **kwargs): | ||
if args: | ||
# Hack used when instantiating from SimpleTestCase._pre_setup. | ||
assert not kwargs | ||
self.operations = args[0] | ||
else: | ||
assert not args | ||
self.operations = list(kwargs.items()) | ||
|
||
def save_options(self, test_func): | ||
if test_func._modified_settings is None: | ||
test_func._modified_settings = self.operations | ||
else: | ||
# Duplicate list to prevent subclasses from altering their parent. | ||
test_func._modified_settings = list( | ||
test_func._modified_settings) + self.operations | ||
|
||
def enable(self): | ||
self.options = {} | ||
for name, operations in self.operations: | ||
try: | ||
# When called from SimpleTestCase._pre_setup, values may be | ||
# overridden several times; cumulate changes. | ||
value = self.options[name] | ||
except KeyError: | ||
value = list(getattr(settings, name, [])) | ||
for action, items in operations.items(): | ||
# items my be a single value or an iterable. | ||
if isinstance(items, six.string_types): | ||
items = [items] | ||
if action == 'append': | ||
value = value + [item for item in items if item not in value] | ||
elif action == 'prepend': | ||
value = [item for item in items if item not in value] + value | ||
elif action == 'remove': | ||
value = [item for item in value if item not in items] | ||
else: | ||
raise ValueError("Unsupported action: %s" % action) | ||
self.options[name] = value | ||
super(modify_settings, self).enable() |