Пример #1
0
 def test_add_item_correctly(self):
     session_id = 'someId'
     name = 'ItemName'
     price = 42.42
     category = 'Category'
     description = 'This is some item'
     attributes = {'att1': 42, 'att2': 'bla'}
     image_id = 'imageId'
     image_url = 'https://image.com'
     owner_id = str(ObjectId())
     owner = ShopOwner('login', 'pw', 'first', 'last', id=owner_id)
     self.shop_owner_handler.active_user_sessions[session_id] = owner
     shop = Shop('Shop', Address('', '', '', 0, 0), owner_id)
     shop_id = self.shops_dao.store_one(shop.to_db_object())
     item_id = self.item_handler.add_item(name, price, category, shop_id,
                                          description, attributes, image_id,
                                          image_url, session_id)
     items = self.items_dao.get_all()
     self.assertEqual(len(items), 1)
     self.assertEqual(str(items[0]['_id']), item_id)
     self.assertEqual(items[0]['name'], name)
     self.assertEqual(items[0]['price'], price)
     self.assertEqual(items[0]['category'], category)
     self.assertEqual(str(items[0]['shop']), shop_id)
     self.assertEqual(items[0]['details']['description'], description)
     self.assertEqual(items[0]['details']['attributes'], attributes)
     self.assertEqual(items[0]['image']['id'], image_id)
     self.assertEqual(items[0]['image']['url'], image_url)
Пример #2
0
 def test_add_item_with_incorrect_owner_id(self):
     session_id = 'sessionId'
     owner_id = str(ObjectId())
     other_owner_id = str(ObjectId())
     owner = ShopOwner('login', 'pw', 'first', 'last', id=other_owner_id)
     self.shop_owner_handler.active_user_sessions[session_id] = owner
     shop = Shop('Shop', Address('', '', '', 0, 0), owner_id)
     shop_id = self.shops_dao.store_one(shop.to_db_object())
     with self.assertRaises(UnauthorizedAccessError):
         self.item_handler.add_item('Item', 42.42, 'Category', shop_id,
                                    'Description', {}, 'imageId',
                                    'imageUrl', session_id)
Пример #3
0
def confirm():
    shop = Shop()
    shop.name = request.args['shop'].replace('.myshopify.com', '')
    api = ShopifyApi(shop)
    auth = request.args.get("code")
    api.confirm_installation(auth)

    try:
        token = shop.token
        shop = load_shop(shop.name)
        last_billing = shop.billing_id
        shop.token = token
    except TypeError:
        last_billing = None

    url = api.add_billing(last_billing)
    return redirect(url, code=302)
Пример #4
0
 def test_get_shops_correctly(self):
     address_1 = Address('Street 1', '12345', 'Country 1', 42.42, 13.37)
     address_2 = Address('Street 2', '54321', 'Country 2', 8.15, 44.44)
     shop_1 = Shop('Shop 1', address_1, str(ObjectId()))
     shop_2 = Shop('Shop 2', address_2, str(ObjectId()))
     shop_1_id = self.dao.store_one(shop_1.to_db_object())
     shop_2_id = self.dao.store_one(shop_2.to_db_object())
     shops = self.shop_handler.get_shops()
     self.assertEqual(len(shops), 2)
     self.assertIn(shop_1_id, [shop['id'] for shop in shops])
     self.assertIn(shop_2_id, [shop['id'] for shop in shops])
Пример #5
0
 def test_get_shops_correctly_with_session_id(self):
     session_id = 'sessionId'
     shop_owner_id = str(ObjectId())
     shop_owner = ShopOwner('login', 'pw', 'first', 'last', shop_owner_id)
     self.shop_owner_handler.active_user_sessions[session_id] = shop_owner
     address_1 = Address('Street 1', '12345', 'Country 1', 42.42, 13.37)
     address_2 = Address('Street 2', '54321', 'Country 2', 8.15, 44.44)
     shop_1 = Shop('Shop 1', address_1, shop_owner_id)
     shop_2 = Shop('Shop 2', address_2, str(ObjectId()))
     shop_1_id = self.dao.store_one(shop_1.to_db_object())
     shop_2_id = self.dao.store_one(shop_2.to_db_object())
     shops = self.shop_handler.get_shops(session_id=session_id)
     self.assertEqual(len(shops), 1)
     self.assertEqual(shops[0]['id'], shop_1_id)
Пример #6
0
def load_shop(name):

    shop = Shop()
    data = ref.child(name).get()

    shop.name = data['name']
    shop.token = data['token']
    shop.button_pos = data['button_pos']
    shop.button_enabled = data['button_enabled']
    shop.sticky_bar_enabled = data['sticky_bar_enabled']

    try:
        shop.phone = data['phone']
    except KeyError:
        shop.phone = None
    try:
        shop.predefined_text = data['predefined_text']
    except KeyError:
        shop.predefined_text = None
    try:
        shop.sticky_label_text = data['sticky_label_text']
    except KeyError:
        shop.sticky_label_text = None
    try:
        shop.sticky_bar_color = data['sticky_bar_color']
    except KeyError:
        shop.sticky_bar_color = '33CC33'
    try:
        shop.sticky_bar_text_color = data['sticky_bar_text_color']
    except KeyError:
        shop.sticky_bar_text_color = 'FFFFFF'
    try:
        shop.script_tag_id = data['script_tag_id']
    except KeyError:
        shop.script_tag_id = None
    try:
        shop.billing_id = data['billing_id']
    except KeyError:
        shop.billing_id = None

    return shop
Пример #7
0
# -*- coding:utf-8 -*-
# 商店信息测试

from config.appconfig import db
from model.shop import Shop
from model.user import User

user = User.query.filter_by(id = 1).first()

print(user)

shop = Shop(name = 'Moyani',address = "Guangzhou",userId = user.id)
db.session.add(shop)
db.session.commit()
print(shop)
Пример #8
0
def install_redirect():
    shop = Shop()
    shop.name = request.args['shop']
    api = ShopifyApi(shop)
    return redirect(api.redirect_to_install_confirmation(), code=302)