def callback(ch, method, properties, body):
    print('Received in main')
    data = json.loads(body)
    print(data)

    if properties.content_type == 'product created':
        product = Product(id=data['id'],
                          title=data['title'],
                          image=data['image'])
        db.session.add(product)
        db.session.commit()
        print('Product created')

    elif properties.content_type == 'product updated':
        product = Product.query.get(data['id'])
        product.title = data['title']
        product.image = data['image']
        db.session.commit()
        print('Product changed')

    elif properties.content_type == 'product list requested':

        requests.get('http://docker.for.mac.localhost:8001/api/products')
        print('Product list sent')

    elif properties.content_type == 'product deleted':
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()
        print('Product deleted')
Beispiel #2
0
def callback(ch, method, properties, body):
    print('Recieve in-main')
    data = json.loads(body)
    print(data)

    if properties.content_type == 'product-created':
        product = Product(id=data['id'], title=data['title'], image=data['image'])
        db.session.add(product)
        try:
            db.session.commit()
            print('Product created')
        except Exception as e:
            print(e)
            

    elif properties.content_type == 'product-updated':
        product = Product.query.get(data['id'])
        product.title = data['title']
        product.title = data['image']
        try:
            db.session.commit()
        except Exception as e:
            print(e)
        print('Product updated')

    
    elif properties.content_type == 'product-deleted':
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()
        print('Product deleted')
Beispiel #3
0
def callback(ch, method, properties, body):
    print("Received in main")
    data = json.loads(body)
    print(data)

    if properties.content_type == 'product_created':
        product = Product(id=data['id'],
                          title=data['title'],
                          image=data['image'])
        db.session.add(product)
        db.session.commit()
        print('Product Created')

    elif properties.content_type == 'product_updated':
        product = Product.query.get(data['id'])
        product.title = data['title']
        product.image = data['image']
        db.session.commit()
        print('Product Updated')

    elif properties.content_type == 'product_deleted':
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()
        print('Product Deleted')
Beispiel #4
0
def callback(ch, method, properties, body):
    logging.info('Received in main')  # test
    data = json.loads(body)
    logging.info('Data Received: %s', data)  # test

    if properties.content_type == event_created:
        product = Product(id=data['id'],
                          title=data['title'],
                          image=data['image'])
        # creating the object with SQLAlchemy
        db.session.add(product)
        db.session.commit()
        logging.info('Product created')

    elif properties.content_type == event_updated:
        product = Product.query.get(data['id'])
        product.title = data['title']
        product.image = data['image']
        # updated the object with SQLAlchemy
        db.session.commit()
        logging.info('Product updated')

    elif properties.content_type == event_deleted:
        product = Product.query.get(data)
        # deleting the object in SQLAlchemy
        db.session.delete(product)
        db.session.commit()
        logging.info('Product deleted')
Beispiel #5
0
def callback(ch, method, properties, body):
    print("Recieved in main")
    data = json.loads(body)
    print(data)

    if properties.content_type == "product_created":
        product = Product(id=data["id"], title=data["title"], image=data["image"])
        db.session.add(product)
        db.session.commit()
        print("Product Created")
    elif properties.content_type == "product_updated":
        try:
            product = Product.query.get(data["id"])
            product.title = data["title"]
            product.image = data["image"]
            db.session.commit()
            print("Product Updated")
        except:
            abort(400, "No Product Exists")

    elif properties.content_type == "product_deleted":
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()
        print("Product Deleted")
    else:
        print("No properties.content.type chosen")
def callback(ch,method, properties,body):
    print('recieved in main')
    body = body.decode('utf-8').replace('\0', '')
    data = json.loads(body)
    print(data)

    if properties.content_type == 'product_created':
        product = Product(id=data['id'],title=data['title'],image=data['image'])
        db.session.add(product)
        db.session.commit()
        print('Product created')

    elif properties.content_type == 'product_updated':
        product = Product.query.get(data['id'])
        product.title = data['title']
        product.image = data['image']
        db.session.commit()
        print('Product updated')
    
    elif properties.content_type == 'product_deleted':
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()
        print('Product deleted')
    else:
        print('Product listed')
Beispiel #7
0
def callback(ch, method, properties, body):
    print("\nReceived from admin_2_web_mq")
    data = json.loads(body)

    if properties.content_type == "PRODUCT_CREATED":
        print("PRODUCT_CREATED")
        product = Product(
            id=data["id"],
            title=data["title"],
            image=data["image"]
        )
        if product is not None:
            db.session.add(product)
            db.session.commit()
        else:
            print("Sorry! Product cannot be created", data)

    if properties.content_type == "PRODUCT_UPDATED":
        print("PRODUCT_UPDATED")
        product = Product.query.get(data["id"])
        if product is not None:
            product.title = data["title"]
            product.image = data["image"]
            db.session.commit()
        else:
            print("Sorry! Product DoesNotExist", data["id"])

    if properties.content_type == "PRODUCT_DELETED":
        print("PRODUCT_DELETED")
        product = Product.query.get(data["id"])
        if product is not None:
            db.session.delete(product)
            db.session.commit()
        else:
            print("Sorry! Product DoesNotExist", data["id"])
Beispiel #8
0
def callback(ch, method, properties, body):
    print("Received in main")
    data = json.loads(body)
    print(data)

    try:
        if properties.content_type == "product_created":
            product = Product(
                id=data["id"], title=data["title"], image=data["image"])
            db.session.add(product)
            db.session.commit()
            print("Product Created Successfully")

        elif properties.content_type == "product_updated":
            product = Product.query.get(data["id"])
            product.title = data["title"]
            product.image = data["image"]
            db.session.commit()
            print("Product Updated Successfully")

        elif properties.content_type == "product_deleted":
            product = Product.query.get(data)
            db.session.delete(product)
            db.session.commit()
            print("Product Deleted Successfully")
    except Exception as e:
        print("Error while updating database :", e)
Beispiel #9
0
def callback(ch, method, properties, body):
    print('received main...')
    data = json.loads(body)
    #print(data)

    if properties.content_type == 'product_created':
        product = Product(product_id=data['id'],
                          title=data['title'],
                          image=data['image'])
        db.session.add(product)
        db.session.commit()
        print('product_created')

    elif properties.content_type == 'product_updated':
        product = Product.query.filter_by(product_id=data['id']).first()
        product.title = data['title']
        product.image = data['image']
        db.session.commit()
        print('product_updated')

    elif properties.content_type == 'product_deleted':
        print(data, 'deleted data')
        product = Product.query.filter_by(product_id=data).first()
        db.session.delete(product)
        db.session.commit()
        print('product_deleted')
Beispiel #10
0
def callback(ch, method, properties, body):
    print('Received in main')
    data = json.loads(body)
    print(data)

    if properties.content_type == 'product_created':
        product = Product(
            id=data['id'],
            sku=data['sku'],
            name=data['name'],
            price=data['price'],
            brand=data['brand'],
            image=data['image'],
            views=data['views']
        )
        db.session.add(product)
        db.session.commit()
        print('Product Created')

    elif properties.content_type == 'product_updated':
        product = Product.query.get(data['id'])
        product.sku = data['sku']
        product.name = data['name']
        product.price = data['price']
        product.brand = data['brand']
        product.image = data['image']
        product.views = data['views']
        db.session.commit()
        print('Product Updated')

    elif properties.content_type == 'product_deleted':
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()
        print('Product Deleted')
Beispiel #11
0
def callback(ch, method, properties, body):
    print("received in flask")
    data = json.loads(body)
    print(data)
    obj = Product(id=data["id"], title=data["title"], image=data["image"])
    db.session.add(obj)
    db.session.commit()
    print("done")
Beispiel #12
0
def callback(ch, method, properties, body):
    print("Recieve in main")
    data = json.loads(body)
    print(data)

    if properties.content_type == "product_created":
        product = Product(id=data["id"], image=data["image"], title=data["image"])
        db.session.add(product)
        db.session.commit()
    elif properties.content_type == "product_updated":
        product = Product.query.get(id=data["id"])
        product.title = data["title"]
        product.image = data["image"]
        db.session.commit()
    elif properties.content_type == "product_deleted":
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()
Beispiel #13
0
class Test_Product(unittest.TestCase):
    def setUp(self):
        self.product = Product()

    def test_setCost(self):
        self.assertEqual(self.product.setCost(),self.product.privat_cost)

    def test_getSales(self):
        self.assertEqual(self.product.getSales(900)

class Test_DataBase(unittest.TestCase):
    def setUp(self):
        self.database = DataBase()

    def test_id(self):
        self.assertEqual(self.database.id(),self.database.articl)

if __name__ == "__main__":
  unittest.main()
Beispiel #14
0
def callback(ch, method: str, properties: pika.BasicProperties, body):
    data = loads(body)

    content_type = properties.content_type.split("_", 1)[1]
    if content_type == "created":
        product = Product(id=data["id"],
                          title=data["title"],
                          image=data["image"])
        db.session.add(product)
        db.session.commit()
    elif content_type == "updated":
        product = Product.query.get(data["id"])
        product.title = data["title"]
        product.image = data["image"]
        db.session.commit()
    elif content_type == "deleted":
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()
    else:
        print("Wrong code")
        return
Beispiel #15
0
 def test_pack_order(self):
     p = Product("A", 3, 6, 9)
     self.assertDictEqual(
         p.pack_order(4), {
             'small_cardboard_box': 0,
             'medium_cardboard_box': 1,
             'large_cardboard_box': 0,
             'collect_cardboard_box': 0
         })
     self.assertDictEqual(
         p.pack_order(12), {
             'small_cardboard_box': 0,
             'medium_cardboard_box': 2,
             'large_cardboard_box': 0,
             'collect_cardboard_box': 1
         })
     self.assertDictEqual(
         p.pack_order(36), {
             'small_cardboard_box': 0,
             'medium_cardboard_box': 0,
             'large_cardboard_box': 4,
             'collect_cardboard_box': 2
         })
Beispiel #16
0
def callback(ch, method, properties, body):
    print(f'Receive in main: {body}')
    data = json.loads(body)
    print(data)

    if properties.content_type == 'product created':
        product = Product(id=data['id'], title=data['title'], image=data['image'])
        db.session.add(product)
        db.session.commit()
        print("Product created")

    elif properties.content_type == 'product updated':
        product = Product.query.get(data['id'])
        product.title = data['title']
        product.image = data['image']
        db.session.commit()
        print("Product updated")

    elif properties.content_type == 'product deleted':
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()
        print("Product deleted")
def callback(ch, method, properties, body):
    print('Receieved in client')
    data = json.loads(body)
    print(body, data)
    if properties.content_type == "product_created":
        product = Product(id=data['id'], title=data['title'], image=data['image'],
                          price=data['price'], discounted_price=data['discounted_price'])
        db.session.add(product)
        db.session.commit()
    elif properties.content_type == "product_updated":
        product = Product.query.get(data['id'])
        product.title = data['title']
        product.image = data['image']
        product.price = data['price']
        product.discounted_price = data['discounted_price']
        db.session.commit()
    elif properties.content_type == "product_deleted":
        product = Product.query.get(data)
        db.session.delete(product)
        db.session.commit()
Beispiel #18
0
 def setUp(self):
     self.product = Product()
Beispiel #19
0
from main import Product
#from main import Shop

productss = []
with open('products.txt') as f:  #all available products
    all_products = f.readlines()
    for line in all_products:
        line = line.replace('\n', '')
        productss.append(line)
print(productss)

for product in productss:
    answer = input('Do you want to buy this product? ')
    if answer == 'yes' or answer == 'Yes':
        prod = Product(product)
        print(prod.name)
        question = input('Do you want to see some info about it? ')
        if question == 'Yes' or question == 'yes':
            print('Here you can see some info:')
            print('Product name: ' + prod.name)
            print('The number of the pages: ' + prod.pages)
            print('Country: ' + prod.country)
            print('Price: ' + prod.price)
            print('The article number: ' + prod.article)
            print('The weight of the book: ' + prod.weight)
            print(' ')

    else:
        print(' ')
Beispiel #20
0
    pic = Picture(picturePath="fawegfawe" + str(i),
                  pictureColor=i,
                  productType=i)
    db.session.add(pic)

db.session.commit()

producttypes = ProductType.query.all()
print(producttypes)

# Create products
for i, pt in enumerate(producttypes):
    for o, color in enumerate(pt.color):
        for p, size in enumerate(pt.size):
            #print("P ÄR", p)
            product = Product(inStock=10, color=o, size=p, productType=i)
            db.session.add(product)

# NEWS
news = News(
    text=
    "Brand i LIU stores lokaler natten till trosdag, en utbytestudent står talad för mordbrand",
    header="LIU-store utsatt för mordbrand",
    picture="resources/images/asso.png",
    date="2020-04.03")
news1 = News(text="Kassa stulen av I:are, behövde pengar att vaska för",
             header="Kassastöld",
             picture="resources/images/asso.png",
             date="2020-04.03")
db.session.add(news)
db.session.add(news1)
Beispiel #21
0
from main import Product

#name, price, quantity

apple = Product("Apple", 112, 0.99, 245)
banana = Product("Banana", 143, 1.19, 188)
cherry = Product("Cherry", 115, 0.59, 768)
milk = Product("Milk", 426, 5.99, 837)
coffee = Product("Coffee", 981, 3.89, 230)
keyboard = Product("Keyboard", 776, 159.99, 21)
shirts = Product("Shirt", 451, 11.49, 999)
Beispiel #22
0
 def test_return_col_box(self):
     p = Product("A", 3, 6, 9)
     self.assertEqual(p.return_col_box(0, 1, 0), 0, "Should be 0 col_boxes")
     self.assertEqual(p.return_col_box(0, 2, 0), 1, "Should be 1 col_box")
     self.assertEqual(p.return_col_box(0, 1, 3), 2, "Should be 2 col_boxes")