def __init__(self, url_prefix, seller_id: str, password: str): self.url_prefix = urljoin(url_prefix, "seller/") self.seller_id = seller_id self.password = password self.terminal = "my terminal" self.auth = Auth(url_prefix) code, self.token = self.auth.login(self.seller_id, self.password, self.terminal) assert code == 200
def change_unreceived(seller_id, password, store_id, order_id): json = {"user_id": seller_id, "store_id": store_id, "order_id": order_id} terminal = "CaiXukun" url = "http://127.0.0.1:5000/seller/change_unreceived" auth = Auth("http://127.0.0.1:5000") code, token = auth.login(seller_id, password, terminal) headers = {"token": token} r = requests.post(url, headers=headers, json=json) return r.status_code
def track_order_by_order_id(buyer_id, password, order_id): json = {"user_id": buyer_id, "order_id": order_id} terminal = "CaiXukun" url = "http://127.0.0.1:5000/buyer/track_order_by_order_id" auth = Auth("http://127.0.0.1:5000") code, token = auth.login(buyer_id, password, terminal) headers = {"token": token} r = requests.post(url, headers=headers, json=json) return r.status_code, r.json().get("orderdetail")
def cancel_order(buyer_id, password, order_id): json = {"user_id": buyer_id, "order_id": order_id} terminal = "CaiXukun" url = "http://127.0.0.1:5000/buyer/cancel_order" auth = Auth("http://127.0.0.1:5000") code, token = auth.login(buyer_id, password, terminal) headers = {"token": token} r = requests.post(url, headers=headers, json=json) return r.status_code
def search_book_site(buyer_id, password, key_word): json = {"user_id": buyer_id, "key_word": key_word} terminal = "CaiXukun" url = "http://127.0.0.1:5000/buyer/search_book_site" auth = Auth("http://127.0.0.1:5000") code, token = auth.login(buyer_id, password, terminal) headers = {"token": token} r = requests.post(url, headers=headers, json=json) return r.status_code
def __init__(self, url_prefix, user_id, password): self.url_prefix = urljoin(url_prefix, "buyer/") self.user_id = user_id self.password = password self.token = "" self.terminal = "my terminal" self.auth = Auth(url_prefix) code, self.token = self.auth.login(self.user_id, self.password, self.terminal) assert code == 200
def update_comment(buyer_id, password, orderdetail_id, content): json = { "user_id": buyer_id, "orderdetail_id": orderdetail_id, "content": content } terminal = "CaiXukun" url = "http://127.0.0.1:5000/buyer/update_comment" auth = Auth("http://127.0.0.1:5000") code, token = auth.login(buyer_id, password, terminal) headers = {"token": token} r = requests.post(url, headers=headers, json=json) return r.status_code
class Seller: def __init__(self, url_prefix, seller_id: str, password: str): self.url_prefix = urljoin(url_prefix, "seller/") self.seller_id = seller_id self.password = password self.terminal = "my terminal" self.auth = Auth(url_prefix) code, self.token = self.auth.login(self.seller_id, self.password, self.terminal) assert code == 200 def create_store(self, store_id): json = { "user_id": self.seller_id, "store_id": store_id, } #print(simplejson.dumps(json)) url = urljoin(self.url_prefix, "create_store") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def add_book(self, store_id: str, stock_level: int, book_info: book.Book) -> int: json = { "user_id": self.seller_id, "store_id": store_id, "book_info": book_info.__dict__, "stock_level": stock_level } #print(simplejson.dumps(json)) url = urljoin(self.url_prefix, "add_book") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def add_stock_level(self, seller_id: str, store_id: str, book_id: str, add_stock_num: int) -> int: json = { "user_id": seller_id, "store_id": store_id, "book_id": book_id, "add_stock_level": add_stock_num } #print(simplejson.dumps(json)) url = urljoin(self.url_prefix, "add_stock_level") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def deliver_books(self, store_id: str, order_id: str) -> int: json = { "user_id": self.seller_id, "store_id": store_id, "order_id": order_id } url = urljoin(self.url_prefix, "deliver_books") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code
class Buyer: def __init__(self, url_prefix, user_id, password): self.url_prefix = urljoin(url_prefix, "buyer/") self.user_id = user_id self.password = password self.token = "" self.terminal = "my terminal" self.auth = Auth(url_prefix) code, self.token = self.auth.login(self.user_id, self.password, self.terminal) assert code == 200 def new_order(self, store_id: str, book_id_and_count: [(str, int)]) -> (int, str): books = [] for id_count_pair in book_id_and_count: books.append({"id": id_count_pair[0], "count": id_count_pair[1]}) json = {"user_id": self.user_id, "store_id": store_id, "books": books} #print(simplejson.dumps(json)) url = urljoin(self.url_prefix, "new_order") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("order_id") def payment(self, order_id: str): json = { "user_id": self.user_id, "password": self.password, "order_id": order_id } url = urljoin(self.url_prefix, "payment") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def add_funds(self, add_value: str) -> int: json = { "user_id": self.user_id, "password": self.password, "add_value": add_value } url = urljoin(self.url_prefix, "add_funds") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def receive(self, order_id: str) -> int: json = { "user_id": self.user_id, "password": self.password, "order_id": order_id } url = urljoin(self.url_prefix, "receive") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code
class Buyer: def __init__(self, url_prefix, user_id, password): self.url_prefix = urljoin(url_prefix, "buyer/") self.user_id = user_id self.password = password self.token = "" self.terminal = "my terminal" self.auth = Auth(url_prefix) code, self.token = self.auth.login(self.user_id, self.password, self.terminal) assert code == 200 def new_order(self, store_id: str, book_id_and_count: [(str, int)]) -> (int, str): books = [] for id_count_pair in book_id_and_count: books.append({"id": id_count_pair[0], "count": id_count_pair[1]}) json = {"user_id": self.user_id, "store_id": store_id, "books": books} #print(simplejson.dumps(json)) url = urljoin(self.url_prefix, "new_order") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("order_id") def payment(self, order_id: str): json = { "user_id": self.user_id, "password": self.password, "order_id": order_id } url = urljoin(self.url_prefix, "payment") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def add_funds(self, add_value: str) -> int: json = { "user_id": self.user_id, "password": self.password, "add_value": add_value } url = urljoin(self.url_prefix, "add_funds") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def confirm_receipt(self, order_id: str) -> int: json = {"user_id": self.user_id, "order_id": order_id} url = urljoin(self.url_prefix, "confirm_receipt") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def query_order_state(self, order_id: str) -> (int, str): json = {"user_id": self.user_id, "order_id": order_id} url = urljoin(self.url_prefix, "query_order_state") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("state") def cancel_order(self, password: str, order_id: str) -> int: json = { "user_id": self.user_id, "password": password, "order_id": order_id } url = urljoin(self.url_prefix, "cancel_order") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def add_comment(self, store_id: str, book_id: str, comment: str, rate: int) -> int: json = { "user_id": self.user_id, "store_id": store_id, "book_id": book_id, "comment": comment, "rate": rate } url = urljoin(self.url_prefix, "add_comment") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def view_comments(self, store_id: str, book_id: str) -> (int, [str]): json = { "user_id": self.user_id, "store_id": store_id, "book_id": book_id } url = urljoin(self.url_prefix, "view_comments") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("comments") def add_into_cart(self, store_id: str, book_id: str, count: int) -> int: json = { "user_id": self.user_id, "store_id": store_id, "book_id": book_id, "count": count } url = urljoin(self.url_prefix, "add_into_cart") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def view_cart(self) -> (int, {str: [(str, int)]}): json = {"user_id": self.user_id} url = urljoin(self.url_prefix, "view_cart") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("cart") def view_historical_order(self) -> (int, str, [{str: {str: str}}]): json = {"user_id": self.user_id} url = urljoin(self.url_prefix, "view_historical_order") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("orders") def checkout_cart(self) -> int: json = {"user_id": self.user_id, "password": self.password} url = urljoin(self.url_prefix, "checkout_cart") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code
class Buyer: def __init__(self, url_prefix, user_id, password): self.url_prefix = urljoin(url_prefix, "buyer/") self.user_id = user_id self.password = password self.token = "" self.terminal = "my terminal" self.auth = Auth(url_prefix) code, self.token = self.auth.login(self.user_id, self.password, self.terminal) assert code == 200 def new_order(self, store_id: str, book_id_and_count: [(str, int)]) -> (int, str): books = [] for id_count_pair in book_id_and_count: books.append({"id": id_count_pair[0], "count": id_count_pair[1]}) json = {"user_id": self.user_id, "store_id": store_id, "books": books} #print(simplejson.dumps(json)) url = urljoin(self.url_prefix, "new_order") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("order_id") def payment(self, order_id: str): json = { "user_id": self.user_id, "password": self.password, "order_id": order_id } url = urljoin(self.url_prefix, "payment") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def add_funds(self, add_value: str) -> int: json = { "user_id": self.user_id, "password": self.password, "add_value": add_value } url = urljoin(self.url_prefix, "add_funds") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def cancel_order(self, buyer_id: str, order_id: str): json = {"user_id": buyer_id, "order_id": order_id} url = urljoin(self.url_prefix, "cancel_order") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def query_order(self, user_id): json = {"user_id": user_id} url = urljoin(self.url_prefix, "query_order") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) print('access') print(r) response_json = r.json() return r.status_code, response_json.get("order_list") def query_order_para(self, user_id, para): json = {"user_id": user_id, "para": para} url = urljoin(self.url_prefix, "query_order_para") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) print('access') print(r) response_json = r.json() return r.status_code, response_json.get("order_list") def query_order_state(self, order_id): json = {"order_id": order_id} url = urljoin(self.url_prefix, "query_order_state") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) # print(r) response_json = r.json() return r.status_code, response_json.get("order_state") def query_detail_order(self, order_id): json = {"order_id": order_id} url = urljoin(self.url_prefix, "query_detail_order") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) # print(r) response_json = r.json() return r.status_code, response_json.get("order_detail_list") def receive_book(self, buyer_id: str, order_id: str): json = {"user_id": buyer_id, "order_id": order_id} url = urljoin(self.url_prefix, "receive_book") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code # 全站搜索图书,默认搜索第一个 def search_book_all(self, query: str, first: int = 1): json = {"query": query, "first": first} url = urljoin(self.url_prefix, "search_book_all") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("pages"), response_json.get( "book_list") # 店铺搜索 def search_book_store(self, query: str, store_id: str, first: int = 1): json = {"query": query, "store_id": store_id, "first": first} url = urljoin(self.url_prefix, "search_book_store") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("pages"), response_json.get( "book_list") # 全站搜索图书,默认搜索第一个 def search_book_all_tag(self, tag: str, first: int = 1): json = {"tag": tag, "first": first} url = urljoin(self.url_prefix, "search_book_all_tag") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("pages"), response_json.get( "book_list") # 店铺搜索 def search_book_store_tag(self, tag: str, store_id: str, first: int = 1): json = {"tag": tag, "store_id": store_id, "first": first} url = urljoin(self.url_prefix, "search_book_store_tag") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("pages"), response_json.get( "book_list") # 全站搜索图书,默认搜索第一个 def search_book_all_title(self, title: str, first: int = 1): json = {"title": title, "first": first} url = urljoin(self.url_prefix, "search_book_all_title") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("pages"), response_json.get( "book_list") # 店铺搜索 def search_book_store_title(self, title: str, store_id: str, first: int = 1): json = {"title": title, "store_id": store_id, "first": first} url = urljoin(self.url_prefix, "search_book_store_title") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("pages"), response_json.get( "book_list") # 全站搜索图书,默认搜索第一个 def search_book_all_author(self, author: str, first: int = 1): json = {"author": author, "first": first} url = urljoin(self.url_prefix, "search_book_all_author") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("pages"), response_json.get( "book_list") # 店铺搜索 def search_book_store_author(self, author: str, store_id: str, first: int = 1): json = {"author": author, "store_id": store_id, "first": first} url = urljoin(self.url_prefix, "search_book_store_author") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("pages"), response_json.get( "book_list")
class Buyer: def __init__(self, url_prefix, user_id, password): self.url_prefix = urljoin(url_prefix, "buyer/") self.user_id = user_id self.password = password self.token = "" self.terminal = "my terminal" self.auth = Auth(url_prefix) code, self.token = self.auth.login(self.user_id, self.password, self.terminal) assert code == 200 def new_order(self, store_id: str, book_id_and_count: [(str, int)]) -> (int, str): books = [] for id_count_pair in book_id_and_count: books.append({"id": id_count_pair[0], "count": id_count_pair[1]}) json = {"user_id": self.user_id, "store_id": store_id, "books": books} #print(simplejson.dumps(json)) url = urljoin(self.url_prefix, "new_order") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code, response_json.get("order_id") def payment(self, order_id: str): json = {"user_id": self.user_id, "password": self.password, "order_id": order_id} url = urljoin(self.url_prefix, "payment") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def add_funds(self, add_value: str) -> int: json = {"user_id": self.user_id, "password": self.password, "add_value": add_value} url = urljoin(self.url_prefix, "add_funds") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def receive_book(self,buyer_id: str, order_id: str) -> int: json={ "user_id":buyer_id, "order_id":order_id } url = urljoin(self.url_prefix, "receive_book") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def search_history_status(self,buyer_id: str,flag:int): json = { "buyer_id": buyer_id, "flag":flag } url = urljoin(self.url_prefix, "search_history_status") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def cancel(self,buyer_id: str, order_id: str): json = { "buyer_id": buyer_id, "order_id": order_id } url = urljoin(self.url_prefix, "cancel") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def auto_cancel(self,order_id:str): json={"order_id":order_id} url=urljoin(self.url_prefix,"test_auto_cancel") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code def search_functions_limit(self,store_id:str,search_type:str,search_input:str,field:str)->(int, [dict]): json = {"store_id": store_id, "search_type": search_type, "search_input":search_input, "field":field} url=urljoin(self.url_prefix,"search_functions_limit") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) response_json = r.json() return r.status_code,response_json.get("[res]")#test
class Seller: def __init__(self, url_prefix, seller_id: str, password: str): self.url_prefix = urljoin(url_prefix, "seller/") self.seller_id = seller_id self.password = password self.terminal = "my terminal" self.auth = Auth(url_prefix) code, self.token = self.auth.login(self.seller_id, self.password, self.terminal) assert code == 200 def create_store(self, store_id): json = { "user_id": self.seller_id, "store_id": store_id, } # print(simplejson.dumps(json)) url = urljoin(self.url_prefix, "create_store") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def add_book(self, store_id: str, stock_level: int, book_info: book.Book) -> int: json = { "user_id": self.seller_id, "store_id": store_id, "book_info": book_info.__dict__, "stock_level": stock_level } # print(simplejson.dumps(json)) url = urljoin(self.url_prefix, "add_book") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def add_stock_level(self, seller_id: str, store_id: str, book_id: str, add_stock_num: int) -> int: json = { "user_id": seller_id, "store_id": store_id, "book_id": book_id, "add_stock_level": add_stock_num } # print(simplejson.dumps(json)) url = urljoin(self.url_prefix, "add_stock_level") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def ship(self, seller_id: str, order_id: str): json = {"user_id": seller_id, "order_id": order_id} url = urljoin(self.url_prefix, "ship") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def check_s_balance(self, seller_id, store_id: str): json = { "user_id": seller_id, "password": self.password, "store_id": store_id, } url = urljoin(self.url_prefix, "check_s_balance") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) json = r.json() return r.status_code, json["result"] def check_stock(self, seller_id: str, password: str, store_id: str, book_id: str) -> int: json = { "user_id": seller_id, "password": password, "store_id": store_id, "book_id": book_id, } # print(simplejson.dumps(json)) url = urljoin(self.url_prefix, "check_stock") headers = {"token": self.token} r = requests.post(url, headers=headers, json=json) return r.status_code def search_all_order_seller(self, store_id, condition=""): json = { "user_id": self.seller_id, "password": self.password, "store_id": store_id, "condition": condition, } url = urljoin(self.url_prefix, "search_all_order_seller") r = requests.post(url, json=json) result = r.json().get("result") count = result["count"] return r.status_code, count def search_order_detail_seller(self, order_id: str): json = { "user_id": self.seller_id, "password": self.password, "order_id": order_id, } url = urljoin(self.url_prefix, "search_order_detail_seller") r = requests.post(url, json=json) result = r.json().get("result") count = result["result_count"] condition = result["condition"] return r.status_code, count, condition