def testGetSubdomainMiddleware5(self): "Test GetSubdomainMiddleware.process_request populates the variables we need correctly" rf = RequestFactory(domain = 'boox.notfoo.tld') request = rf.request() middleware = GetSubdomainMiddleware() middleware.process_request(request) self.assertEqual(request.META['domain'], 'boox.notfoo.tld')
def testGetSubdomainMiddleware2(self): "Test GetSubdomainMiddleware.process_request populates the variables we need correctly" rf = RequestFactory(subdomain = 'www') request = rf.request() middleware = GetSubdomainMiddleware() middleware.process_request(request) self.assertEqual(request.META['subdomain'], 'www') self.assertEqual(request.subdomain, None)
def testGetSubdomainMiddleware3(self): "Test GetSubdomainMiddleware.process_request populates the variables we need correctly" user = User.objects.create_user(username = '******', password = '******', email = '*****@*****.**') subdomain = Subdomain.objects.register_new_subdomain(subdomain_text = 'foo4', name='Foo, the subdomain', description = 'Foo has not description', user = user) rf = RequestFactory(subdomain = 'foo4') request = rf.request() middleware = GetSubdomainMiddleware() middleware.process_request(request) self.assertEqual(request.META['subdomain'], 'foo4')
def testGetSubdomainMiddleware5(self): "Test GetSubdomainMiddleware.process_request populates the variables we need correctly" rf = RequestFactory(domain = 'boox.notfoo.tld') request = rf.request() middleware = GetSubdomainMiddleware() middleware.process_request(request) self.assertEqual(request.subdomain_text, 'boox.notfoo.tld') self.assertEqual(request.main_site, False) self.assertEqual(request.subdomain, None)
def testpopulate_subdomain(self): user = User.objects.create_user(username = '******', password = '******', email = '*****@*****.**') subdomain = Subdomain.objects.register_new_subdomain(subdomain_text = 'foo5', name='Foo, the subdomain', description = 'Foo has not description', user = user) rf = RequestFactory(subdomain = 'foo5', main_site = False) request = rf.request() middleware = GetSubdomainMiddleware() middleware.process_request(request) context = populate_subdomain(request) self.assertEqual(context['subdomain_text'], 'testserver') self.assertEqual(context['main_site'], False) self.assertEqual(context['subdomain'], None)
def testensure_is_main_subdomain2(self): def view_func(request): "Dummy view function to decorate" return HttpResponse('hello') view_func = ensure_is_main_subdomain(view_func) rf = RequestFactory(subdomain = 'bar') request = rf.request() middleware = GetSubdomainMiddleware() middleware.process_request(request) response = view_func(request) self.assertEqual(HttpResponseRedirect, response.__class__)
def testensure_has_subdomain2(self): def view_func(request): "Dummy view function to decorate" return HttpResponse('hello') view_func = ensure_has_subdomain(view_func) user = User.objects.create_user(username = '******', password = '******', email = '*****@*****.**') subdomain = Subdomain.objects.register_new_subdomain(subdomain_text = 'foo7', name='Foo, the subdomain', description = 'Foo has not description', user = user) rf = RequestFactory(subdomain = 'doesnotexistxx') request = rf.request() middleware = GetSubdomainMiddleware() middleware.process_request(request) response = view_func(request) self.assertEqual(HttpResponseRedirect, response.__class__)
def testGetSubdomainMiddleware4(self): "Test GetSubdomainMiddleware.process_request populates the variables we need correctly" user = User.objects.create_user(username = '******', password = '******', email = '*****@*****.**') subdomain = Subdomain.objects.register_new_subdomain(subdomain_text = 'fooa1', name='Foo, the subdomain', description = 'Foo has not description', user = user, subdomain_callback = create_subdomain_settings) subdomain.domain = 'bax.notfoo.tld' subdomain.save() rf = RequestFactory(domain = 'bax.notfoo.tld') request = rf.request() middleware = GetSubdomainMiddleware() middleware.process_request(request) self.assertEqual(request.subdomain_text, 'bax.notfoo.tld') self.assertEqual(request.main_site, False) self.assertEqual(request.subdomain, subdomain)
def testGetSubdomainMiddleware1(self): "Test GetSubdomainMiddleware.process_request succeds without exceptions on a request." rf = RequestFactory(subdomain = 'foo') request = rf.request() middleware = GetSubdomainMiddleware() middleware.process_request(request)