def test_get_avg_score(self):
     client = Client()
     student = Student(id='17373010', name='xxx', usr_name='xxx', usr_password='******', grade='2')
     student.save()
     score = Score(student_id=student, course_name="123", semester="22", score=22, origin_score="33", label="")
     score.save()
     response = client.get("/score/avg_score/?student_id=17373010")
     self.assertEqual(response.status_code, 200)
 def test_post_score4(self):
     client = Client()
     student = Student(id='17373010', name='xxx', usr_name='xxx', usr_password='******', grade='2')
     student.save()
     data = {"student_id": "17373010",
             "info": [["B1A09104A", "工科数学分析(1)", "6.0", "99"]]}
     response = client.post("/score/", content_type='application/json',
                            data=data)
     self.assertEqual(response.status_code, 400)
Esempio n. 3
0
 def test_get(self):
     student = Student(id='17373010',
                       name='xxx',
                       usr_name='xxx',
                       usr_password='******',
                       grade='2')
     student.save()
     add_request('s', '17373010')
     client = Client()
     request = client.get('/request/')
     self.assertEqual(request.status_code, 200)
Esempio n. 4
0
 def test_post5(self):
     student = Student(id='17373010',
                       name='xxx',
                       usr_name='xxx',
                       usr_password='******',
                       grade='2')
     student.save()
     add_request('s', '17373010')
     client = Client()
     data = {"student_id": "17373010"}
     request = client.post("/request/score_course/?student_id=17373010",
                           content_type='application/json',
                           data=data)
     self.assertEqual(request.status_code, 200)
    def test_post_400(self):
        """
        检测返回状态码为400的post请求
        1.插入的json包格式有问题
        """
        Student(usr_name="mushan", usr_password="******", id="17373349", name="hbb", grade=3).save()

        data = {
            "school_year": "2019-2020",
            "first_semester": "2019-09-02",
            "winter_semester": "2020-01-13",
            "second_semester": "2020-02-24",
            "third_semester": "2020-06-29",
            "end_semester": "2020-09-06",
            "contet": [
                {
                    "semester": "2019-2020第一学期",
                    "date": "2019-09-13",
                    "holiday": "中秋节"
                }
            ]
        }

        response = self.client.post('/ddl/Calendar/', content_type='application/json', data=data)
        self.assertEqual(response.status_code, 400)
Esempio n. 6
0
 def test_post2(self):
     student = Student(id='17373010',
                       name='xxx',
                       usr_name='xxx',
                       usr_password='******',
                       grade='2')
     student.save()
     add_request('s', '17373010')
     client = Client()
     data = {
         "req_id": "1",
         "usr_name": "xxx",
         "password": "******",
         "req_type": "xxx"
     }
     request = client.post("/request/",
                           content_type='application/json',
                           data=data)
     self.assertEqual(request.status_code, 201)
 def test_get_463(self):
     """
     检测返回状态码为463的get请求
     数据库中无该学年信息
     """
     Student(usr_name="mushan", usr_password="******", id="17373349", name="hbb", grade=3).save()
     SchoolYear(school_year="2018-2019", first_semester="2019-09-02",
                winter_semester="2020-01-13", second_semester="2020-02-24",
                third_semester="2020-06-29", end_semester="2020-09-06").save()
     response = self.client.get('/ddl/Calendar/?student_id=17373349&school_year=2019-2020')
     self.assertEqual(response.status_code, 463)
    def test_get_200(self):
        """
        检测返回状态码为200的get请求
        成功的请求
        """
        Student(usr_name="mushan", usr_password="******", id="17373349", name="hbb", grade=3).save()
        student = Student.objects.get(id="17373349")
        DDL(student_id=student, ddl="2020-03-19 23:55:00", homework="第一次作业",
            state="已提交", course="计算机科学").save()

        response = self.client.get('/ddl/?student_id=17373349')
        self.assertEqual(response.status_code, 200)
Esempio n. 9
0
    def test_post_200(self):
        """
        检测返回状态码为200的post请求
        1.如果数据库中无该学生,返回0
        2.如果数据库中密码不相同,返回-1
        3.如果成功删除返回1
        """
        data = {
            "usr_name": "mushan",
            "password": "******",
            "error_type": "1",
        }

        Student(usr_name="mushan", usr_password="******", id="17373349", name="hbb", grade=3).save()
        response = self.client.post('/spider/delete/', content_type='application/json', data=data)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data["state"], -1)

        Student(usr_name="mushan", usr_password="******", id="17373349", name="hbb", grade=3).save()
        response = self.client.post('/spider/delete/', content_type='application/json', data=data)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data["state"], 1)
Esempio n. 10
0
    def test_get_200(self):
        """
        检测返回状态码为200的get请求
        """
        Student(usr_name="mushan", usr_password="******", id="17373349", name="hbb", grade=3).save()
        response = self.client.get('/spider/update/?student_id=17373349')
        self.assertEqual(response.status_code, 200)

        response = self.client.get('/spider/update/?calendar=1')
        self.assertEqual(response.status_code, 200)

        response = self.client.get('/spider/update/?empty_room=1')
        self.assertEqual(response.status_code, 200)
Esempio n. 11
0
    def test_post_401(self):
        """
        检测返回状态码为401的post请求
        1.数据库中无该学生数据
        """
        Student(usr_name="mushan",
                usr_password="******",
                id="17373348",
                name="hbb",
                grade=3).save()

        data = {"student_id": "17373349", "kind": "bug", "content": "ddl错误"}
        response = self.client.post('/feedback/',
                                    content_type='application/json',
                                    data=data)
        self.assertEqual(response.status_code, 401)
    def test_post_200(self):
        """
        检测返回状态码为200的post请求
        1.成功返回
        """
        Student(usr_name="mushan", usr_password="******", id="17373349", name="hbb", grade=3).save()

        data = {
            "student_id": "17373349",
            "ddl": [
                {
                    "content": [
                        {
                            "ddl": "2020-3-19 下午11:55",
                            "homework": "第一次作业",
                            "state": "提交"
                        },
                        {
                            "ddl": "2020-3-19 下午11:55",
                            "homework": "第二次作业",
                            "state": "未提交"
                        }
                    ],
                    "name": "计算机科学方法论"
                },
                {
                    "content": [
                        {
                            "ddl": "",
                            "homework": "第一次作业",
                            "state": "提交"
                        }
                    ],
                    "name": "计算机图形学"
                }
            ]
        }

        response = self.client.post('/ddl/', content_type='application/json', data=data)
        self.assertEqual(response.status_code, 200)
Esempio n. 13
0
    def test_get_200(self):
        """
        检测返回状态码为200的get请求
        1.获取所有反馈
        2.获取某一天的反馈
        3。获取某一类的反馈
        """
        Student(usr_name="mushan",
                usr_password="******",
                id="17373349",
                name="hbb",
                grade=3).save()
        student = Student.objects.get(id="17373349")
        Feedback(student_id=student, kind="bug", content="ddl有问题").save()

        response = self.client.get('/feedback/')
        self.assertEqual(response.status_code, 200)

        response = self.client.get('/feedback/?date=2020-05-14')
        self.assertEqual(response.status_code, 200)

        response = self.client.get('/feedback/?kind=bug')
        self.assertEqual(response.status_code, 200)
    def post(request):
        """
        输入:用户名,用户密码,输出:登录状态(1代表成功,2代表无该账号,3代表密码错误)
        参数1:用户名 e.g. mushan,用户密码 e.g. h1010
        例:http --form POST http://127.0.0.1:8000/login/ usr_name="mushan" usr_password="******"
        获取学生基本信息
        返回: [state, student_id, name]
        没有提供参数,参数数量错误,返回400错误;
        参数错误,返回400错误;
        密码账号错误401
        账号被锁返回460
        服务器ip返回461
        """

        try:  # 保存前端请求数据
            record = RequestRecord.objects.get(name="login")
            record.count = record.count + 1
            record.save()
        except RequestRecord.DoesNotExist:
            RequestRecord(name="login", count=1).save()

        req = request.data

        if (len(req) != 2) | ("usr_name" not in req) | ("usr_password" not in req):
            raise ArgumentError()

        usr_name = request.data["usr_name"]
        usr_password = request.data["usr_password"]
        ans = get_student_info(usr_name, usr_password)

        state = ans
        if (ans == 0) | (ans == -1) | (ans == -2) | (ans == -3) | (ans == -4) | (ans == -5):
            raise InternalServerError()

        if ans == -6:  # IP is banned from the buaa
            raise IPBannedError()

        if (ans == -7) | (ans == -8):
            raise UnAuthorizedError()

        if ans == -9:
            raise ArgumentError()

        if ans == -10:
            raise AccountLockedError()

        state = 1
        student_id = str(ans[0])
        password_d = Aescrypt(KEY, MODEL, IV, ENCODE_)
        student_id = password_d.aesencrypt(student_id)
        name = ans[2]
        grade = ans[3]
        if Student.objects.filter(id=student_id).count() == 0:
            Student(usr_name=usr_name, usr_password=usr_password, id=student_id, name=name, grade=grade).save()
            add_request('l', student_id)
        else:
            Student(usr_name=usr_name, usr_password=usr_password, id=student_id, name=name, grade=grade).save()

        try:  # 学生更新数据最新时间
            student = Student.objects.get(id=student_id)
            PostRecord.objects.get(student_id=student, name="login").delete()
            PostRecord.objects.get(student_id=student, name="login").save()
        except PostRecord.DoesNotExist:
            PostRecord(student_id=student, name="login").save()

        if len(StudentCourse.objects.filter(student_id_id=student_id)) == 0 or len(
                Score.objects.filter(student_id_id=student_id)) == 0:
            add_request('j', student_id)
        if len(DDL.objects.filter(student_id_id=student_id)) == 0:
            add_request('d', student_id)

        content = {"state": state, "student_id": ans[0], "name": name}
        return Response(content)
 def test_get_score(self):
     client = Client()
     student = Student(id='17373010', name='xxx', usr_name='xxx', usr_password='******', grade='2')
     student.save()
     response = client.get("/score/?student_id=17373010&semester=''")
     self.assertEqual(response.status_code, 200)