def test_valid_lecturer_filter(self): res = self.client.get( api.url_for(CourseListResource, lecturer=self.simon.id) ) response = json.loads(res.data.decode('utf-8')) self.assertEqual(len(response), 1) self.assertEqual(response[0]['id'], self.imt3601.id) self.assertEqual(response[0]['name'], self.imt3601.name) res = self.client.get( api.url_for(CourseListResource, lecturer=self.frode.id) ) response = json.loads(res.data.decode('utf-8')) self.assertEqual(len(response), 1) self.assertEqual(response[0]['id'], self.imt1031.id) self.assertEqual(response[0]['name'], self.imt1031.name) res = self.client.get( api.url_for(CourseListResource, lecturer=0) ) response = json.loads(res.data.decode('utf-8')) self.assertEqual(len(response), 0)
def test_valid_lecturer_filter(self): res = self.client.get( api.url_for(LectureListResource, course=self.imt3601.id) ) response = json.loads(res.data.decode('utf-8')) self.assertEqual(len(response), 1) self.assertEqual(response[0]['id'], self.imt3601_l1.id) self.assertEqual(response[0]['name'], self.imt3601_l1.name) res = self.client.get( api.url_for(LectureListResource, course=self.imt1031.id) ) response = json.loads(res.data.decode('utf-8')) self.assertEqual(len(response), 3) self.assertEqual(response[0]['id'], self.imt1031_l1.id) self.assertEqual(response[0]['name'], self.imt1031_l1.name) res = self.client.get( api.url_for(LectureListResource, course=999999) ) response = json.loads(res.data.decode('utf-8')) self.assertEqual(len(response), 0)
def test_content(self): res = self.client.get(api.url_for(CourseListResource)) response = json.loads(res.data.decode('utf-8')) self.assertEqual(len(response), 2) self.assertEqual(response[0]['id'], self.imt3601.id) self.assertEqual(response[1]['id'], self.imt1031.id) self.assertEqual(response[0]['name'], self.imt3601.name) self.assertEqual(response[1]['name'], self.imt1031.name)
def test_wrong_lecturer(self): self.login(self.simon.email, self.simon.password) res = self.client.post( api.url_for(CourseListResource, lecturerId=self.frode.id, name='awsm')) self.assert403(res)
def test_no_name(self): self.login(self.simon.email, self.simon.password) res = self.client.post( api.url_for( CourseListResource, lecturerId=self.frode.id, )) self.assert400(res)
def test_no_lecturer(self): self.login(self.simon.email, self.simon.password) res = self.client.post( api.url_for( CourseListResource, name='awsm' ) ) self.assert400(res)
def test_no_name(self): self.login(self.simon.email, self.simon.password) res = self.client.post( api.url_for( CourseListResource, lecturerId=self.frode.id, ) ) self.assert400(res)
def test_wrong_lecturer(self): self.login(self.simon.email, self.simon.password) res = self.client.post( api.url_for( CourseListResource, lecturerId=self.frode.id, name='awsm' ) ) self.assert403(res)
def test_success(self): self.login(self.simon.email, self.simon.password) res = self.client.post( api.url_for(CourseListResource, lecturerId=self.simon.id, name='awsm')) self.assert200(res) data = json.loads(res.data.decode('utf-8')) self.assertIsNotNone(data) self.assertIn('id', data) self.assertEqual(data['id'], 3) # It's the third course, so it should be 3 awsmCourse = Course.query.filter(Course.id == data['id']).first() self.assertFalse(awsmCourse is None) self.assertEqual(awsmCourse.name, 'awsm') self.assertEqual(awsmCourse.lecturer_id, self.simon.id)
def test_success(self): self.login(self.simon.email, self.simon.password) res = self.client.post( api.url_for( CourseListResource, lecturerId=self.simon.id, name='awsm' ) ) self.assert200(res) data = json.loads(res.data.decode('utf-8')) self.assertIsNotNone(data) self.assertIn('id', data) self.assertEqual(data['id'], 3) # It's the third course, so it should be 3 awsmCourse = Course.query.filter(Course.id == data['id']).first() self.assertFalse(awsmCourse is None) self.assertEqual(awsmCourse.name, 'awsm') self.assertEqual(awsmCourse.lecturer_id, self.simon.id)
def test_no_lecturer(self): self.login(self.simon.email, self.simon.password) res = self.client.post(api.url_for(CourseListResource, name='awsm')) self.assert400(res)
def test_success(self): res = self.client.get(api.url_for(LectureListResource)) self.assert200(res)
def test_response_is_list(self): res = self.client.get(api.url_for(LectureListResource)) response = json.loads(res.data.decode('utf-8')) self.assertIsInstance(response, list)
def test_response_format(self): res = self.client.get(api.url_for(LectureListResource)) self.assertEqual(res.headers['Content-Type'], 'application/json')
def test_invalid_course_filter(self): res = self.client.get(api.url_for(LectureListResource, course='hello')) self.assert400(res)
def test_invalid_lecturer_filter(self): res = self.client.get( api.url_for(CourseListResource, lecturer='hello') ) self.assert400(res)
def test_invalid_course_filter(self): res = self.client.get( api.url_for(LectureListResource, course='hello') ) self.assert400(res)
def login(self, email, password): self.client.post( api.url_for(LoginResource, email=email, password=password) )
def login(self, email, password): self.client.post( api.url_for(LoginResource, email=email, password=password))