def test_list_students(self):
        """Test case for list_students

        List all students
        """
        body = Student()
        body.first_name = names.get_first_name()
        last_name = names.get_last_name()
        body.last_name = last_name
        body.grades = {'math': 8, 'history': 9}
        response = self.client.open(
            '/service-api/student',
            method='POST',
            data=json.dumps(body),
            content_type='application/json')
        query_string = [('last_name', last_name)]
        #arrange
        response = self.client.open(
            #'/service-api/student/?last_name={last_name}'.format(last_name=last_name),
            '/service-api/student/',
            method='GET',
            query_string=query_string)
        #assert
        self.assert200(response,
                        'Response body is : ' + response.data.decode('utf-8'))
Beispiel #2
0
    def test_get_student_by_id(self):
        """Test case for get_student_by_id

        Find student by ID
        """
        body = Student()
        body.first_name = names.get_first_name()
        body.last_name = names.get_last_name()
        body.grades = {'math': 8, 'history': 9}
        response = self.client.open(
            '/service-api/student/',
            method='POST',
            data=json.dumps(body),
            content_type='application/json')
        student_id = (response.json)

        query_string = [('math', 9)]
        response = self.client.open(
            '/service-api/student/{student_id}'.format(student_id=student_id),
            method='GET',
            query_string=query_string)
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
        self.assertTrue(response.is_json)
        self.assertIsInstance(response.json, dict)
    def test_get_student_by_id(self):
        """Test case for get_student_by_id

        Find student by ID
        """
        #arrange
        body = Student()
        body.first_name = names.get_first_name()
        body.last_name = names.get_last_name()
        body.grades = {'math': 8, 'history': 9}
        response = self.client.open(
            '/service-api/student',
            method='POST',
            data=json.dumps(body),
            content_type='application/json')
        student_id = (response.json)
        #act
        response = self.client.open(
            '/service-api/student/{student_id}'.format(student_id=student_id),
            method='GET')
        #assert
        self.assert200(response,
                        'Response body is : ' + response.data.decode('utf-8'))
        #clean up
        response = self.client.open(
            '/service-api/student/{student_id}'.format(student_id=student_id),
            method='DELETE')
 def test_delete_student(self):
     """Test case for delete_student
     """
     body = Student()
     body.first_name = names.get_first_name()
     body.last_name = names.get_last_name()
     body.grades = {'math': 8, 'history': 9}
     response = self.client.open('/service-api/student',
                                 method='POST',
                                 data=json.dumps(body),
                                 content_type='application/json')
     student_id = (response.json)
 def test_add_student(self):
     """Test case for add_student
     Add a new student
     """
     body = Student()
     body.first_name = names.get_first_name()
     body.last_name = names.get_last_name()
     body.grades = {'math': 8, 'history': 9}
     response = self.client.open('/service-api/student',
                                 method='POST',
                                 data=json.dumps(body),
                                 content_type='application/json')
     self.assert200(response,
                    'Response body is : ' + response.data.decode('utf-8'))
     self.assertTrue(response.is_json)
     self.assertIsInstance(response.json, int)
Beispiel #6
0
    def test_add_student(self):
        """Test case for add_student

        Add a new student
        """
        body = Student()
        body.first_name = names.get_first_name()
        body.last_name = names.get_last_name()
        body.grades = {'The_Mathematics_of_Quantum_Neutrino_Fields': 0, '20th_Century_History': 0}
        response = self.client.open(
            '/service-api/student',
            method='POST',
            data=json.dumps(body),
            content_type='application/json')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
        self.assertTrue(response.is_json)
        # self.assertIsInstance(response.json, int)   # 返回学生id
        self.assertIsInstance(response.json, dict)           
    def test_get_student_by_last_name(self):
        """Test case for get_student_by_last_name

        Find student by last name
        """
        body = Student()
        body.first_name = names.get_first_name()
        body.last_name = 'last_name_example'
        body.grades = {'math': 8, 'history': 9}
        response = self.client.open('/service-api/student/',
                                    method='POST',
                                    data=json.dumps(body),
                                    content_type='application/json')

        query_string = [('last_name', 'last_name_example')]
        response = self.client.open('/service-api/student/',
                                    method='GET',
                                    query_string=query_string)
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Beispiel #8
0
    def test_delete_student(self):
        """Test case for delete_student

        Delete student by ID
        """
        body = Student()
        body.first_name = names.get_first_name()
        body.last_name = names.get_last_name()
        body.grades = {'math': 8, 'history': 9}
        response = self.client.open(
            '/service-api/student',
            method='POST',
            data=json.dumps(body),
            content_type='application/json')
        student_id = (response.json)['student_id']    # 学生id
        # student_id = (response.json)
        response = self.client.open(
            '/service-api/student/{student_id}'.format(student_id=student_id),
            method='DELETE')
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
Beispiel #9
0
    def test_get_student_by_last_name(self):
        """Test case for get_student_by_last_name

        Find student by last name
        """
        body = Student()
        body.first_name = names.get_first_name()
        body.last_name = names.get_last_name()
        body.grades = {'Chinese': 8, 'history': 9}
        response = self.client.open(
            '/service-api/student',
            method='POST',
            data=json.dumps(body),
            content_type='application/json')
        
        query_string = [('last_name', (response.json)['last_name'])] # 学生的last_name
        response = self.client.open(
            '/service-api/student/',
            method='GET',
            query_string=query_string)
        self.assert200(response,
                       'Response body is : ' + response.data.decode('utf-8'))
        self.assertTrue(response.is_json)
        self.assertIsInstance(response.json, dict)