Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Deleted old tests/utils package. Probably an unlucky auto-merge (thes…

…es utils are now in cms/test/util, notice the absence of "s")
  • Loading branch information...
commit 2a3778557b37d111be9662d8e9bfd67f3892e382 1 parent bd94a6c
Chris Glass chrisglass authored
0  cms/tests/base.py
View
No changes.
0  cms/tests/util/__init__.py
View
No changes.
103 cms/tests/util/context_managers.py
View
@@ -1,103 +0,0 @@
-from django.conf import settings
-from django.utils.translation import get_language, activate
-from shutil import rmtree as _rmtree
-from tempfile import template, mkdtemp, _exists
-import StringIO
-import sys
-
-
-class SettingsOverride(object):
- """
- Overrides Django settings within a context and resets them to their inital
- values on exit.
-
- Example:
-
- with SettingsOverride(DEBUG=True):
- # do something
- """
- def __init__(self, **overrides):
- self.overrides = overrides
-
- def __enter__(self):
- self.old = {}
- for key, value in self.overrides.items():
- self.old[key] = getattr(settings, key)
- setattr(settings, key, value)
-
- def __exit__(self, type, value, traceback):
- for key, value in self.old.items():
- setattr(settings, key, value)
-
-
-class StdoutOverride(object):
- """
- This overrides Python's the standard output and redirrects it to a StringIO
- object, so that on can test the output of the program.
-
- example:
- lines = None
- with StdoutOverride() as buffer:
- # print stuff
- lines = buffer.getvalue()
- """
- def __enter__(self):
- self.buffer = StringIO.StringIO()
- sys.stdout = self.buffer
- return self.buffer
-
- def __exit__(self, type, value, traceback):
- self.buffer.close()
- # Revert the stdout to the real one
- sys.stdout = sys.__stdout__
-
-
-
-class LanguageOverride(object):
- def __init__(self, language):
- self.newlang = language
-
- def __enter__(self):
- self.oldlang = get_language()
- activate(self.newlang)
-
- def __exit__(self, type, value, traceback):
- activate(self.oldlang)
-
-
-class TemporaryDirectory:
- """Create and return a temporary directory. This has the same
- behavior as mkdtemp but can be used as a context manager. For
- example:
-
- with TemporaryDirectory() as tmpdir:
- ...
-
- Upon exiting the context, the directory and everthing contained
- in it are removed.
- """
-
- def __init__(self, suffix="", prefix=template, dir=None):
- self.name = mkdtemp(suffix, prefix, dir)
-
- def __enter__(self):
- return self.name
-
- def cleanup(self):
- if _exists(self.name):
- _rmtree(self.name)
-
- def __exit__(self, exc, value, tb):
- self.cleanup()
-
-class UserLoginContext(object):
- def __init__(self, testcase, user):
- self.testcase = testcase
- self.user = user
-
- def __enter__(self):
- self.testcase.login_user(self.user)
-
- def __exit__(self, exc, value, tb):
- self.testcase.user = None
- self.testcase.client.logout()
21 cms/tests/util/menu_extender.py
View
@@ -1,21 +0,0 @@
-from menus.base import NavigationNode
-from menus.menu_pool import menu_pool
-from cms.menu_bases import CMSAttachMenu
-
-
-class TestMenu(CMSAttachMenu):
- name = "test menu"
-
- def get_nodes(self, request):
- nodes = []
- n = NavigationNode('sample root page', "/", 1)
- n2 = NavigationNode('sample settings page', "/bye/", 2)
- n3 = NavigationNode('sample account page', "/hello/", 3)
- n4 = NavigationNode('sample my profile page', "/hello/world/", 4, 3)
- nodes.append(n)
- nodes.append(n2)
- nodes.append(n3)
- nodes.append(n4)
- return nodes
-
-menu_pool.register_menu(TestMenu)
Please sign in to comment.
Something went wrong with that request. Please try again.