def setup_app(): # create test dir and populate it using the example files global tmpdir global tmproot global orig_dir # save the directory where the unit testing has been run if orig_dir is None: orig_dir = os.getcwd() # os.chdir(orig_dir) # create json files to be used by Cork tmproot = testutils.pick_conf_directory() populate_conf_directory() # purge the temporary test directory remove_temp_dir() # populate the temporary test dir tstamp = str(time())[5:] tmpdir = "%s/cork_functional_test_wd_%s" % (tmproot, tstamp) os.mkdir(tmpdir) # copy the needed files tmp_source = "%s/cork_functional_test_source" % tmproot shutil.copytree(tmp_source + "/example_conf", tmpdir + "/example_conf") shutil.copytree(orig_dir + "/test/views", tmpdir + "/views") # change to the temporary test directory # cork relies on this being the current directory os.chdir(tmpdir) # create global TestApp instance global app import simple_webapp app = TestApp(simple_webapp.app)
from nose import SkipTest from nose.tools import assert_raises, raises, with_setup from time import time import mock import os, sys import shutil from cork import Cork, AAAException, AuthException from cork import Mailer import testutils testdir = None # Test directory aaa = None # global Cork instance cookie_name = None # global variable to track cookie status tmproot = testutils.pick_conf_directory() class RoAttrDict(dict): """Read-only attribute-accessed dictionary. Used to mock beaker's session objects """ def __getattr__(self, name): return self[name] class MockedAdminCork(Cork): """Mocked module where the current user is always 'admin'""" @property def _beaker_session(self): return RoAttrDict(username='******')