Beispiel #1
0
    def pre_run_initialization(self):
        self.seller_id = "test_close_order_seller_id_{}".format(
            str(uuid.uuid1()))
        self.store_id = "test_close_order_store_id_{}".format(str(
            uuid.uuid1()))
        self.buyer_id = "test_close_order_buyer_id_{}".format(str(
            uuid.uuid1()))
        self.password = self.buyer_id
        gen_book = GenBook(self.seller_id, self.store_id)
        self.seller = gen_book.seller
        ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                            low_stock_level=False,
                                            max_book_count=5)
        self.buy_book_info_list = gen_book.buy_book_info_list
        assert ok
        b = register_new_buyer(self.buyer_id, self.password)
        self.buyer = b
        code, self.order_id = b.new_order(self.store_id, buy_book_id_list)
        assert code == 200
        self.total_price = 0
        for item in self.buy_book_info_list:
            book: Book = item[0]
            num = item[1]
            self.total_price = self.total_price + book.price * num

        self.buyer2_id = "test_close_order_buyer2_id_{}".format(
            str(uuid.uuid1()))  # 2号无订单买家
        self.password2 = self.buyer2_id
        b2 = register_new_buyer(self.buyer2_id, self.password2)
        self.buyer2 = b2
        yield
Beispiel #2
0
    def pre_run_initialization(self):
        # 创建一个用户,开一家店
        self.seller_id = "test_cancel_order_seller_id_{}".format(
            str(uuid.uuid1()))
        self.store_id = "test_cancel_order_store_id_{}".format(
            str(uuid.uuid1()))
        self.password = self.seller_id
        gen_book = GenBook(self.seller_id, self.store_id)
        ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                            low_stock_level=False,
                                            max_book_count=5)
        self.buy_book_info_list = gen_book.buy_book_info_list
        assert ok
        self.seller = gen_book.get_seller()

        self.buyer_id = "test_cancel_order_buyer_id_{}".format(
            str(uuid.uuid1()))
        buyer1 = register_new_buyer(self.buyer_id, self.password)
        self.buyer = buyer1
        self.another_buyer_id = self.buyer_id + "_another"
        buyer2 = register_new_buyer(self.another_buyer_id, self.password)

        code, self.order_id = buyer1.new_order(self.store_id, buy_book_id_list)
        assert code == 200
        self.total_price = 0
        for item in self.buy_book_info_list:
            book: Book = item[0]
            num = item[1]
            self.total_price = self.total_price + book.price * num

        yield
    def pre_run_initialization(self):
        self.buyer_id = "test_search_order_buyer_id_{}".format(str(uuid.uuid1()))
        self.password = self.buyer_id
        b = register_new_buyer(self.buyer_id, self.password)
        self.buyer = b

        self.buyer2_id = "test_close_order_buyer2_id_{}".format(str(uuid.uuid1()))  # 2号无订单买家
        self.password2 = self.buyer2_id
        b2 = register_new_buyer(self.buyer2_id, self.password2)
        self.buyer2 = b2
        yield
    def pre_run_initialization(self):
        # do before test
        self.seller_id = "test_delivery_books_seller_id_{}".format(
            str(uuid.uuid1()))
        self.buyer_id = "test_delivery_books_buyer_id_{}".format(
            str(uuid.uuid1()))
        self.store_id = "test_delivery_books_store_id_{}".format(
            str(uuid.uuid1()))
        self.password = self.buyer_id
        self.total_price = 0
        self.buyer = register_new_buyer(self.buyer_id, self.password)

        self.gen_book = GenBook(self.seller_id, self.store_id)
        ok, buy_book_id_list = self.gen_book.gen(non_exist_book_id=False,
                                                 low_stock_level=False)
        assert ok
        self.buy_book_info_list = self.gen_book.buy_book_info_list
        for item in self.buy_book_info_list:
            price = item[2]
            num = item[1]
            if price is None:
                continue
            else:
                self.total_price = self.total_price + price * num
        code, self.order_id = self.buyer.new_order(self.store_id,
                                                   buy_book_id_list)
        assert code == 200

        yield
Beispiel #5
0
 def test_comment_while_order_is_not_done(self):
     gen_book = GenBook(self.seller_id, self.store_id)
     ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                         low_stock_level=False,
                                         max_book_count=5)
     self.buy_book_info_list = gen_book.buy_book_info_list
     assert ok
     b = register_new_buyer(self.buyer_id, self.password)
     self.buyer = b
     code, self.order_id = b.new_order(self.store_id, buy_book_id_list)
     assert code == 200
     self.total_price = 0
     for item in self.buy_book_info_list:
         book: Book = item[0]
         num = item[1]
         if book.price is None:
             continue
         else:
             self.total_price = self.total_price + book.price * num
     code = self.buyer.add_funds(self.total_price)
     assert code == 200
     s = Seller(conf.URL, self.seller_id, self.password)
     self.seller = s
     code = self.buyer.payment(self.order_id)
     assert code == 200
     code = self.seller.deliver_books(self.store_id, self.order_id)
     assert code == 200
     code = self.buyer.add_comment(self.store_id,
                                   self.buy_book_info_list[0][0].id,
                                   self.comment, self.rate)
     assert code != 200
    def pre_run_initialization(self):
        self.buyer_id = "test_search_order__buyer_{}".format(str(uuid.uuid1()))
        self.password = self.buyer_id
        b = register_new_buyer(self.buyer_id, self.password)
        self.buyer = b

        yield
Beispiel #7
0
    def pre_run_initialization(self):
        self.seller_id = "test_change_received_seller_id_{}".format(
            str(uuid.uuid1()))
        self.store_id = "test_change_received_store_id_{}".format(
            str(uuid.uuid1()))
        self.buyer_id = "test_change_received_buyer_id_{}".format(
            str(uuid.uuid1()))
        self.seller_password = self.seller_id
        self.buyer_password = self.buyer_id

        gen_book = GenBook(self.seller_id, self.store_id)
        ok, self.buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                                 low_stock_level=False,
                                                 max_book_count=20)
        self.buy_book_info_list = gen_book.buy_book_info_list
        assert ok

        # 创建用户
        self.buyer = register_new_buyer(self.buyer_id, self.buyer_password)

        # 生成订单
        code, self.order_id = self.buyer.new_order(self.store_id,
                                                   self.buy_book_id_list)
        assert code == 200

        self.total_price = 99
        for item in self.buy_book_info_list:
            book: Book = item[0]
            num = item[1]
            self.total_price = self.total_price + book.price * num
        code = self.buyer.add_funds(self.total_price)
        assert code == 200
Beispiel #8
0
    def gen_database(self):
        logging.info("load data")
        for i in range(1, self.seller_num + 1):
            user_id, password = self.to_seller_id_and_password(i)
            seller = register_new_seller(user_id, password)
            for j in range(1, self.store_num_per_user + 1):
                store_id = self.to_store_id(i, j)
                code = seller.create_store(store_id)
                assert code == 200
                self.store_ids.append(store_id)
                row_no = 0

                while row_no < self.book_num_per_store:
                    books = self.book_db.get_book_info(row_no, self.batch_size)
                    if len(books) == 0:
                        break
                    for bk in books:
                        code = seller.add_book(store_id, self.stock_level, bk)
                        assert code == 200
                        if i == 1 and j == 1:
                            self.book_ids.append(bk.id)
                    row_no = row_no + len(books)
        logging.info("seller data loaded.")
        for k in range(1, self.buyer_num + 1):
            user_id, password = self.to_buyer_id_and_password(k)
            buyer = register_new_buyer(user_id, password)
            buyer.add_funds(self.user_funds)
            self.buyer_ids.append(user_id)
        logging.info("buyer data loaded.")
Beispiel #9
0
 def test_ok(self):
     gen_book_1 = GenBook(self.seller1_id, self.store1_id)
     gen_book_2 = GenBook(self.seller2_id, self.store2_id)
     ok, buy_book_id_list_1 = gen_book_1.gen(non_exist_book_id=False,
                                             low_stock_level=False,
                                             max_book_count=5)
     ok, buy_book_id_list_2 = gen_book_2.gen(non_exist_book_id=False,
                                             low_stock_level=False,
                                             max_book_count=5)
     self.buy_book_info_list_1 = gen_book_1.buy_book_info_list
     self.buy_book_info_list_2 = gen_book_2.buy_book_info_list
     assert ok
     b = register_new_buyer(self.buyer_id, self.password)
     self.buyer = b
     buy_book_id_list_1 = list(
         list(items) for items in list(buy_book_id_list_1))
     buy_book_id_list_2 = list(
         list(items) for items in list(buy_book_id_list_2))
     cart_test = {
         self.store1_id: buy_book_id_list_1,
         self.store2_id: buy_book_id_list_2
     }
     for i in self.buy_book_info_list_1:
         code = self.buyer.add_into_cart(self.store1_id, i[0].id, i[1])
         assert code == 200
     for i in self.buy_book_info_list_2:
         code = self.buyer.add_into_cart(self.store2_id, i[0].id, i[1])
         assert code == 200
     code, cart = self.buyer.view_cart()
     assert code == 200
     assert cart == cart_test
     code = self.buyer.checkout_cart()
     assert code == 200
 def pre_run_initialization(self):
     self.seller_id = "test_confirm_receipt_seller_id_{}".format(
         str(uuid.uuid1()))
     self.store_id = "test_confirm_receipt_store_id_{}".format(
         str(uuid.uuid1()))
     self.buyer_id = "test_confirm_receipt_buyer_id_{}".format(
         str(uuid.uuid1()))
     self.password = self.seller_id
     gen_book = GenBook(self.seller_id, self.store_id)
     ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                         low_stock_level=False,
                                         max_book_count=5)
     self.buy_book_info_list = gen_book.buy_book_info_list
     assert ok
     b = register_new_buyer(self.buyer_id, self.password)
     self.buyer = b
     code, self.order_id = b.new_order(self.store_id, buy_book_id_list)
     assert code == 200
     self.total_price = 0
     for item in self.buy_book_info_list:
         book: Book = item[0]
         num = item[1]
         if book.price is None:
             continue
         else:
             self.total_price = self.total_price + book.price * num
     code = self.buyer.add_funds(self.total_price)
     assert code == 200
     s = Seller(conf.URL, self.seller_id, self.password)
     self.seller = s
     code = self.buyer.payment(self.order_id)
     assert code == 200
     yield
    def pre_run_initialization(self):
        self.store_id = "test_cancel_store_{}".format(str(uuid.uuid1()))
        self.seller_id = "test_cancel_seller_{}".format(str(uuid.uuid1()))
        self.store_id = "test_cancel_store_id_{}".format(str(uuid.uuid1()))
        self.buyer_id = "test_cancel__buyer_{}".format(str(uuid.uuid1()))

        gen_book = GenBook(self.seller_id, self.store_id)
        self.seller = gen_book.seller
        ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                            low_stock_level=False,
                                            max_book_count=5)
        self.buy_book_info_list = gen_book.buy_book_info_list
        assert ok
        self.password = self.buyer_id
        b = register_new_buyer(self.buyer_id, self.password)
        self.buyer = b
        self.total_price = 0
        for item in self.buy_book_info_list:
            book: Book = item[0]
            num = item[1]
            self.total_price = self.total_price + book.price * num
        code = self.buyer.add_funds(self.total_price + 100000)
        assert code == 200

        code, self.order_id = b.new_order(self.store_id, buy_book_id_list)
        assert code == 200
        yield
Beispiel #12
0
 def pre_run_initialization(self):
     self.seller_id = "test_deliver_book_seller_id_{}".format(
         str(uuid.uuid1()))
     self.store_id = "test_deliver_book_store_id_{}".format(
         str(uuid.uuid1()))
     self.buyer_id = "test_deliver_book_buyer_id_{}".format(
         str(uuid.uuid1()))
     self.password = self.seller_id
     #会注册该seller和店铺
     gen_book = GenBook(self.seller_id, self.store_id)
     s = gen_book.seller
     self.seller = s
     #书籍信息
     ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                         low_stock_level=False,
                                         max_book_count=1)
     self.buy_book_info_list = gen_book.buy_book_info_list
     assert ok
     #添加新的买家
     b = register_new_buyer(self.buyer_id, self.password)
     self.buyer = b
     #添加新的订单
     code, self.order_id = b.new_order(self.store_id, buy_book_id_list)
     assert code == 200
     #计算书的总价格
     self.total_price = 0
     for item in self.buy_book_info_list:
         book: Book = item[0]
         num = item[1]
         if book.price is None:
             continue
         else:
             self.total_price = self.total_price + book.price * num
     yield
Beispiel #13
0
    def pre_run_initialization(self):
        self.seller_id = "test_auto_comment_seller_id_{}".format(
            str(uuid.uuid1()))
        self.store_id = "test_auto_comment_store_id_{}".format(
            str(uuid.uuid1()))
        self.buyer_id = "test_auto_comment_buyer_id_{}".format(
            str(uuid.uuid1()))
        self.seller_password = self.seller_id
        self.buyer_password = self.buyer_id

        # 创建商家用户并插入图书数据
        gen_book = GenBook(self.seller_id, self.store_id)
        ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                            low_stock_level=False,
                                            max_book_count=20)
        self.buy_book_info_list = gen_book.buy_book_info_list
        assert ok

        # 创建用户
        self.buyer = register_new_buyer(self.buyer_id, self.buyer_password)

        # 生成订单
        code, self.order_id = self.buyer.new_order(self.store_id,
                                                   buy_book_id_list)
        assert code == 200
Beispiel #14
0
 def pre_run_initialization(self):
     self.seller_id = "test_new_order_seller_id_{}".format(str(uuid.uuid1()))
     self.store_id = "test_new_order_store_id_{}".format(str(uuid.uuid1()))
     self.buyer_id = "test_new_order_buyer_id_{}".format(str(uuid.uuid1()))
     self.password = self.seller_id  # self.password = self.buyer_id
     self.buyer = register_new_buyer(self.buyer_id, self.password)
     self.gen_book = GenBook(self.seller_id, self.store_id)
     yield
Beispiel #15
0
    def pre_run_initialization(self):

        self.buyer_id = "test_track_order_buyer_id_{}".format(str(
            uuid.uuid1()))
        # 创建用户
        self.buyer_password = self.buyer_id
        self.buyer = register_new_buyer(self.buyer_id, self.buyer_password)

        # 生成十家不同店铺的订单
        for i in range(10):
            self.seller_id = "test_change_status_to_unreceived_seller_id_{}".format(
                str(uuid.uuid1()))
            self.store_id = "test_change_status_to_unreceived_store_id_{}".format(
                str(uuid.uuid1()))
            self.seller_password = self.seller_id
            # 创建商家用户并插入图书数据
            gen_book = GenBook(self.seller_id, self.store_id)
            ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                                low_stock_level=False,
                                                max_book_count=20)
            self.buy_book_info_list = gen_book.buy_book_info_list
            assert ok

            # 生成订单
            code, self.order_id = self.buyer.new_order(self.store_id,
                                                       buy_book_id_list)
            assert code == 200

            self.total_price = 0
            for item in self.buy_book_info_list:
                book: Book = item[0]
                num = item[1]
                self.total_price = self.total_price + book.price * num

            code = self.buyer.add_funds(100 + self.total_price)
            assert code == 200

            if i % 5 == 0:
                code = cancel_order(self.buyer_id, self.buyer_password,
                                    self.order_id)
                assert code == 200
            else:
                if i % 5 >= 2:
                    code = self.buyer.payment(self.order_id)
                    assert code == 200
                if i % 5 >= 3:
                    code = change_unreceived(self.seller_id,
                                             self.seller_password,
                                             self.store_id, self.order_id)
                    assert code == 200
                if i % 5 >= 4:
                    code = change_received(self.buyer_id, self.buyer_password,
                                           self.order_id)
                    assert code == 200
Beispiel #16
0
 def test_false_buyer(self):
     code = self.buyer.add_funds(self.total_price)
     assert code == 200
     code = self.buyer.payment(self.order_id)
     assert code == 200
     code = self.seller.deliver(self.seller_id, self.order_id)
     assert code == 200
     
     fake_b = register_new_buyer(self.buyer_id + 's', self.password + 's')
     code = fake_b.receive(self.order_id)
     assert code != 200
Beispiel #17
0
 def pre_run_initialization(self):
     self.seller_id = "test_new_order_seller_id_{}".format(str(uuid.uuid1()))
     self.store_id = "test_new_order_store_id_{}".format(str(uuid.uuid1()))
     self.buyer_id = "test_new_order_buyer_id_{}".format(str(uuid.uuid1()))
     self.password = self.seller_id
     self.buyer = register_new_buyer(self.buyer_id, self.password)
     self.gen_book = GenBook(self.seller_id, self.store_id)
     ok, buy_book_id_list = self.gen_book.gen(non_exist_book_id=False, low_stock_level=False)
     assert ok
     code, _ = self.buyer.new_order(self.store_id, buy_book_id_list)
     assert code == 200
     yield
Beispiel #18
0
 def test_non_exist_store(self):
     gen_book_1 = GenBook(self.seller1_id, self.store1_id)
     ok, buy_book_id_list_1 = gen_book_1.gen(non_exist_book_id=False,
                                             low_stock_level=False,
                                             max_book_count=5)
     self.buy_book_info_list_1 = gen_book_1.buy_book_info_list
     assert ok
     b = register_new_buyer(self.buyer_id, self.password)
     self.buyer = b
     for i in self.buy_book_info_list_1:
         code = self.buyer.add_into_cart(self.store1_id + "_x", i[0].id,
                                         i[1])
         assert code != 200
Beispiel #19
0
 def test_non_exist_order(self):
     gen_book = GenBook(self.seller_id, self.store_id)
     ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                         low_stock_level=False,
                                         max_book_count=5)
     self.buy_book_info_list = gen_book.buy_book_info_list
     assert ok
     b = register_new_buyer(self.buyer_id, self.password)
     self.buyer = b
     code = self.buyer.add_comment(self.store_id,
                                   self.buy_book_info_list[0][0].id,
                                   self.comment, self.rate)
     assert code != 200
Beispiel #20
0
 def pre_run_initialization(self):
     self.seller_id = "test_view_historical_seller_id_{}".format(str(uuid.uuid1()))
     self.store_id = "test_view_historical_store_id_{}".format(str(uuid.uuid1()))
     self.buyer_id = "test_view_historical_buyer_id_{}".format(str(uuid.uuid1()))
     self.password = self.seller_id
     gen_book = GenBook(self.seller_id, self.store_id)
     ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False, low_stock_level=False, max_book_count=5)
     self.buy_book_info_list = gen_book.buy_book_info_list
     assert ok
     b = register_new_buyer(self.buyer_id, self.password)
     self.buyer = b
     code, self.order_id = b.new_order(self.store_id, buy_book_id_list)
     self.time = time.strftime('%a, %d %b %Y %H:%M:%S GMT', time.localtime(time.time()))
     yield
 def pre_run_initialization(self):
     self.seller_id = "test_payment_seller_id_{}".format(str(uuid.uuid1()))
     self.store_id = "test_payment_store_id_{}".format(str(uuid.uuid1()))
     self.buyer_id = "test_payment_buyer_id_{}".format(str(uuid.uuid1()))
     self.password = self.seller_id
     gen_book = GenBook(self.seller_id, self.store_id)
     ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                         low_stock_level=False,
                                         max_book_count=5)
     self.buy_book_info_list = gen_book.buy_book_info_list
     assert ok
     b = register_new_buyer(self.buyer_id, self.password)
     self.buyer = b
     code, self.order_id = b.new_order(self.store_id, buy_book_id_list)
     assert code == 200
    def pre_run_initialization(self):
        self.seller_id = "test_search_book_in_site_seller_id_{}".format(str(uuid.uuid1()))
        self.store_id = "test_search_book_in_site_store_id_{}".format(str(uuid.uuid1()))
        self.buyer_id = "test_search_book_in_site_buyer_id_{}".format(str(uuid.uuid1()))
        self.seller_password = self.seller_id
        self.buyer_password = self.buyer_id
        self.key_word = "科学"

        # 创建商家用户并插入图书数据
        gen_book = GenBook(self.seller_id, self.store_id)
        ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False, low_stock_level=False, max_book_count=20)
        self.buy_book_info_list = gen_book.buy_book_info_list
        assert ok

        # 创建用户
        self.buyer = register_new_buyer(self.buyer_id, self.buyer_password)
    def pre_run_initialization(self):
        engine = create_engine(
            'postgresql://*****:*****@localhost:5432/bookstore')
        DBSession = sessionmaker(bind=engine)
        self.session = DBSession()
        self.seller_id = "test_autocancel_seller_{}".format(str(uuid.uuid1()))
        self.store_id = "test_autocancel_store_{}".format(str(uuid.uuid1()))
        self.buyer_id = "test_autocancel_buyer_{}".format(str(uuid.uuid1()))
        self.password = self.seller_id
        self.buyer = register_new_buyer(self.buyer_id, self.password)
        self.gen_book = GenBook(self.seller_id, self.store_id)

        ok, buy_book_id_list = self.gen_book.gen(non_exist_book_id=False,
                                                 low_stock_level=False)
        assert ok

        code, self.order_id = self.buyer.new_order(self.store_id,
                                                   buy_book_id_list)
        assert code == 200
        yield
Beispiel #24
0
 def pre_run_initialization(self):
     self.query = '感人'
     self.title = '美丽心灵'
     self.tag = '漫画'
     self.author = '张乐平'
     self.seller_id = "test_add_book_stock_level1_user_{}".format(
         str(uuid.uuid1()))
     self.store_id = "test_add_book_stock_level1_store_{}".format(
         str(uuid.uuid1()))
     self.password = self.seller_id
     self.seller = register_new_seller(self.seller_id, self.password)
     self.buyer_id = "test_new_order_buyer_id_{}".format(str(uuid.uuid1()))
     self.buyer = register_new_buyer(self.buyer_id, self.password)
     code = self.seller.create_store(self.store_id)
     assert code == 200
     book_db = book.BookDB()
     self.books = book_db.get_book_id(0, 2)
     for bk in self.books:
         code = self.seller.add_book(self.store_id, 0, bk, 20)
         assert code == 200
     yield
    def pre_run_initialization(self):
        # 创建一个用户,开一家店
        self.seller_id = "test_admmit_return_seller_id_{}".format(
            str(uuid.uuid1()))
        self.store_id = "test_admmit_return_store_id_{}".format(
            str(uuid.uuid1()))
        self.password = self.seller_id
        gen_book = GenBook(self.seller_id, self.store_id)
        ok, buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                            low_stock_level=False,
                                            max_book_count=5)
        self.buy_book_info_list = gen_book.buy_book_info_list
        assert ok

        self.seller = gen_book.get_seller()

        self.buyer_id = "test_admmit_return_buyer_id_{}".format(
            str(uuid.uuid1()))
        b = register_new_buyer(self.buyer_id, self.password)
        self.buyer = b
        code, self.order_id = b.new_order(self.store_id, buy_book_id_list)
        assert code == 200
        self.total_price = 0
        for item in self.buy_book_info_list:
            book: Book = item[0]
            num = item[1]
            self.total_price = self.total_price + book.price * num

        code = self.buyer.add_funds(self.total_price)
        assert code == 200
        code = self.buyer.payment(self.order_id)
        assert code == 200

        code = self.seller.deliver(self.seller_id, self.order_id)
        assert code == 200

        self.another_seller_id = self.seller_id + "_another"
        self.another_seller = register_new_seller(self.another_seller_id,
                                                  self.password)
        yield
Beispiel #26
0
 def pre_run_initialization(self):
     self.buyer_id = "check_balance_buyer_id_{}".format(str(uuid.uuid1()))
     self.password = self.buyer_id
     self.buyer = register_new_buyer(self.buyer_id, self.password)
     yield
Beispiel #27
0
 def pre_run_initialization(self):
     self.user_id = "test_add_funds_{}".format(str(uuid.uuid1()))
     self.password = self.user_id
     self.buyer = register_new_buyer(self.user_id, self.password)
     yield
    def pre_run_initialization(self):
        self.seller_id = "test_get_comment_by_book_id_seller_id_{}".format(
            str(uuid.uuid1()))
        self.store_id = "test_get_comment_by_book_id_store_id_{}".format(
            str(uuid.uuid1()))
        self.seller_password = self.seller_id

        self.seller = register_new_seller(self.seller_id, self.seller_password)

        self.seller.create_store(self.store_id)

        book_db = book.BookDB()
        self.books = book_db.get_book_info(0, 5)
        self.book_id_list = []
        self.book_info_list = []

        for bk in self.books:
            code = self.seller.add_book(self.store_id, 0, bk)
            assert code == 200
            code = self.seller.add_stock_level(self.seller_id, self.store_id,
                                               bk.id, 100000)
            assert code == 200
            num = random.randint(1, 100)
            self.book_id_list.append((bk.id, num))
            self.book_info_list.append((bk, num))

        for i in range(10):
            self.buyer_id = "test_change_status_to_unreceived_buyer_id_{}".format(
                str(uuid.uuid1()))
            self.buyer_password = self.buyer_id
            self.buyer = register_new_buyer(self.buyer_id, self.buyer_password)

            # 生成订单
            code, self.order_id = self.buyer.new_order(self.store_id,
                                                       self.book_id_list)
            assert code == 200

            self.total_price = 0
            for item in self.book_info_list:
                bk: Book = item[0]
                num = item[1]
                self.total_price = self.total_price + bk.price * num
            code = self.buyer.add_funds(self.total_price)
            assert code == 200

            code = self.buyer.payment(self.order_id)
            assert code == 200

            code = change_unreceived(self.seller_id, self.seller_password,
                                     self.store_id, self.order_id)
            assert code == 200

            code = change_received(self.buyer_id, self.buyer_password,
                                   self.order_id)
            assert code == 200

            code, self.orderdetails = track_order_by_order_id(
                self.buyer_id, self.buyer_password, self.order_id)
            assert code == 200
            for orderdeatail in self.orderdetails:
                orderdetail_id = orderdeatail['orderdetail_id']
                self.star = random.randint(1, 5)
                self.content = ""
                for j in range(random.randint(2, 5)):
                    self.content += chr(random.randint(0x4e00, 0x9fbf))
                code = add_comment(self.buyer_id, self.buyer_password,
                                   orderdetail_id, self.star, self.content)
                assert code == 200
    def pre_run_initialization(self):
        # 创建一个用户,开一家店
        self.seller_id = "test_query_history_order_seller_id_{}".format(
            str(uuid.uuid1()))
        self.store_id = "test_query_history_order_store_id_{}".format(
            str(uuid.uuid1()))
        # self.password = self.seller_id
        gen_book = GenBook(self.seller_id, self.store_id)
        ok, self.buy_book_id_list = gen_book.gen(non_exist_book_id=False,
                                                 low_stock_level=False,
                                                 max_book_count=5)

        self.buy_book_info_list = gen_book.buy_book_info_list
        assert ok
        self.total_price = 0
        for item in self.buy_book_info_list:
            book: Book = item[0]
            num = item[1]
            self.total_price = self.total_price + book.price * num

        self.seller = gen_book.get_seller()

        self.buyer_id = "test_query_history_order_buyer_id_{}".format(
            str(uuid.uuid1()))
        self.password = self.buyer_id
        self.buyer = register_new_buyer(self.buyer_id, self.password)

        # 未付款
        code, self.order_id1 = self.buyer.new_order(self.store_id,
                                                    self.buy_book_id_list)
        assert code == 200

        # 已付款
        code, self.order_id2 = self.buyer.new_order(self.store_id,
                                                    self.buy_book_id_list)
        # assert self.buy_book_id_list==[]
        assert code == 200
        code = self.buyer.add_funds(self.total_price)
        assert code == 200
        code = self.buyer.payment(self.order_id2)
        assert code == 200

        # 已发货
        code, self.order_id3 = self.buyer.new_order(self.store_id,
                                                    self.buy_book_id_list)
        assert code == 200
        code = self.buyer.add_funds(self.total_price)
        assert code == 200
        code = self.buyer.payment(self.order_id3)
        assert code == 200
        code = self.seller.deliver(self.seller_id, self.order_id3)
        assert code == 200

        # 已收货
        code, self.order_id4 = self.buyer.new_order(self.store_id,
                                                    self.buy_book_id_list)
        assert code == 200
        code = self.buyer.add_funds(self.total_price)
        assert code == 200
        code = self.buyer.payment(self.order_id4)
        assert code == 200
        code = self.seller.deliver(self.seller_id, self.order_id4)
        assert code == 200
        code = self.buyer.receive(self.buyer_id, self.order_id4)
        assert code == 200
        yield