def test_wrong_link_wrong_object(self): response = self.client.get('/aa98', follow=True) SimpleTestCase.assertRedirects(self=self, response=response, expected_url='/aa98/', status_code=301, target_status_code=404, msg_prefix='', fetch_redirect_response=True) print("wrong link '/aa98' returned 404")
def test_create_view_valid_post(client: Client, helpers: SimpleTestCase): """ A valid post should create a log and redirect the user to the log detail page """ url = reverse('terminal_logs:create') data = {'content': 'Adding some dummy content'} response = client.post(url, data, follow=True) assert Log.objects.exists() helpers.assertRedirects(response, reverse('terminal_logs:log_list'))
def test_report_bad_permission(self): anotherTestUser = authModels.User(username="******", password=make_password("password")) anotherTestUser.is_staff = True anotherTestUser.save() self.assertTrue( self.client.login(username="******", password="******")) response = self.client.get(reverse('history-report'), follow=True) SimpleTestCase.assertRedirects(self, response=response, expected_url="/admin/")
def check_redirects(response, expected_url): test_case = SimpleTestCase() test_case.assertRedirects(response, expected_url=expected_url) return True