Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 12
0
 def test_success(self):
     res = self.client.get(api.url_for(LectureListResource))
     self.assert200(res)
Esempio n. 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)
Esempio n. 14
0
 def test_response_format(self):
     res = self.client.get(api.url_for(LectureListResource))
     self.assertEqual(res.headers['Content-Type'], 'application/json')
Esempio n. 15
0
 def test_success(self):
     res = self.client.get(api.url_for(LectureListResource))
     self.assert200(res)
Esempio n. 16
0
 def test_invalid_course_filter(self):
     res = self.client.get(api.url_for(LectureListResource, course='hello'))
     self.assert400(res)
Esempio n. 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)
Esempio n. 18
0
 def test_response_format(self):
     res = self.client.get(api.url_for(LectureListResource))
     self.assertEqual(res.headers['Content-Type'], 'application/json')
Esempio n. 19
0
 def test_invalid_lecturer_filter(self):
     res = self.client.get(
         api.url_for(CourseListResource, lecturer='hello')
     )
     self.assert400(res)
Esempio n. 20
0
 def test_invalid_course_filter(self):
     res = self.client.get(
         api.url_for(LectureListResource, course='hello')
     )
     self.assert400(res)
Esempio n. 21
0
File: base.py Progetto: MACSIFS/IFS
 def login(self, email, password):
     self.client.post(
         api.url_for(LoginResource, email=email, password=password)
     )
Esempio n. 22
0
File: base.py Progetto: MACSIFS/IFS
 def login(self, email, password):
     self.client.post(
         api.url_for(LoginResource, email=email, password=password))