class ContactViewTest(TestCase): url = '/cms/contact' def setUp(self): self.factory = AsyncRequestFactory() self.admin = User.objects.create_user(username='******', email='', password='******') self.admin.is_superuser = True self.company = Company.objects.create(name='Company', street='street', number='1', zipcode='12345', city='city') self.contact = Contact.objects.create(username='******', email='', password='******', company=self.company) MailSetting.objects.create(smtp_user='******', smtp_server='localhost', smtp_port=587, smtp_password='******', stmp_use_tls=True) ShopSetting.objects.create(google_recaptcha_publickey='pub', google_recaptcha_privatekey='priv') def test_successful_login(self): request = self.factory.get(ContactViewTest.url) request.user = self.admin response = ContactView.as_view()(request) self.assertEqual(response.status_code, 200) def test_permission_denied_for_loggedin_user(self): request = self.factory.get(ContactViewTest.url) request.user = self.contact self.assertRaises(PermissionDenied) def test_permission_denied_for_anonymous_user(self): request = self.factory.get(ContactViewTest.url) request.user = AnonymousUser() self.assertRaises(PermissionDenied) @skip("Unkown internal http error, to be checked at a later time") def test_post_contact_form(self): request = self.factory.post(ContactViewTest.url, data={ 'name': 'test_user', 'email': '*****@*****.**', 'phone': '088/2654789', 'message': 'This is a message' }) response = ContactView.as_view()(request) self.assertEqual(response.status_code, 200)
class CSSSettingsViewTest(TestCase): url = '/cms/css-setting' def setUp(self): self.factory = AsyncRequestFactory() self.admin = User.objects.create_user(username='******', email='', password='******') self.admin.is_superuser = True self.company = Company.objects.create(name='Company', street='street', number='1', zipcode='12345', city='city') self.contact = Contact.objects.create(username='******', email='', password='******', company=self.company) def test_successful_login(self): request = self.factory.get(CSSSettingsViewTest.url) request.user = self.admin response = CSSSettingsView.as_view()(request) self.assertEqual(response.status_code, 200) def test_permission_denied_for_loggedin_user(self): request = self.factory.get(CSSSettingsViewTest.url) request.user = self.contact self.assertRaises(PermissionDenied) def test_permission_denied_for_anonymous_user(self): request = self.factory.get(CSSSettingsViewTest.url) request.user = AnonymousUser() self.assertRaises(PermissionDenied) @skip("Unkown internal http error, to be checked at a later time") def test_post_csssetting_form(self): request = self.factory.post(CSSSettingsViewTest.url + '1', data={}) request.user = self.admin response = CSSSettingsView.as_view()(request) self.assertEqual(response.status_code, 200)