def test_embargo_restriction(self): """ The view should return HTTP 403 status if the course is embargoed. """ with restrict_course(self.course.id) as redirect_url: response = self._post_to_view() assert 403 == response.status_code body = json.loads(response.content.decode('utf-8')) assert get_absolute_url(redirect_url) == body['user_message_url']
def test_embargo_restriction(self): """ The view should return HTTP 403 status if the course is embargoed. """ with restrict_course(self.course.id) as redirect_url: response = self._post_to_view() self.assertEqual(403, response.status_code) body = json.loads(response.content) self.assertEqual(get_absolute_url(redirect_url), body["user_message_url"])
def test_embargo_restriction(self): """ The view should return HTTP 403 status if the course is embargoed. """ with restrict_course(self.course.id) as redirect_url: response = self._post_to_view() self.assertEqual(403, response.status_code) body = json.loads(response.content) self.assertEqual(get_absolute_url(redirect_url), body['user_message_url'])
def assert_access_denied(self, user_message_path): """ Verify that the view returns HTTP status 403 and includes a URL in the response, and no enrollment is created. """ data = self._generate_data() response = self.client.post(self.url, data, content_type='application/json') # Expect an error response self.assertEqual(response.status_code, 403) # Expect that the redirect URL is included in the response resp_data = json.loads(response.content) user_message_url = get_absolute_url(user_message_path) self.assertEqual(resp_data['user_message_url'], user_message_url) # Verify that we were not enrolled self.assertEqual(self._get_enrollments(), [])