示例#1
0
    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)
示例#2
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)
示例#3
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)
示例#4
0
    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)
示例#5
0
    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)
示例#6
0
    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)
示例#7
0
    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)
示例#8
0
    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)
示例#9
0
    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)
示例#10
0
    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)
示例#11
0
    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)
示例#12
0
 def test_success(self):
     res = self.client.get(api.url_for(LectureListResource))
     self.assert200(res)
示例#13
0
 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)
示例#14
0
 def test_response_format(self):
     res = self.client.get(api.url_for(LectureListResource))
     self.assertEqual(res.headers['Content-Type'], 'application/json')
示例#15
0
 def test_success(self):
     res = self.client.get(api.url_for(LectureListResource))
     self.assert200(res)
示例#16
0
 def test_invalid_course_filter(self):
     res = self.client.get(api.url_for(LectureListResource, course='hello'))
     self.assert400(res)
示例#17
0
 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)
示例#18
0
 def test_response_format(self):
     res = self.client.get(api.url_for(LectureListResource))
     self.assertEqual(res.headers['Content-Type'], 'application/json')
示例#19
0
 def test_invalid_lecturer_filter(self):
     res = self.client.get(
         api.url_for(CourseListResource, lecturer='hello')
     )
     self.assert400(res)
示例#20
0
 def test_invalid_course_filter(self):
     res = self.client.get(
         api.url_for(LectureListResource, course='hello')
     )
     self.assert400(res)
示例#21
0
文件: base.py 项目: MACSIFS/IFS
 def login(self, email, password):
     self.client.post(
         api.url_for(LoginResource, email=email, password=password)
     )
示例#22
0
文件: base.py 项目: MACSIFS/IFS
 def login(self, email, password):
     self.client.post(
         api.url_for(LoginResource, email=email, password=password))