Compare commits
No commits in common. 'xiaofan_branch' and 'master' have entirely different histories.
xiaofan_br
...
master
|
After Width: | Height: | Size: 35 MiB |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,118 +0,0 @@
|
||||
/*
|
||||
Navicat Premium Data Transfer
|
||||
|
||||
Source Server : mini12306
|
||||
Source Server Type : MySQL
|
||||
Source Server Version : 80036
|
||||
Source Host : localhost:3306
|
||||
Source Schema : mini12306
|
||||
|
||||
Target Server Type : MySQL
|
||||
Target Server Version : 80036
|
||||
File Encoding : 65001
|
||||
|
||||
Date: 10/05/2024 10:26:03
|
||||
*/
|
||||
|
||||
SET NAMES utf8mb4;
|
||||
SET FOREIGN_KEY_CHECKS = 0;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for log
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `log`;
|
||||
CREATE TABLE `log` (
|
||||
`id` int(0) NOT NULL,
|
||||
`eventname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`operator` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`eventtime` datetime(0) DEFAULT CURRENT_TIMESTAMP,
|
||||
`eventcontent` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_german2_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for passenger
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `passenger`;
|
||||
CREATE TABLE `passenger` (
|
||||
`id` int(0) NOT NULL,
|
||||
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`account` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`mobileno` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`bankcardno` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`idcardno` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`state` enum('已乘坐','未乘坐') CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`membertype` enum('普通用户','高级会员') CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_german2_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Records of passenger
|
||||
-- ----------------------------
|
||||
INSERT INTO `passenger` VALUES (1, '肖帆', '2023210156', 'xiaofan123.', '18879439530', '122312324334546575676', '362502200202213611', '未乘坐', '普通用户');
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for ticket
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `ticket`;
|
||||
CREATE TABLE `ticket` (
|
||||
`id` int(0) NOT NULL,
|
||||
`seatno` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`seatclass` int(0) DEFAULT NULL,
|
||||
`price` decimal(10, 2) DEFAULT NULL,
|
||||
`state` enum('未售','已售') CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`trainno` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`date` datetime(0) DEFAULT NULL,
|
||||
`passengerAccont` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`fromstation` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`tostation` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_german2_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for ticketseller
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `ticketseller`;
|
||||
CREATE TABLE `ticketseller` (
|
||||
`id` int(0) NOT NULL AUTO_INCREMENT,
|
||||
`name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NOT NULL,
|
||||
`accont` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci NOT NULL,
|
||||
`password` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`idcardno` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`mobileno` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`state` enum('未购票','已购票','已乘坐') CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`authority level` enum('普通用户','高级会员') CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_german2_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for train
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `train`;
|
||||
CREATE TABLE `train` (
|
||||
`id` int(0) NOT NULL,
|
||||
`trainno` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`date` date DEFAULT NULL,
|
||||
`departurestation` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`arrivalstation` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`departuretime` datetime(0) DEFAULT NULL,
|
||||
`arrivaltime` datetime(0) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_german2_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
-- ----------------------------
|
||||
-- Table structure for train station
|
||||
-- ----------------------------
|
||||
DROP TABLE IF EXISTS `train station`;
|
||||
CREATE TABLE `train station` (
|
||||
`id` int(0) NOT NULL,
|
||||
`trainno` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`date` datetime(0) DEFAULT NULL,
|
||||
`stationname` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_german2_ci DEFAULT NULL,
|
||||
`arrivaltime` datetime(0) DEFAULT NULL,
|
||||
`departuretime` datetime(0) DEFAULT NULL,
|
||||
PRIMARY KEY (`id`) USING BTREE
|
||||
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_german2_ci ROW_FORMAT = Dynamic;
|
||||
|
||||
SET FOREIGN_KEY_CHECKS = 1;
|
||||
|
After Width: | Height: | Size: 35 MiB |
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 34 KiB |
|
Before Width: | Height: | Size: 57 KiB |
|
Before Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 60 KiB |
@ -0,0 +1,2 @@
|
||||
# import pymysql
|
||||
# pymysql.install_as_MySQLdb()
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,5 +0,0 @@
|
||||
from django.contrib import admin
|
||||
# from .models import Train
|
||||
# admin.site.register(Train)
|
||||
|
||||
# Register your models here.
|
||||
@ -1,3 +0,0 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
@ -1,2 +1,2 @@
|
||||
import pymysql
|
||||
pymysql.install_as_MySQLdb()
|
||||
# import pymysql
|
||||
# pymysql.install_as_MySQLdb()
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,670 @@
|
||||
# import json
|
||||
# import requests
|
||||
#
|
||||
# url='http://localhost:8000/save_passenger/'
|
||||
# payload = json.dumps({
|
||||
# "name": "123123",
|
||||
# "idCard": "585654785478945674",
|
||||
# "PhoneNO": "19999999999",
|
||||
# "Bankcard": "1231231232568745",
|
||||
# "password": "123123123"
|
||||
# })
|
||||
# headers = {
|
||||
# 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
# 'content-type': 'application/json',
|
||||
# 'Accept': '*/*',
|
||||
# 'Host': 'localhost:8000',
|
||||
# 'Connection': 'keep-alive'
|
||||
# }
|
||||
# response = requests.post(url=url, data=payload)
|
||||
# assert response.status_code == 200
|
||||
# # assert response.json()['message'] == '注册成功'
|
||||
# print(response.json())
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
|
||||
# 设置基本的URL和路由
|
||||
base_url = 'http://localhost:8000'
|
||||
save_passenger_url = base_url + '/save_passenger/'
|
||||
login_view_url = base_url + '/login_view/'
|
||||
search_train_url = base_url + '/search_train/'
|
||||
headers = {
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'content-type': 'application/json',
|
||||
'Accept': '*/*',
|
||||
'Host': 'localhost:8000',
|
||||
'Connection': 'keep-alive'
|
||||
}
|
||||
# 保存乘客信息的测试
|
||||
def test_save_passenger():
|
||||
data = json.dumps({
|
||||
"name": "123123",
|
||||
"idCard": "585654785478945674",
|
||||
"PhoneNO": "19999999999",
|
||||
"Bankcard": "1231231232568745",
|
||||
"password": "123123123"
|
||||
})
|
||||
response = requests.post(save_passenger_url, data=data,headers=headers)
|
||||
if response.status_code == 200:
|
||||
print("Ticket booking successful:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("Failed to book ticket:", response.status_code)
|
||||
|
||||
# 登录的测试
|
||||
def test_login_view():
|
||||
data = {
|
||||
'account': '15315219585',
|
||||
'password': '1'
|
||||
}
|
||||
response = requests.post(login_view_url, json=data)
|
||||
if response.status_code == 200:
|
||||
print("Ticket booking successful:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("Failed to book ticket:", response.status_code)
|
||||
|
||||
# 查询车次的测试
|
||||
def test_search_train():
|
||||
data = {
|
||||
"departure": "1",
|
||||
"destination": "1",
|
||||
"date": "2024-07-04"
|
||||
}
|
||||
response = requests.post(search_train_url, json=data)
|
||||
if response.status_code == 200:
|
||||
print("Ticket booking successful:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("Failed to book ticket:", response.status_code)
|
||||
|
||||
|
||||
|
||||
def test_book_ticket():
|
||||
url = 'http://localhost:8000/book_ticket/'
|
||||
|
||||
# 预订车票
|
||||
data = {
|
||||
"date": "2024-07-05",
|
||||
"trainno": "G123"
|
||||
}
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("Ticket booking successful:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("Failed to book ticket:", response.status_code)
|
||||
|
||||
|
||||
# 获取乘客信息
|
||||
def test_get_passengers():
|
||||
url = 'http://localhost:8000/get_passengers/'
|
||||
response = requests.get(url=url)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("Passenger data:", response.json())
|
||||
else:
|
||||
print("Failed to retrieve passengers:", response.status_code)
|
||||
|
||||
|
||||
# 添加乘客信息
|
||||
def test_addpassenger():
|
||||
url = 'http://localhost:8000/addpassenger/'
|
||||
data = {
|
||||
"name": "张三",
|
||||
"idCard": "420322199545857478",
|
||||
"PhoneNO": "15315219585",
|
||||
"passengerstate": "正常"
|
||||
}
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("Passenger added successfully:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("Failed to add passenger:", response.status_code)
|
||||
|
||||
|
||||
# 购买车票
|
||||
def test_buy_ticket():
|
||||
url = 'http://localhost:8000/buy_ticket/'
|
||||
data = {
|
||||
"ticket_id": "1",
|
||||
"passenger_name": "张三",
|
||||
"date": "2024-07-05",
|
||||
"trainno": "G123",
|
||||
"tickettype": "二等座",
|
||||
"price": 100,
|
||||
"seatno": "C12"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("购票成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
elif response.status_code == 404:
|
||||
print("购票失败, 车票不存在")
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 改签
|
||||
def test_reschedule_ticket():
|
||||
url = 'http://localhost:8000/reschedule_ticket/'
|
||||
data = {
|
||||
"ticket_id": "1",
|
||||
"travelDate": "2024-07-05",
|
||||
"departure": "12",
|
||||
"destination": "12",
|
||||
"date": "2024-07-05"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("改签申请成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
elif response.status_code == 404:
|
||||
print("申请失败, 车票或新车次不存在")
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
# 取消订单
|
||||
def test_cancelOrder():
|
||||
url = 'http://localhost:8000/cancelOrder/'
|
||||
data = {
|
||||
"ticket_id": "1",
|
||||
"passenger_name": "张三",
|
||||
"date": "2024-07-05",
|
||||
"trainno": "G123",
|
||||
"tickettype": "二等座",
|
||||
"price": 100,
|
||||
"seatno": "C12"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("取消成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 退票
|
||||
# def test_refund_ticket():
|
||||
# url = 'http://localhost:8000/refund_ticket/'
|
||||
# data = {
|
||||
# "ticket_id": "1",
|
||||
# "date": "2024-07-05"
|
||||
# }
|
||||
#
|
||||
# headers = {'Content-Type': 'application/json'}
|
||||
#
|
||||
# response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
#
|
||||
# if response.status_code == 200:
|
||||
# print("退票成功:", response.json())
|
||||
# elif response.status_code == 400:
|
||||
# print("Bad Request:", response.json())
|
||||
# else:
|
||||
# print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 改签
|
||||
# def test_change_ticket():
|
||||
# data = {
|
||||
# "ticket_id": "3",
|
||||
# "travelDate": "2024-07-05",
|
||||
# "trainno": "G1233",
|
||||
# "date": "2024-07-05"
|
||||
# }
|
||||
# url = 'http://localhost:8000/change_ticket/'
|
||||
# headers = {'Content-Type': 'application/json'}
|
||||
#
|
||||
# response = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||
#
|
||||
# if response.status_code == 200:
|
||||
# print("改签成功:", response.json())
|
||||
# elif response.status_code == 400:
|
||||
# print("Bad Request:", response.json())
|
||||
# else:
|
||||
# print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 购买返程
|
||||
def test_buyReturn():
|
||||
url = 'http://localhost:8000/buyReturn/'
|
||||
data = {
|
||||
"departure": "12",
|
||||
"arrival": "12"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("返程查询成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 修改密码
|
||||
def test_change_password():
|
||||
url = 'http://localhost:8000/change_password/'
|
||||
data = {
|
||||
"name": "test1",
|
||||
"oldpassword": "12",
|
||||
"newpassword": "123"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("密码修改成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 获取订单
|
||||
def test_get_orders():
|
||||
url = 'http://localhost:8000/get_orders/'
|
||||
response = requests.get(url)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("订单查询成功:", response.json())
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 查询车次
|
||||
def test_search_ticket():
|
||||
url = 'http://localhost:8000/search_ticket/'
|
||||
data = {
|
||||
"trainno": "G123",
|
||||
"date": "2024-07-05"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("车次查询成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
# 运行测试
|
||||
# test_save_passenger()
|
||||
# test_login_view()
|
||||
# test_search_train()
|
||||
# import json
|
||||
# import requests
|
||||
#
|
||||
# url='http://localhost:8000/save_passenger/'
|
||||
# payload = json.dumps({
|
||||
# "name": "123123",
|
||||
# "idCard": "585654785478945674",
|
||||
# "PhoneNO": "19999999999",
|
||||
# "Bankcard": "1231231232568745",
|
||||
# "password": "123123123"
|
||||
# })
|
||||
# headers = {
|
||||
# 'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
# 'content-type': 'application/json',
|
||||
# 'Accept': '*/*',
|
||||
# 'Host': 'localhost:8000',
|
||||
# 'Connection': 'keep-alive'
|
||||
# }
|
||||
# response = requests.post(url=url, data=payload)
|
||||
# assert response.status_code == 200
|
||||
# # assert response.json()['message'] == '注册成功'
|
||||
# print(response.json())
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
|
||||
# 设置基本的URL和路由
|
||||
base_url = 'http://localhost:8000'
|
||||
save_passenger_url = base_url + '/save_passenger/'
|
||||
login_view_url = base_url + '/login_view/'
|
||||
search_train_url = base_url + '/search_train/'
|
||||
headers = {
|
||||
'User-Agent': 'Apifox/1.0.0 (https://apifox.com)',
|
||||
'content-type': 'application/json',
|
||||
'Accept': '*/*',
|
||||
'Host': 'localhost:8000',
|
||||
'Connection': 'keep-alive'
|
||||
}
|
||||
# 保存乘客信息的测试
|
||||
def test_save_passenger():
|
||||
data = json.dumps({
|
||||
"name": "123123",
|
||||
"idCard": "585654785478945674",
|
||||
"PhoneNO": "19999999999",
|
||||
"Bankcard": "1231231232568745",
|
||||
"password": "123123123"
|
||||
})
|
||||
response = requests.post(save_passenger_url, data=data,headers=headers)
|
||||
if response.status_code == 200:
|
||||
print("Ticket booking successful:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("Failed to book ticket:", response.status_code)
|
||||
|
||||
# 登录的测试
|
||||
def test_login_view():
|
||||
data = {
|
||||
'account': '15315219585',
|
||||
'password': '1'
|
||||
}
|
||||
response = requests.post(login_view_url, json=data)
|
||||
if response.status_code == 200:
|
||||
print("Ticket booking successful:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("Failed to book ticket:", response.status_code)
|
||||
|
||||
# 查询车次的测试
|
||||
def test_search_train():
|
||||
data = {
|
||||
"departure": "1",
|
||||
"destination": "1",
|
||||
"date": "2024-07-04"
|
||||
}
|
||||
response = requests.post(search_train_url, json=data)
|
||||
if response.status_code == 200:
|
||||
print("Ticket booking successful:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("Failed to book ticket:", response.status_code)
|
||||
|
||||
|
||||
|
||||
def test_book_ticket():
|
||||
url = 'http://localhost:8000/book_ticket/'
|
||||
|
||||
# 预订车票
|
||||
data = {
|
||||
"date": "2024-07-05",
|
||||
"trainno": "G123"
|
||||
}
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("Ticket booking successful:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("Failed to book ticket:", response.status_code)
|
||||
|
||||
|
||||
# 获取乘客信息
|
||||
def test_get_passengers():
|
||||
url = 'http://localhost:8000/get_passengers/'
|
||||
response = requests.get(url=url)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("Passenger data:", response.json())
|
||||
else:
|
||||
print("Failed to retrieve passengers:", response.status_code)
|
||||
|
||||
|
||||
# 添加乘客信息
|
||||
def test_addpassenger():
|
||||
url = 'http://localhost:8000/addpassenger/'
|
||||
data = {
|
||||
"name": "张三",
|
||||
"idCard": "420322199545857478",
|
||||
"PhoneNO": "15315219585",
|
||||
"passengerstate": "正常"
|
||||
}
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("Passenger added successfully:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("Failed to add passenger:", response.status_code)
|
||||
|
||||
|
||||
# 购买车票
|
||||
def test_buy_ticket():
|
||||
url = 'http://localhost:8000/buy_ticket/'
|
||||
data = {
|
||||
"ticket_id": "1",
|
||||
"passenger_name": "张三",
|
||||
"date": "2024-07-05",
|
||||
"trainno": "G123",
|
||||
"tickettype": "二等座",
|
||||
"price": 100,
|
||||
"seatno": "C12"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("购票成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
elif response.status_code == 404:
|
||||
print("购票失败, 车票不存在")
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 改签
|
||||
def test_reschedule_ticket():
|
||||
url = 'http://localhost:8000/reschedule_ticket/'
|
||||
data = {
|
||||
"ticket_id": "1",
|
||||
"travelDate": "2024-07-05",
|
||||
"departure": "12",
|
||||
"destination": "12",
|
||||
"date": "2024-07-05"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("改签申请成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
elif response.status_code == 404:
|
||||
print("申请失败, 车票或新车次不存在")
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
# 取消订单
|
||||
def test_cancelOrder():
|
||||
url = 'http://localhost:8000/cancelOrder/'
|
||||
data = {
|
||||
"ticket_id": "1",
|
||||
"passenger_name": "张三",
|
||||
"date": "2024-07-05",
|
||||
"trainno": "G123",
|
||||
"tickettype": "二等座",
|
||||
"price": 100,
|
||||
"seatno": "C12"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("取消成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 退票
|
||||
# def test_refund_ticket():
|
||||
# url = 'http://localhost:8000/refund_ticket/'
|
||||
# data = {
|
||||
# "ticket_id": "1",
|
||||
# "date": "2024-07-05"
|
||||
# }
|
||||
#
|
||||
# headers = {'Content-Type': 'application/json'}
|
||||
#
|
||||
# response = requests.post(url, data=json.dumps(data), headers=headers)
|
||||
#
|
||||
# if response.status_code == 200:
|
||||
# print("退票成功:", response.json())
|
||||
# elif response.status_code == 400:
|
||||
# print("Bad Request:", response.json())
|
||||
# else:
|
||||
# print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 改签
|
||||
# def test_change_ticket():
|
||||
# data = {
|
||||
# "ticket_id": "3",
|
||||
# "travelDate": "2024-07-05",
|
||||
# "trainno": "G1233",
|
||||
# "date": "2024-07-05"
|
||||
# }
|
||||
# url = 'http://localhost:8000/change_ticket/'
|
||||
# headers = {'Content-Type': 'application/json'}
|
||||
#
|
||||
# response = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||
#
|
||||
# if response.status_code == 200:
|
||||
# print("改签成功:", response.json())
|
||||
# elif response.status_code == 400:
|
||||
# print("Bad Request:", response.json())
|
||||
# else:
|
||||
# print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 购买返程
|
||||
def test_buyReturn():
|
||||
url = 'http://localhost:8000/buyReturn/'
|
||||
data = {
|
||||
"departure": "12",
|
||||
"arrival": "12"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("返程查询成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 修改密码
|
||||
def test_change_password():
|
||||
url = 'http://localhost:8000/change_password/'
|
||||
data = {
|
||||
"name": "test1",
|
||||
"oldpassword": "12",
|
||||
"newpassword": "123"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("密码修改成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 获取订单
|
||||
def test_get_orders():
|
||||
url = 'http://localhost:8000/get_orders/'
|
||||
response = requests.get(url)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("订单查询成功:", response.json())
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
|
||||
# 查询车次
|
||||
def test_search_ticket():
|
||||
url = 'http://localhost:8000/search_ticket/'
|
||||
data = {
|
||||
"trainno": "G123",
|
||||
"date": "2024-07-05"
|
||||
}
|
||||
|
||||
headers = {'Content-Type': 'application/json'}
|
||||
|
||||
response = requests.post(url=url, data=json.dumps(data), headers=headers)
|
||||
|
||||
if response.status_code == 200:
|
||||
print("车次查询成功:", response.json())
|
||||
elif response.status_code == 400:
|
||||
print("Bad Request:", response.json())
|
||||
else:
|
||||
print("其他错误:", response.status_code)
|
||||
|
||||
# 运行测试
|
||||
# test_save_passenger()
|
||||
# test_login_view()
|
||||
# te
|
||||
Loading…
Reference in new issue