Пример #1
0
    def setUp(self):
        super(MyTestCase, self).setUp()

        self.db_session = model.testing_session()
        self.usermail = '*****@*****.**'
        self.user = {'name': 'ark', 'password': '******', 'email': self.usermail}
        self.auth_header = {
            'Authorization':
            'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.\
e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M'
        }
        self.bad_auth_header = {
            'Authorization':
            'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.\
e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0X'
        }

        user = model.User(**self.user)
        self.db_session.add(user)
        self.db_session.commit()
        self.user['id'] = user.id

        self.list = {
            'owner': user.id,
            'name': 'list 1',
            'products': [],
            'description': 'La lista de los jugos'
        }

        list_ = model.List(**self.list)
        self.db_session.add(list_)
        self.db_session.commit()
        self.list['id'] = list_.id

        self.product = {
            'name': 'soda',
            'unit': 'lt',
            'amount': '2',
            'description': 'A lot of sugar'
        }
        product = model.Product(**self.product)
        self.db_session.add(product)
        self.db_session.commit()
        self.product['id'] = product.id

        self.product2 = {
            'name': 'milk',
            'unit': 'ml',
            'amount': '1500',
            'description': 'Cow legacy'
        }
        product = model.Product(**self.product2)
        self.db_session.add(product)
        self.db_session.commit()
        self.product2['id'] = product.id

        self.app = hunterprice.create_api(self.db_session)
Пример #2
0
def test_retrieving_products(session):
    session.execute(
        "INSERT INTO products (reference, sku, _purchased_quantity, maxAllowedPurchaseQty, brand , price)"
        ' VALUES ("product1", "sku1", 100, 10, "IDAYAM", 5.65 )')
    session.execute(
        "INSERT INTO products (reference, sku, _purchased_quantity, maxAllowedPurchaseQty, brand , price)"
        ' VALUES ("product2", "sku2", 200, 5, "MAGGI", 1.25)')
    expected = [
        model.Product("product1", "sku1", 100, 10, "IDAYAM", 5.65),
        model.Product("product2", "sku2", 200, 5, "MAGGI", 1.25),
    ]

    assert session.query(model.Product).all() == expected
Пример #3
0
    def _change_count(self, evt):
        on_cart = evt.rowModel

        try:
            value = int(evt.editor.Value)
        except ValueError:
            print('_change_count: ', locale.POSITIVE)
            evt.Veto()
            return

        if value <= 0:
            print('_change_count: ', locale.POSITIVE)
            evt.Veto()
            return

        in_db = model.Product(self.shop.select_row('products', on_cart.id))

        new_reserved = value + in_db.reserved - on_cart.count
        if new_reserved > in_db.count:
            print('_change_count: ', locale.LACK)
            evt.Veto()
            return

        try:
            self.shop.update('products', 'reserved', in_db.id, new_reserved)
        except ex.DbException as e:
            print('_change_count: ', e.message)
            evt.Veto()
Пример #4
0
def test_error_for_invalid_sku():
    item = model.CartItem("i1", "NONEXISTENTSKU", 10)
    product = model.Product("p1", "AREALSKU", 100,  100, 'A REAL SKU' , 100)
    repo = FakeRepository([product])

    with pytest.raises(services.InvalidSku, match="Invalid sku NONEXISTENTSKU"):
        services.add(item, repo, FakeSession())
Пример #5
0
def test_returns_item():
    item = model.CartItem("i1", "CHAKRI ATTA", 10)
    product = model.Product("p1", "CHAKRI ATTA", 100,  100, 'CHAKRI ATTA' , 16)
    repo = FakeRepository([product])

    result = services.add(item, repo, FakeSession())
    assert result == "p1"
Пример #6
0
 def on_post(self, req, resp):
     data = req.context['data']
     product = model.Product(**data)
     self.session.add(product)
     self.session.commit()
     product.id
     req.context['result'] = product
Пример #7
0
def test_saving_products(session):
    product = model.Product("product1", "sku1", 100, 10, "IDAYAM", 5.65)
    session.add(product)
    session.commit()
    rows = session.execute(
        'SELECT reference, sku, _purchased_quantity, maxAllowedPurchaseQty, brand, price FROM "products"'
    )
    assert list(rows) == [("product1", "sku1", 100, 10, "IDAYAM", 5.65)]
Пример #8
0
def test_commits():
    item = model.CartItem("i1", "CHAKRI ATTA", 10)
    product = model.Product("p1", "CHAKRI ATTA", 100,  100, 'CHAKRI ATTA' , 16)
    repo = FakeRepository([product])
    session = FakeSession()

    services.add(item, repo, session)
    assert session.committed is True
Пример #9
0
def deploy_two_products_in_vm(request, template_name):
    atts = []
    atts.append({'port': '8080'})
    template = model.Template(template_name)
    product = model.Product('tomcat', 'io.murano.apps.apache.Tomcat', atts)
    net = model.Network("node-int-net-01", True)
    inst = model.Instance('ubuntu', 'Ubuntu14.04init_deprecated', '2', '',
                          False, [net])
    service = model.Service(product.name, product)
    service.add_instance(inst)
    template.add_service(service)

    product2 = model.Product('tomcat', 'io.murano.apps.apache.Tomcat', atts)
    service2 = model.Service(product2.name, product2)
    service.add_instance(inst, True)
    template.add_service(service2)
    request.deploy_template(template)
Пример #10
0
def test_saving_items(session):
    product = model.Product("product1", "sku1", 100, 10, "IDAYAM", 5.65)
    item = model.CartItem("item1", "sku1", 2)
    product.add(item)
    session.add(product)
    session.commit()
    rows = list(session.execute('SELECT cartitem_id, product_id FROM "items"'))
    assert rows == [(product.id, item.id)]
Пример #11
0
def seed_activities():
    """Fill the Activity table with standard data"""
    
    Activities_dictionary = {
    "shampoo": {
        "description": "Put a small amount of shampoo into your hand, rub your hands together, and then rub this shampoo into your hair. Use your fingertips to massage your head, so the shampoo can clean your scalp.", 
        "video": "https://giphy.com/embed/10uVasOeFs6U92",
        "image": "/static/img/shampoo.png"
        }, 
    "conditioner": {
        "description": "Put a small amount of conditioner into your hand, rub your hands together, and then massage this conditioner into your hair. Work the conditioner through your hair, all the way to the ends.", 
        "video": "https://giphy.com/embed/mRvJKBHGhJFIc",
        "image": "/static/img/conditioner.png"
        },
    "bar-soap": {
        "description": "Get the bar of soap wet and rub the bar onto a washcloth to create a lather. Scrub your body, starting at your neck and working down. Give an extra scrub to your underarms and private areas.",
        "video": "https://giphy.com/embed/3o6MbjjOqVPMHZvuve",
        "image": "/static/img/bar_soap.png"
        },
    "liquid-soap": {
        "description": "Squirt a small amount of the soap onto loofah and scrub! Start at your neck and working down. Give an extra scrub to your underarms and private areas.",
        "video": "https://giphy.com/embed/3o6nUOysbD4Q4WEKuA",
        "image": "/static/img/liquid_soap.png"
        },
    "shave-face": {
        "description": "Squirt a small amount of shaving cream into your palm, rub your hands together, and then smear the cream on your cheeks, chin, and upper lip. Carefully shave away any hair. Take your time!",
        "video": "https://giphy.com/embed/l3q2NRoiCbOtccRqw",
        "image": "/static/img/razor2.png"
        },
    "shave-armpits": {
        "description": "Squirt a small amount of shaving cream into your palm, rub your hands together, and then smear the cream on your underarms. Carefully shave away any hair. Take your time!",
        "video": "https://giphy.com/embed/pXPytwoLcTRJu",
        "image": "/static/img/razor_blades.png"
        },
    "shave-legs": {
        "description": "Squirt a small amount of shaving cream into your palm, rub your hands together, and then smear the cream on your left leg. Carefully shave away any hair. Repeat this on your right leg. Take your time!",
        "video": "https://giphy.com/embed/TlK63EoG08XCy2J9ZWU",
        "image": "/static/img/lady_razor.png"
        },
}


    actions = []
    stuff = []

    for key in Activities_dictionary:
        act = model.Activity(activity_name=key, 
                description=Activities_dictionary[key]["description"], 
                activity_video=Activities_dictionary[key]["video"])
        actions.append(act)
        thing = model.Product(product_name=key,
            product_img=Activities_dictionary[key]["image"])
        stuff.append(thing)


    model.db.session.add_all(actions)
    model.db.session.add_all(stuff)
    model.db.session.commit()
Пример #12
0
def to_product(db_row):
    refs_index = __find_index(m.PRODUCT_COMBINED_FIELDS, 'reference')
    refs_by_flor = db_row[refs_index].split('_')
    refs_by_dash = db_row[refs_index].split('-')
    refs = refs_by_flor if len(refs_by_flor) >= len(
        refs_by_dash) else refs_by_dash
    if len(refs) == 1 and refs[0] == '':
        refs.clear()
    return m.Product(*db_row, references=refs)
Пример #13
0
def deploy_no_network(request, template_name):
    atts = []
    atts.append({'port': '8080'})
    template = model.Template(template_name)
    product = model.Product('tomcat', 'io.murano.apps.apache.Tomcat', atts)
    inst = model.Instance('ubuntu', 'Ubuntu14.04init_deprecated', '2', '',
                          False)
    service = model.Service(product.name, product)
    service.add_instance(inst)
    template.add_service(service)
    request.deploy_template(template)
Пример #14
0
def deploy_orion_docker(request, template_name):
    template = model.Template(template_name)
    net = model.Network("node-int-net-01", True)

    inst = model.Instance('ubuntu', 'Ubuntu14.04init_deprecated', '2', '',
                          False, [net])
    product = model.Product('docker',
                            'io.murano.apps.docker.DockerStandaloneHost')
    service = model.Service(product.name, product)
    service.add_instance(inst)

    atts = []
    atts.append({'publish': True})
    atts.append({'host': product.id})
    product = model.Product('dockerorion', 'io.murano.apps.docker.DockerOrion',
                            atts)
    service2 = model.Service(product.name, product)

    template.add_service(service)
    template.add_service(service2)
    request.deploy_template(template)
Пример #15
0
def deploy_orion_chef(request, template_name):
    atts = []
    atts.append({'port': '1026'})
    product = model.Product('orionchef', 'io.murano.conflang.chef.GitChef',
                            atts)
    template = model.Template(template_name)
    net = model.Network("node-int-net-01", True)
    inst = model.Instance('centos', 'CentOS-6.5init_deprecated', '2', 'demo4',
                          False, [net])
    service = model.Service(product.name, product)
    service.add_instance(inst)
    template.add_service(service)
    request.deploy_template(template)
Пример #16
0
    def showProducts(self, keyword):
        self.recentSearch = keyword
        queryResult = self.client["product"].find().sort(
            "name", pymongo.ASCENDING)
        data = {"user": self.model, "products": list()}

        for i in queryResult:
            if keyword in i["name"].lower():
                data["products"].append(
                    model.Product(i["_id"], i["name"], i["price"], i["pic"],
                                  i["qty"], i["sold"], i["input_date"]))

        return self.view.showProducts(data)
Пример #17
0
def test_repository_can_save_a_product(session):
    product = model.Product("product1", "PALAK-LEAF", 100, 10, "OM PRODUCES",
                            1.45)

    repo = repository.SqlAlchemyRepository(session)
    repo.add(product)
    session.commit()

    rows = session.execute(
        'SELECT reference, sku, _purchased_quantity, maxAllowedPurchaseQty, brand, price FROM "products"'
    )
    assert list(rows) == [("product1", "PALAK-LEAF", 100, 10, "OM PRODUCES",
                           1.45)]
Пример #18
0
def test_repository_can_retrieve_a_product_with_items(session):
    cartitem_id = insert_cart_item(session)
    product1_id = insert_product(session, "product1")
    insert_product(session, "product2")
    insert_item(session, cartitem_id, product1_id)

    repo = repository.SqlAlchemyRepository(session)
    retrieved = repo.get("product1")

    expected = model.Product("product1", "EASTERN-MASALA", 100, 10, "EASTERN",
                             1.65)
    assert retrieved == expected  # Product.__eq__ only compares reference
    assert retrieved.sku == expected.sku
    assert retrieved._purchased_quantity == expected._purchased_quantity
    assert retrieved._items == {
        model.CartItem("item1", "EASTERN-MASALA", 5),
    }
Пример #19
0
def add_product(referrer):
    form = AddProductForm()
    search_bar = search()

    if form.validate_on_submit():
        user_id = form.user_id.data
        name = form.name.data.strip()
        asin = form.asin.data.strip()
        category_id = form.category_id.data
        default_photo = form.default_photo.data.strip()
        custom_photo = form.custom_photo.data

        new_product = model.Product(name=name,
                                    asin=asin,
                                    category_id=category_id,
                                    default_photo=default_photo,
                                    custom_photo=custom_photo)
        new_product_id = new_product.id

        if referrer == 'new':
            model.session.add(new_product)
            model.session.commit()

        add_to_lib = model.Library(user_id=user_id,
                                   product_id=new_product_id,
                                   product_desc=name,
                                   status=1)
        model.session.add(add_to_lib)
        model.session.commit()

        return jsonify(msg='Success')
    else:
        if referrer == 'new':
            return render_template("add_product.html",
                                   title="Add a Product",
                                   form=form,
                                   search=search_bar)
        else:
            return 'Fail'
Пример #20
0
from init import db
import model as m


def insert(*objects):
    for o in objects:
        db.session.add(o)
        print('Added {}'.format(o))


products = []
products.append(
    m.Product(name='Libella',
              picture='libella.jpg',
              size='0.5 l',
              prize=0.70,
              description='Alle Sorten',
              isOrganic=False,
              enabled=True))
products.append(
    m.Product(name='Löschzwerg',
              picture='löschzwerg.jpg',
              size='0.33 l',
              prize=1.0,
              description='',
              isOrganic=False,
              enabled=True))
products.append(
    m.Product(name='Bier/Radler',
              picture='waldhaus.jpg',
              size='0.33 l',
Пример #21
0
 def _display_data(self):
     data = [model.Product(x) for x in self.shop.get_from('products')]
     self.db_list.SetObjects(data)
Пример #22
0
def deploy_mysql_puppet(request, template_name):
    prod = model.Product('msyqlpuppet',
                         'io.murano.conflang.fiware.MySQLPuppet')
    deploy_blueprint_template(request, template_name, prod)
Пример #23
0
def deploy_orion_chef(request, template_name):
    atts = []
    atts.append({'port': '1026'})
    prod = model.Product('orionchef', 'io.murano.conflang.fiware.OrionChef',
                         atts)
    deploy_blueprint_template(request, template_name, prod)
Пример #24
0
def deploy_tomcat(request, template_name):
    atts = []
    atts.append({'port': '8080'})
    prod = model.Product('tomcat', 'io.murano.apps.apache.Tomcat', atts)
    deploy_blueprint_template(request, template_name, prod)
Пример #25
0
def deploy_git(request, template_name):
    atts = []
    atts.append({'repo': 'test'})
    prod = model.Product('git', 'io.murano.apps.linux.Git', atts)
    deploy_blueprint_template(request, template_name, prod)
Пример #26
0
def deploy_mysql_puppet(request, template_name):
    atts = []
    atts.append({'port': '1026'})
    prod = model.Product('msyqlpuppet',
                         'io.murano.conflang.puppet.MySQLPuppet', atts)
    deploy_blueprint_template(request, template_name, prod)
Пример #27
0
    def addProduct(self, error):
        data = {"user": self.model, "error": error}

        result = self.view.addProduct(data)
        if (result["action"] == None):
            isError = False
            col = self.client["product"]
            #check product name
            if (len(result["data"]["name"]) == 0):
                isError = True
                error["productName"] = "Product Name Can't be Empty"
            elif (col.find_one({"name": result["data"]["name"]}) != None):
                isError = True
                error["productName"] = "Product Name Already Used"
            #check product price
            try:
                if (int(result["data"]["price"]) < 0):
                    isError = True
                    error["productPrice"] = "Invalid Value"
            except:
                isError = True
                error["productPrice"] = "Invalid Value"
            #check product quantity
            try:
                if (int(result["data"]["qty"]) < 0):
                    isError = True
                    error["productQty"] = "Invalid Value"
            except:
                isError = True
                error["productQty"] = "Invalid Value"

            if (isError):
                return self.addProduct(error)
            else:
                col.insert_one({
                    "name":
                    result["data"]["name"],
                    "price":
                    int(result["data"]["price"]),
                    "pic":
                    "img/default-product.png",
                    "qty":
                    int(result["data"]["qty"]),
                    "sold":
                    0,
                    "input_date":
                    datetime.datetime.today().strftime("%Y-%m-%d %H:%M:%S")
                })

                currentProduct = self.client["product"].find_one(
                    {"name": result["data"]["name"]})

                #record action
                self.client["input_product_history"].insert_one({
                    "user":
                    self.model.getInfo()["_id"],
                    "product":
                    currentProduct["_id"],
                    "product_name":
                    currentProduct["name"],
                    "input_date":
                    currentProduct["input_date"]
                })

                result["action"] = "product-detail"
                result["product"] = model.Product(currentProduct["_id"],
                                                  result["data"]["name"],
                                                  int(result["data"]["price"]),
                                                  "img/default-product.png",
                                                  int(result["data"]["qty"]),
                                                  currentProduct["sold"],
                                                  currentProduct["input_date"])
                return result
        else:
            return result