Exemple #1
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)
Exemple #2
0
    def test_request_verification_code(self):
        result, reply = request_api(
            AccountServiceApi.REQUEST_VERIFICATION_CODE,
            data={"email": "*****@*****.**"})
        self.assertEqual(result, Result.ERROR_INVALID_EMAIL)

        result, reply = request_api(
            AccountServiceApi.REQUEST_VERIFICATION_CODE,
            data={
                "email": TEST_EMAIL,
            })
        self.assertEqual(result, Result.SUCCESS)
Exemple #3
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))
Exemple #4
0
    def test_interact_review(self):
        result, reply = request_api(ReviewServiceApi.INTERACT_REVIEW,
                                    data={
                                        "review_id": TEST_REVIEW_ID,
                                        "action": ReviewInteraction.LIKE
                                    },
                                    token=self._token)
        self.assertEqual(result, Result.SUCCESS)

        result, reply = request_api(ReviewServiceApi.INTERACT_REVIEW,
                                    data={
                                        "review_id": TEST_REVIEW_ID,
                                        "action": ReviewInteraction.DISLIKE
                                    },
                                    token=self._token)
        self.assertEqual(result, Result.SUCCESS)
Exemple #5
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))
Exemple #6
0
	def test_echo(self):
		result, reply = request_api(TestServiceApi.ECHO, data={
			"message": "Hello World"
		})

		self.assertEqual(result, Result.SUCCESS)

		self.assertEqual(reply["message"], "Hello World")
Exemple #7
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)
Exemple #8
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))
Exemple #9
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))
Exemple #10
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))
Exemple #11
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")
Exemple #12
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)
Exemple #13
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"])
Exemple #14
0
 def test_add_review(self):
     result, _ = request_api(ReviewServiceApi.ADD_REVIEW,
                             data={
                                 "course_id": TEST_COURSE_ID,
                                 "teacher_id": TEST_TEACHER_ID,
                                 "semester": TEST_SEMESTER,
                                 "title": "Test title",
                                 "content": "Test content",
                                 "recommend_score": 4.5,
                                 "content_score": 4,
                                 "work_score": 3.5,
                                 "exam_score": 5,
                             },
                             token=self._token)
     self.assertEqual(result, Result.SUCCESS)
Exemple #15
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"])
Exemple #16
0
 def test_get_teacher_names(self):
     result, reply = request_api(TeacherServiceApi.GET_TEACHER_LIST,
                                 method="GET",
                                 token=self._token)
     self.assertEqual(result, Result.SUCCESS)