Beispiel #1
0
 def test_get_courses_by_school(self):
     result, reply = request_api(CourseServiceApi.GET_COURSES_BY_SCHOOL,
                                 method="GET",
                                 token=self._token)
     self.assertEqual(result, Result.SUCCESS)
     self.assertTrue(
         validate_reply(reply, GET_COURSES_BY_SCHOOL_REPLY_SCHEMA))
Beispiel #2
0
    def test_login(self):
        result, reply = request_api(AccountServiceApi.LOGIN,
                                    data={
                                        "email":
                                        "*****@*****.**",
                                        "verification_code":
                                        TEST_VERIFICATION_CODE,
                                    })
        self.assertEqual(result, Result.ERROR_VERIFICATION_CODE)

        result, reply = request_api(
            AccountServiceApi.REQUEST_VERIFICATION_CODE,
            data={"email": TEST_EMAIL})
        self.assertEqual(result, Result.SUCCESS)

        result, reply = request_api(AccountServiceApi.LOGIN,
                                    data={
                                        "email": TEST_EMAIL,
                                        "verification_code":
                                        TEST_VERIFICATION_CODE
                                    })
        self.assertEqual(result, Result.SUCCESS)
        self.assertTrue(validate_reply(reply, LOGIN_REPLY_SCHEMA))
        token = decode_jwt(reply["access_token"])
        self.assertEqual(token["user_id"], TEST_UID)
        self.assertEqual(token["email"], TEST_EMAIL)
Beispiel #3
0
 def test_get_teacher_info(self):
     result, reply = request_api(TeacherServiceApi.GET_TEACHER_INFO,
                                 data={
                                     "teacher_id": TEST_TEACHER_ID,
                                 },
                                 token=self._token)
     self.assertEqual(result, Result.SUCCESS)
     self.assertTrue(validate_reply(reply, GET_TEACHER_INFO_REPLY_SCHEMA))
Beispiel #4
0
 def test_get_course_list(self):
     result, reply = request_api(CourseServiceApi.GET_COURSE_LIST,
                                 data={
                                     "current_page": 1,
                                     "page_size": 20,
                                 },
                                 token=self._token)
     self.assertEqual(result, Result.SUCCESS)
     self.assertTrue(validate_reply(reply, GET_COURSE_LIST_REPLY_SCHEMA))
Beispiel #5
0
 def test_get_teachers_by_course(self):
     result, reply = request_api(TeacherServiceApi.GET_TEACHERS_BY_COURSE,
                                 data={
                                     "course_id": TEST_COURSE_ID,
                                 },
                                 token=self._token)
     self.assertEqual(result, Result.SUCCESS)
     self.assertTrue(
         validate_reply(reply, GET_TEACHERS_BY_COURSE_REPLY_SCHEMA))
Beispiel #6
0
 def test_search_courses_by_name(self):
     result, reply = request_api(CourseServiceApi.SEARCH_COURSES_BY_NAME,
                                 method="POST",
                                 data={
                                     "course_name": "高数",
                                 },
                                 token=self._token)
     self.assertEqual(result, Result.SUCCESS)
     self.assertTrue(
         validate_reply(reply, SEARCH_COURSES_BY_NAME_REPLY_SCHEMA))
Beispiel #7
0
 def test_get_user_info(self):
     token = login_test_user()
     result, reply = request_api(AccountServiceApi.GET_USER_INFO,
                                 method="GET",
                                 token=token)
     self.assertEqual(result, Result.SUCCESS)
     self.assertTrue(validate_reply(reply, GET_USER_INFO_REPLY_SCHEMA))
     self.assertEqual(reply["user_id"], TEST_UID)
     self.assertEqual(reply["email"], TEST_EMAIL)
     self.assertEqual(reply["authority"], "user")
Beispiel #8
0
 def test_get_teacher_reviews(self):
     result, reply = request_api(ReviewServiceApi.GET_TEACHER_REVIEWS,
                                 data={
                                     "teacher_id": TEST_TEACHER_ID,
                                     "current_page": 1,
                                     "page_size": 10,
                                 },
                                 token=self._token)
     self.assertEqual(result, Result.SUCCESS)
     self.assertTrue(validate_reply(reply,
                                    GET_TEACHER_REVIEWS_REPLY_SCHEMA))
     # Check if all reviews belong to requested course
     for review in reply["reviews"]:
         self.assertEqual(review["teacher_id"], TEST_TEACHER_ID)
Beispiel #9
0
 def test_get_latest_reviews(self):
     result, reply = request_api(ReviewServiceApi.GET_LATEST_REVIEWS,
                                 data={
                                     "offset": 0,
                                     "size": 10,
                                 },
                                 token=self._token)
     self.assertEqual(result, Result.SUCCESS)
     self.assertTrue(validate_reply(reply, GET_LATEST_REVIEWS_REPLY_SCHEMA))
     # Make sure reviews are sorted by time
     reviews = reply["reviews"]
     for i in range(len(reviews) - 1):
         self.assertTrue(
             reviews[i]["create_time"] >= reviews[i + 1]["create_time"])
Beispiel #10
0
 def test_get_course_rank(self):
     result, reply = request_api(CourseServiceApi.GET_COURSE_RANK,
                                 method="POST",
                                 data={
                                     "course_type": 100,
                                     "school_id": 2,
                                 },
                                 token=self._token)
     self.assertEqual(result, Result.SUCCESS)
     self.assertTrue(validate_reply(reply, GET_COURSE_RANK_REPLY_SCHEMA))
     # Make sure courses are sorted descending by score
     courses = reply["courses"]
     for i in range(len(courses) - 1):
         self.assertTrue(
             courses[i]["recommend_score"] >= courses[i +
                                                      1]["recommend_score"])
Beispiel #11
0
    def test_get_course_info(self):
        result, reply = request_api(CourseServiceApi.GET_COURSE_INFO,
                                    method="POST",
                                    data={
                                        "course_id": 99999,
                                    },
                                    token=self._token)
        self.assertEqual(result, Result.ERROR_COURSE_NOT_FOUND)

        result, reply = request_api(CourseServiceApi.GET_COURSE_INFO,
                                    method="POST",
                                    data={
                                        "course_id": TEST_COURSE_ID,
                                    },
                                    token=self._token)
        self.assertEqual(result, Result.SUCCESS)
        self.assertTrue(validate_reply(reply, GET_COURSE_INFO_REPLY_SCHEMA))
        self.assertEqual(reply["id"], TEST_COURSE_ID)