def test_permissions(self): """ Staff access is required for write operations. """ url = reverse('api_experiments:v0:key_value-list') response = self.client.get(url) self.assertEqual(response.status_code, 200) response = self.client.post(url, {}) self.assertEqual(response.status_code, 401) instance = ExperimentKeyValueFactory() url = reverse('api_experiments:v0:key_value-detail', kwargs={'pk': instance.id}) response = self.client.get(url) self.assertEqual(response.status_code, 200) user = UserFactory(is_staff=False) self.client.login(username=user.username, password=UserFactory._DEFAULT_PASSWORD) response = self.client.put(url, {}) self.assertEqual(response.status_code, 403) response = self.client.patch(url, {}) self.assertEqual(response.status_code, 403) response = self.client.delete(url) self.assertEqual(response.status_code, 403)
def test_permissions(self): """ Staff access is required for write operations. """ url = reverse('api_experiments:v0:key_value-list') response = self.client.get(url) assert response.status_code == 200 response = self.client.post(url, {}) assert response.status_code == 401 instance = ExperimentKeyValueFactory() url = reverse('api_experiments:v0:key_value-detail', kwargs={'pk': instance.id}) response = self.client.get(url) assert response.status_code == 200 user = UserFactory(is_staff=False) self.client.login(username=user.username, password=UserFactory._DEFAULT_PASSWORD) # lint-amnesty, pylint: disable=protected-access response = self.client.put(url, {}) assert response.status_code == 403 response = self.client.patch(url, {}) assert response.status_code == 403 response = self.client.delete(url) assert response.status_code == 403
def test_enrollment_end(self, experiment_end, enrollment_created, expected_bucket): if enrollment_created: enrollment = CourseEnrollmentFactory(user=self.user, course_id='a/b/c') enrollment.created = parser.parse(enrollment_created).replace(tzinfo=pytz.UTC) enrollment.save() if experiment_end: ExperimentKeyValueFactory(experiment_id=0, key='enrollment_end', value=experiment_end) self.assertEqual(self.get_bucket(), expected_bucket)