def setUp(self): self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES breadcrumbs_middleware_class = 'breadcrumbs.middleware.BreadcrumbsMiddleware' if breadcrumbs_middleware_class not in settings.MIDDLEWARE_CLASSES: settings.MIDDLEWARE_CLASSES += (breadcrumbs_middleware_class, ) self.old_TEMPLATE_CONTEXT_PROCESSORS = settings.TEMPLATE_CONTEXT_PROCESSORS request_processor = 'django.core.context_processors.request' if request_processor not in settings.TEMPLATE_CONTEXT_PROCESSORS: settings.TEMPLATE_CONTEXT_PROCESSORS += (request_processor, ) self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'), ) # now we start singleton. singleton are tested on singleton_tests.py self.breadcrumbs = Breadcrumbs() # set some common ta to use SD = SortedDict self.data = [ SD([('name', 'Page1'), ('url', '/page1/')]), SD([('name', 'Page2'), ('url', '/page2/')]), SD([('name', 'Page3'), ('url', '/page2/page3/')]), SD([('name', 'Page4'), ('url', '/page4/')]), SD([('name', 'Page5'), ('url', '/page5/')]), ]
class FlatpagesTest(TestCase): fixtures = ['sample_flatpages_for_breadcrumbs.json'] def setUp(self): breadcrumbs_middleware_class = 'breadcrumbs.middleware.BreadcrumbsMiddleware' flatpages_middleware_class = 'breadcrumbs.middleware.FlatpageFallbackMiddleware' # remove breadcrumbs middlewares to assert that we set correct # order self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES settings.MIDDLEWARE_CLASSES = [mid for mid \ in self.old_MIDDLEWARE_CLASSES if mid not in \ (breadcrumbs_middleware_class, flatpages_middleware_class)] settings.MIDDLEWARE_CLASSES += [ breadcrumbs_middleware_class, flatpages_middleware_class ] self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS settings.TEMPLATE_DIRS = ( os.path.join( os.path.dirname(__file__), 'templates' ), ) # now we start singleton. singleton are tested on singleton_tests.py self.breadcrumbs = Breadcrumbs() def tearDown(self): settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES # kill singleton self.breadcrumbs._drop_it() def test_flatpages_fixture_loaded(self): flat1 = FlatPage.objects.get(pk=1) self.assertEqual(flat1.title, u"Flat Page 1") self.assertEqual(flat1.content, u"This is flat 1") flat2 = FlatPage.objects.get(pk=2) self.assertEqual(flat2.title, u"Flat page 2") self.assertEqual(flat2.content, u"This is flat 2 under flat 1") def test_404_flatpage(self): response = self.client.get('/404_not_found/') self.assertEqual(response.status_code, 404) # self.assertContains(response, "<p>Isn't it flat!</p>") def test_fallback_flatpage(self): response = self.client.get('/flat01/') self.assertEqual(response.status_code, 200) self.assertContains(response, '<ul id="breadcrumbs"><li><a href="/flat01/">Flat Page 1</a></li></ul>') response = self.client.get('/flat01/flat02/') self.assertEqual(response.status_code, 200) self.assertContains(response, '<ul id="breadcrumbs"><li><a href="/flat01/">Flat Page 1</a> » </li><li><a href="/flat01/flat02/">Flat page 2</a></li></ul>')
class FlatpagesTest(TestCase): fixtures = ['sample_flatpages_for_breadcrumbs.json'] def setUp(self): breadcrumbs_middleware_class = 'breadcrumbs.middleware.BreadcrumbsMiddleware' flatpages_middleware_class = 'breadcrumbs.middleware.FlatpageFallbackMiddleware' # remove breadcrumbs middlewares to assert that we set correct # order self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES settings.MIDDLEWARE_CLASSES = [mid for mid \ in self.old_MIDDLEWARE_CLASSES if mid not in \ (breadcrumbs_middleware_class, flatpages_middleware_class)] settings.MIDDLEWARE_CLASSES += [ breadcrumbs_middleware_class, flatpages_middleware_class ] self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'), ) # now we start singleton. singleton are tested on singleton_tests.py self.breadcrumbs = Breadcrumbs() def tearDown(self): settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES # kill singleton self.breadcrumbs._drop_it() def test_flatpages_fixture_loaded(self): flat1 = FlatPage.objects.get(pk=1) self.assertEqual(flat1.title, u"Flat Page 1") self.assertEqual(flat1.content, u"This is flat 1") flat2 = FlatPage.objects.get(pk=2) self.assertEqual(flat2.title, u"Flat page 2") self.assertEqual(flat2.content, u"This is flat 2 under flat 1") def test_404_flatpage(self): response = self.client.get('/404_not_found/') self.assertEqual(response.status_code, 404) # self.assertContains(response, "<p>Isn't it flat!</p>") def test_fallback_flatpage(self): response = self.client.get('/flat01/') self.assertEqual(response.status_code, 200) self.assertContains( response, '<ul id="breadcrumbs"><li><a href="/flat01/">Flat Page 1</a></li></ul>' ) response = self.client.get('/flat01/flat02/') self.assertEqual(response.status_code, 200) self.assertContains( response, '<ul id="breadcrumbs"><li><a href="/flat01/">Flat Page 1</a> » </li><li><a href="/flat01/flat02/">Flat page 2</a></li></ul>' )
def test_breadcrumbs_singleton(self): brd = Breadcrumbs() brd(**self.data[0]) brd2 = Breadcrumbs() brd2(**self.data[1]) # test 3 instances to see if singleton really works self.assertEqual(self.breadcrumbs[0].__dict__, Breadcrumb(**self.data[0]).__dict__) self.assertEqual(self.breadcrumbs[1].__dict__, Breadcrumb(**self.data[1]).__dict__) self.assertEqual(brd[1].__dict__, Breadcrumbs()[1].__dict__)
def tearDown(self): settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS # settings.LOGIN_URL = self.old_LOGIN_URL # kill singleton Breadcrumbs('a','/a') Breadcrumbs('b','/b') print Breadcrumbs() self.breadcrumbs._drop_it() del(self.breadcrumbs) Breadcrumbs('c','/c') print Breadcrumbs()
def setUp(self): self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES breadcrumbs_middleware_class = 'breadcrumbs.middleware.BreadcrumbsMiddleware' if breadcrumbs_middleware_class not in settings.MIDDLEWARE_CLASSES: settings.MIDDLEWARE_CLASSES += (breadcrumbs_middleware_class,) self.old_TEMPLATE_CONTEXT_PROCESSORS = settings.TEMPLATE_CONTEXT_PROCESSORS request_processor = 'django.core.context_processors.request' if request_processor not in settings.TEMPLATE_CONTEXT_PROCESSORS: settings.TEMPLATE_CONTEXT_PROCESSORS += (request_processor,) self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS settings.TEMPLATE_DIRS = ( os.path.join( os.path.dirname(__file__), 'templates' ), ) # now we start singleton. singleton are tested on singleton_tests.py self.breadcrumbs = Breadcrumbs() # set some common ta to use SD = SortedDict self.data = [ SD([('name', 'Page1'), ('url', '/page1/')]), SD([('name', 'Page2'), ('url', '/page2/')]), SD([('name', 'Page3'), ('url', '/page2/page3/')]), SD([('name', 'Page4'), ('url', '/page4/')]), SD([('name', 'Page5'), ('url', '/page5/')]), ]
def setUp(self): self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES breadcrumbs_middleware_class = 'breadcrumbs.middleware.BreadcrumbsMiddleware' if breadcrumbs_middleware_class not in settings.MIDDLEWARE_CLASSES: settings.MIDDLEWARE_CLASSES += (breadcrumbs_middleware_class,) self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS settings.TEMPLATE_DIRS = ( os.path.join( os.path.dirname(__file__), 'templates' ), ) # self.old_LOGIN_URL = settings.LOGIN_URL # settings.LOGIN_URL = '/accounts/login/' # now we start singleton self.breadcrumbs = Breadcrumbs()
def setUp(self): breadcrumbs_middleware_class = 'breadcrumbs.middleware.BreadcrumbsMiddleware' flatpages_middleware_class = 'breadcrumbs.middleware.FlatpageFallbackMiddleware' # remove breadcrumbs middlewares to assert that we set correct # order self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES settings.MIDDLEWARE_CLASSES = [mid for mid \ in self.old_MIDDLEWARE_CLASSES if mid not in \ (breadcrumbs_middleware_class, flatpages_middleware_class)] settings.MIDDLEWARE_CLASSES += [ breadcrumbs_middleware_class, flatpages_middleware_class ] self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'), ) # now we start singleton. singleton are tested on singleton_tests.py self.breadcrumbs = Breadcrumbs()
def test_crumbs(self): # prepare breadcumbs request = self.rf.get('/') request.breadcrumbs = Breadcrumbs((['Home', '/'], ['Test', '/test/'])) response = self.tt.render(Context({ 'object': None, 'request': request })) self.assertTrue("Home / Test" in response)
def test_breadcrumbs_params_and_iteration(self): b = Breadcrumbs() b.add(self.data[0]['name'], self.data[0]['url']) b.add(*self.data[1].values()) b.add(**self.data[2]) b.add(self.data[3:5]) for i, bd in enumerate(b): self.assertEqual(bd, Breadcrumb(**self.data[i]).__dict__)
class BreadcrumbsTest(TestCase): def setUp(self): self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES breadcrumbs_middleware_class = 'breadcrumbs.middleware.BreadcrumbsMiddleware' if breadcrumbs_middleware_class not in settings.MIDDLEWARE_CLASSES: settings.MIDDLEWARE_CLASSES += (breadcrumbs_middleware_class,) self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS settings.TEMPLATE_DIRS = ( os.path.join( os.path.dirname(__file__), 'templates' ), ) # self.old_LOGIN_URL = settings.LOGIN_URL # settings.LOGIN_URL = '/accounts/login/' # now we start singleton self.breadcrumbs = Breadcrumbs() def tearDown(self): settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS # settings.LOGIN_URL = self.old_LOGIN_URL # kill singleton Breadcrumbs('a','/a') Breadcrumbs('b','/b') print Breadcrumbs() self.breadcrumbs._drop_it() del(self.breadcrumbs) Breadcrumbs('c','/c') print Breadcrumbs() def test_breadcrumb_class(self): b = Breadcrumb("Home", "/") self.assertEqual(b.name, "Home") self.assertEqual(b.url, "/") def test_breadcrumbs_singleton(self):
def setUp(self): breadcrumbs_middleware_class = 'breadcrumbs.middleware.BreadcrumbsMiddleware' flatpages_middleware_class = 'breadcrumbs.middleware.FlatpageFallbackMiddleware' # remove breadcrumbs middlewares to assert that we set correct # order self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES settings.MIDDLEWARE_CLASSES = [mid for mid \ in self.old_MIDDLEWARE_CLASSES if mid not in \ (breadcrumbs_middleware_class, flatpages_middleware_class)] settings.MIDDLEWARE_CLASSES += [ breadcrumbs_middleware_class, flatpages_middleware_class ] self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS settings.TEMPLATE_DIRS = ( os.path.join( os.path.dirname(__file__), 'templates' ), ) # now we start singleton. singleton are tested on singleton_tests.py self.breadcrumbs = Breadcrumbs()
class BreadcrumbsTest(TestCase): urls = 'breadcrumbs.tests.urls' def setUp(self): self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES breadcrumbs_middleware_class = 'breadcrumbs.middleware.BreadcrumbsMiddleware' if breadcrumbs_middleware_class not in settings.MIDDLEWARE_CLASSES: settings.MIDDLEWARE_CLASSES += (breadcrumbs_middleware_class,) self.old_TEMPLATE_CONTEXT_PROCESSORS = settings.TEMPLATE_CONTEXT_PROCESSORS request_processor = 'django.core.context_processors.request' if request_processor not in settings.TEMPLATE_CONTEXT_PROCESSORS: settings.TEMPLATE_CONTEXT_PROCESSORS += (request_processor,) self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS settings.TEMPLATE_DIRS = ( os.path.join( os.path.dirname(__file__), 'templates' ), ) # now we start singleton. singleton are tested on singleton_tests.py self.breadcrumbs = Breadcrumbs() # set some common ta to use SD = SortedDict self.data = [ SD([('name', 'Page1'), ('url', '/page1/')]), SD([('name', 'Page2'), ('url', '/page2/')]), SD([('name', 'Page3'), ('url', '/page2/page3/')]), SD([('name', 'Page4'), ('url', '/page4/')]), SD([('name', 'Page5'), ('url', '/page5/')]), ] def tearDown(self): settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS settings.TEMPLATE_CONTEXT_PROCESSORS = self.old_TEMPLATE_CONTEXT_PROCESSORS # kill singleton self.breadcrumbs._drop_it() del self.data def test_breadcrumb_class(self): b = Breadcrumb(**self.data[0]) self.assertEqual(b.name, self.data[0]['name']) self.assertEqual(b.url, self.data[0]['url']) def test_breadcrumbs_singleton(self): brd = Breadcrumbs() brd(**self.data[0]) brd2 = Breadcrumbs() brd2(**self.data[1]) # test 3 instances to see if singleton really works self.assertEqual(self.breadcrumbs[0].__dict__, Breadcrumb(**self.data[0]).__dict__) self.assertEqual(self.breadcrumbs[1].__dict__, Breadcrumb(**self.data[1]).__dict__) self.assertEqual(brd[1].__dict__, Breadcrumbs()[1].__dict__) def test_breadcrumbs_params_and_iteration(self): b = self.breadcrumbs b(self.data[0]['name'], self.data[0]['url']) b(*self.data[1].values()) b(**self.data[2]) b(self.data[3:5]) for i, bd in enumerate(b): self.assertEqual(bd.__dict__, Breadcrumb(**self.data[i]).__dict__) def test_request_breadcrumbs(self): response = self.client.get('/page1/') self.assertEqual(response.status_code, 200) self.assertContains(response, '<ul id="breadcrumbs"><li><a href="/page1/">Page 1</a></li></ul>')
class BreadcrumbsTest(TestCase): urls = 'breadcrumbs.tests.urls' def setUp(self): self.old_MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES breadcrumbs_middleware_class = 'breadcrumbs.middleware.BreadcrumbsMiddleware' if breadcrumbs_middleware_class not in settings.MIDDLEWARE_CLASSES: settings.MIDDLEWARE_CLASSES += (breadcrumbs_middleware_class, ) self.old_TEMPLATE_CONTEXT_PROCESSORS = settings.TEMPLATE_CONTEXT_PROCESSORS request_processor = 'django.core.context_processors.request' if request_processor not in settings.TEMPLATE_CONTEXT_PROCESSORS: settings.TEMPLATE_CONTEXT_PROCESSORS += (request_processor, ) self.old_TEMPLATE_DIRS = settings.TEMPLATE_DIRS settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'templates'), ) # now we start singleton. singleton are tested on singleton_tests.py self.breadcrumbs = Breadcrumbs() # set some common ta to use SD = SortedDict self.data = [ SD([('name', 'Page1'), ('url', '/page1/')]), SD([('name', 'Page2'), ('url', '/page2/')]), SD([('name', 'Page3'), ('url', '/page2/page3/')]), SD([('name', 'Page4'), ('url', '/page4/')]), SD([('name', 'Page5'), ('url', '/page5/')]), ] def tearDown(self): settings.MIDDLEWARE_CLASSES = self.old_MIDDLEWARE_CLASSES settings.TEMPLATE_DIRS = self.old_TEMPLATE_DIRS settings.TEMPLATE_CONTEXT_PROCESSORS = self.old_TEMPLATE_CONTEXT_PROCESSORS # kill singleton self.breadcrumbs._drop_it() del self.data def test_breadcrumb_class(self): b = Breadcrumb(**self.data[0]) self.assertEqual(b.name, self.data[0]['name']) self.assertEqual(b.url, self.data[0]['url']) def test_breadcrumbs_singleton(self): brd = Breadcrumbs() brd(**self.data[0]) brd2 = Breadcrumbs() brd2(**self.data[1]) # test 3 instances to see if singleton really works self.assertEqual(self.breadcrumbs[0].__dict__, Breadcrumb(**self.data[0]).__dict__) self.assertEqual(self.breadcrumbs[1].__dict__, Breadcrumb(**self.data[1]).__dict__) self.assertEqual(brd[1].__dict__, Breadcrumbs()[1].__dict__) def test_breadcrumbs_params_and_iteration(self): b = self.breadcrumbs b(self.data[0]['name'], self.data[0]['url']) b(*self.data[1].values()) b(**self.data[2]) b(self.data[3:5]) for i, bd in enumerate(b): self.assertEqual(bd.__dict__, Breadcrumb(**self.data[i]).__dict__) def test_request_breadcrumbs(self): response = self.client.get('/page1/') self.assertEqual(response.status_code, 200) self.assertContains( response, '<ul id="breadcrumbs"><li><a href="/page1/">Page 1</a></li></ul>')