def test_successful_catalog(self): address_data = { "street": "primera", "city": "segunda", "state": "tercero", "country": "cuarto", "name_code": "123abc" } address = Address(**address_data) address.save() shop_data = { "name": "un ejemplo mas", "address_id": address.id } shop = Shop(**shop_data) shop.save() # Given payload = json.dumps({ "name": "prueba", "shop_id": shop.id }) # When response = self.app.post( '/api/v1/catalog/', headers={"Content-Type": "application/json"}, data=payload ) # Then self.assertEqual(dict, type(response.json)) self.assertEqual(201, response.status_code)
def system_on(): print('>>>>>SYSTEM ON<<<<<') name = input('\n유저 이름을 생성해 주세요\n입력 :') user1 = User(name) shop1 = Shop() while True: choice = input( '1. 검 구매' ' 2. 검 강화하기' ' 3. 랭크 보기' ' 0. 게임 종료' '\n선택 : ') if choice == '1': print(shop1.show_item_list) selected = input('\n구매할 아이템 선택 : ') sword1 = shop1.sell_item(selected) print(sword1.name) user1.buy_sword(sword1) print(user1.show_sword_list) elif choice == '2': do_enchant(user1) elif choice == '3': # with open('rank.txt', 'rt') as f: pass elif choice == '0': print('검 강화하기 게임을 종료하겠습니다') break else: print('없는 선택지 입니다. 다시 선택해주세요.')
def before_first_request(): # 生成测试数据 return db.drop_all() db.create_all() user = User() user.openid = '666' db.session.add(user) db.session.commit() for x in range(10): shop = Shop() shop.name = '麻辣卡鸭子' + str(x) shop.phonenumbers = '1,2,3' categories = [] for y in range(5): category = Category() category.name = '分类' + str(y) foods = [] for z in range(10): food = Food() food.name = '食物名称' + str(z) food.unit = str(z) food.price = str(z) food.quantity = str(z) foods.append(food) category.foods = foods categories.append(category) shop.categories = categories db.session.add(shop) db.session.commit()
def test_successful_inventory(self): address_data = { "street": "primera", "city": "segunda", "state": "tercero", "country": "cuarto", "name_code": "123abc" } address = Address(**address_data) address.save() shop_data = {"name": "un ejemplo mas", "address_id": address.id} shop = Shop(**shop_data) shop.save() catalog_data = {"name": "primavera verano", "shop_id": shop.id} catalog = Catalog(**catalog_data) catalog.save() product_data = { "title": "p2", "description": "un articulo de ropa", "price": 2.2, "is_featured": True, "sku": "abc12345678", "catalog_id": catalog.id, } product = Product(**product_data) product.save() inventory_data = { "product_id": product.id, "quantity": 10, "shop_id": shop.id } inventory = Inventory(**inventory_data) inventory.save() # Given payload = json.dumps({ "sku": "abc12345678", "quantity": 10, "shop_id": shop.id }) # When response = self.app.post('/api/v1/inventory/', headers={"Content-Type": "application/json"}, data=payload) # Then self.assertEqual(dict, type(response.json)) self.assertEqual(200, response.status_code)
def post(self): shop_data = ShopSchema().load(request.json) address_data = shop_data.pop("address_id") address = Address(**address_data) try: address.save() except: return {"message": ERROR_INSERTING_ADDRESS}, 500 shop = {"name": shop_data.get("name"), "address_id": address.id} shop = Shop(**shop) try: shop.save() except: return {"message": ERROR_INSERTING_SHOP}, 500 return {"id": str(shop.id)}, 201
def shop_gen(name="shop", description="this a shop", commission=5, shop_type="All", abilities=None): if shop_type == "Merlin": name = "Merlin Shop" # description = "Merlin sells scrolls of knowledge that you can learn new abilities from them or you can sell scroll to him." description = "Merlin buy and sell everything, even souls of mortals" commission = 2 shop = Shop( 0, name, description, commission, Inventory(scroll_list=create_scrolls(abilities), armor_list=epic_armors, weapon_list=epic_weapons, potion_list=epic_potions, misc_list=[], coin=10000000)) elif shop_type == "Blacksmith": name = "Vulcan Blacksmith" description = "Vulcan epic weapons and armors" commission = 10 shop = Shop( 0, name, description, commission, Inventory(armor_list=epic_armors, weapon_list=epic_weapons)) elif shop_type == "Apothecary": shop = Shop(0, name, description, commission, Inventory(potion_list=epic_potions)) else: name = "Mercury shop" description = "Mercury buy and sell everything, even souls of mortals" commission = 20 shop = Shop( 0, name, description, commission, Inventory(armor_list=epic_armors, weapon_list=epic_weapons, potion_list=epic_potions)) return shop
def create_shop(): user = User() user.username = '******' user.passwd = 'test_pass' user.save() client = Client() client.username = '******' client.email = 'test_phone' client.phone = 'test_pass' client.save() shop = Shop() shop.user = user.id shop.client = client.id shop.save() return shop
def test_shops(self): """ test the @property shop to retrieve a list of shop correspoding to this user """ user = User() user.username = '******' user.passwd = 'test_pass' user.save() client = Client() client.username = '******' client.email = 'test_phone' client.phone = 'test_pass' client.save() user.save() shop = Shop() shop.user = user.id shop.client = client.id shop.save() req_shop = user.shops[0] self.assertIsNotNone(req_shop) storage.delete(user) storage.save() storage.close()
def init_shop(self): shop = get_taobao_shop(self.user['nick']) shop['user_id'] = self.user['uid'] Shop.create(shop)
def create_category(): """ Creates a new category linked to a shop create a shop if the user doesn't have one --- parameters: - in: header name: authorization required: true schema: type: string - in: query name: title required: true schema: type: string - in: query name: description required: true schema: type: string responses: 200: description: the category was saved succefully schema: type: object parameters: id: type: string example: 1239102941-1231290412-dfs12rf-123re-1234r223 400: description: incomplete request schema: type: object parameters: message: type: string example: incomplete request """ state = request.get_json() user = request.user # tests the input values print(state) if not state['title'] or not state['description']: return jsonify(message="incomplete request"), 400 # verify the store for the user shops = storage.filter_by(Shop, 'user', user) shop = None for shp in shops: if shp.user == user: shop = shp # if shop doesn't exists create a new instance if not shop: shop = Shop() shop.user = user shop.save() # Create the Category instance category = Category() category.title = state['title'] category.description = state['description'] category.shop = shop.id category.save() return jsonify(id=category.id)
def shops(): js = jsonify(Shop.get_all()) file = open('json', 'wb') file.write(js.data) return js