Exemplo n.º 1
0
def test_receipt() -> None:
    items: List[IItem] = [
        Item("Milk"), Item("Lemonade"),
        OrdinaryPack(7, "Beer")
    ]
    receipt = Receipt(items)
    assert items == receipt.get_items()
Exemplo n.º 2
0
def test_discount(db: IStoreDatabase) -> None:
    discount = ((Item("Sour Milk"), ), 0.1)
    db.add_discount(discount)
    assert discount[0] in db.get_discounts()
    assert db.get_discounts()[discount[0]] == discount[1]
    discount1: Tuple[Tuple[IItem, ...], float] = (
        (Item("Sour Milk"), OrdinaryPack(5, "Beer")),
        0.2,
    )
    db.add_discount(discount1)
    assert discount1[0] in db.get_discounts()
    assert db.get_discounts()[discount1[0]] == discount1[1]
Exemplo n.º 3
0
    def test_saving_item_and_retrieving_it(self):
        item = Item(id=0, content="hello world")
        item.save(self.cursor)
        self.cursor.execute("SELECT * FROM items")
        # retrieve item back from database
        raw = self.cursor.fetchone()
        retrieved_item = Item.from_tuple(raw)

        # check that it is the one we saved
        self.assertEqual(retrieved_item.id, item.id)
        self.assertEqual(retrieved_item.content, item.content)
        self.assertEqual(retrieved_item.date_created, item.date_created)
Exemplo n.º 4
0
def test_sold_item(db: IStoreDatabase) -> None:
    item = Item("Sour Milk")
    db.add_sold_item(item)
    assert item in db.get_sold_items()
    assert db.get_sold_items()[item] == 1
    item1 = Item("Sour Milk")
    assert item1 in db.get_sold_items()
    db.add_sold_item(item1)
    assert db.get_sold_items()[item] == 2
    pack = OrdinaryPack(5, "Cigarette")
    db.add_sold_item(pack)
    assert pack in db.get_sold_items()
    assert db.get_sold_items()[pack] == 1
Exemplo n.º 5
0
def test_make_receipt(actor_factory: DefaultActorFactory) -> None:
    cashier = actor_factory.create_cashier()
    cashier.open_receipt(receipt_builder=ReceiptBuilder())
    items: List[IItem] = [
        Item("Milk"), Item("Lemonade"),
        OrdinaryPack(7, "Beer")
    ]
    for item in items:
        cashier.add_item_to_receipt(item)
    receipt = cashier.give_receipt()
    for item in receipt:
        items.remove(item)
    assert len(items) == 0
Exemplo n.º 6
0
def test_receipt_calculate_price() -> None:
    items: List[IItem] = [
        Item("Milk"), Item("Lemonade"),
        OrdinaryPack(7, "Beer")
    ]
    receipt = Receipt(items)
    catalogue = {
        Item("Milk"): 3.00,
        Item("Lemonade"): 2.00,
        OrdinaryPack(2, "Beer"): 1.00,
    }
    price = receipt.calculate_price(catalogue, {})
    assert price == 12.00
Exemplo n.º 7
0
    def test_equality(self):
        list_equal1 = List()
        list_equal2 = List()
        list_unequal = List()

        for n in range(10):
            time = datetime.now()
            list_equal1.add(Item(id=n, content="equal", date_created=time))
            list_equal2.add(Item(id=n, content="equal", date_created=time))
            list_unequal.add(Item(id=n, content="not equal", date_created=time))

        self.assertEqual(list_equal1, list_equal2)
        self.assertNotEqual(list_equal1, list_unequal)
        self.assertNotEqual(list_equal2, list_unequal)
Exemplo n.º 8
0
def test_make_x_report(actor_factory: DefaultActorFactory) -> None:
    manager = actor_factory.create_manager()
    sold_items = {
        Item("Milk"): 4,
        Item("Lemonade"): 3,
        OrdinaryPack(2, "Beer"): 2,
    }
    x_report = manager.make_X_report(sold_items.copy(), 15.0)
    for item in x_report:
        assert item[0] in sold_items
        assert item[1] == sold_items[item[0]]
        sold_items.pop(item[0])

    assert len(sold_items) == 0
    assert x_report.calculate_price() == 15.0
Exemplo n.º 9
0
def test_receive_receipt(actor_factory: DefaultActorFactory) -> None:
    cashier = actor_factory.create_cashier()
    cashier.open_receipt(receipt_builder=ReceiptBuilder())
    items: List[IItem] = [
        Item("Milk"), Item("Lemonade"),
        OrdinaryPack(7, "Beer")
    ]
    customer = Customer(items.copy(), cashier, [""])
    for item in customer.show_items():
        cashier.add_item_to_receipt(item)
    customer.receive_receipt()
    receipt = customer.show_receipt()
    for item in receipt:
        items.remove(item)
    assert len(items) == 0
Exemplo n.º 10
0
def add_item_post():
    form = AddItemForm()
    name = form.name.data
    category = request.form["category"]
    description = form.description.data
    country = form.country.data
    min_price = int(form.min_price.data)
    date = request.form["end_day"]
    end_y = date[0:4]
    end_m = date[5:7]
    end_d = date[8:10]
    time = request.form["time"]
    end_h = time[0:2]
    end_min = time[3:5]
    user_id = current_user.id
    auction_image = save_image(form.auction_image.data)
    new_item = Item(name=name,
                    category_id=category,
                    description=description,
                    country=country,
                    min_price=min_price,
                    auction_image=auction_image,
                    end_day=datetime(int(end_y), int(end_m), int(end_d),
                                     int(end_h), int(end_min)),
                    time=time,
                    user_id=user_id)
    if datetime(int(end_y), int(end_m), int(end_d),
                int(end_h)) < datetime.now():
        flash('You entered wrong date!', 'info')
        return redirect(url_for('add_item'))
    else:
        db.session.add(new_item)
        db.session.commit()
        flash('Item post created!', 'success')
    return redirect(url_for('home'))
Exemplo n.º 11
0
 def _syringe(image_size):
     '''Initialize and return the syringe item.'''
     crafts = const.CRAFTS.copy()
     image = PgImage.load(crafts["syringe"]["image_file"], image_size)
     crafts["syringe"].pop("image_file")
     crafts["syringe"].update({"image": image})
     return Item(crafts["syringe"])
Exemplo n.º 12
0
def test_item(db: IStoreDatabase) -> None:
    item = Item("Sour Milk")
    item_with_price = (item, 1.5)
    db.add_item(item_with_price)
    assert item in db.get_items()
    assert db.get_items()[item] == 1.5
    pack = OrdinaryPack(5, "Cigarette")
    pack_with_price = (pack, 1.0)
    db.add_item(pack_with_price)
    assert pack in db.get_items()
    assert db.get_items()[pack] == 1.0
Exemplo n.º 13
0
    def test_deleting_item(self):
        item = Item(id=0, content="hello world")
        item.save(self.cursor)

        item.delete(self.cursor)
        self.cursor.execute("SELECT * FROM items")
        raw_deleted = self.cursor.fetchone()
        self.assertIsNone(raw_deleted)
Exemplo n.º 14
0
    def test_checking_item(self):
        item = Item(id=0, content="hello world")

        # ensure the item is unchecked
        item.checked = False

        item.save(self.cursor)
        self.cursor.execute("SELECT * FROM items")
        raw_unchecked = self.cursor.fetchone()
        # now check the item and retrieve it again
        item.check(self.cursor)
        self.cursor.execute("SELECT * FROM items")
        raw_checked = self.cursor.fetchone()

        item_unchecked = Item.from_tuple(raw_unchecked)
        item_checked = Item.from_tuple(raw_checked)

        self.assertFalse(item_unchecked.checked)
        self.assertTrue(item_checked.checked)
        self.assertNotEqual(item_unchecked.checked, item_checked.checked)
Exemplo n.º 15
0
    def test_saving_list_and_retrieving_it(self):
        list = List()

        for n in range(10):
            list.add(Item(id=n, content="hello world"))

        self.assertEqual(len(list), 10)

        for item in list:
            item.save(self.cursor)

        list_retrieved = List.get_all(self.cursor)

        self.assertEqual(len(list_retrieved), 10)
        self.assertEqual(list, list_retrieved)
    def add_item(self, item_name):

        if item_name is None or len(item_name) < 1:
            return "Item must have a name"

        if not isinstance(item_name, str):
            return "Item name must be a string"

        for item in self.items:
            if item.name == item_name:
                return item_name + ' already Exist'

        new_item = Item(item_name)
        self.items.append(new_item)

        return new_item.id
Exemplo n.º 17
0
def create_items():
    for i in range(count):
        name = faker.word()
        description = faker.sentence()
        country = faker.country()
        min_price = int(faker.random_int(20, 500))
        end_y = 2020
        end_m = 4
        end_d = 20
        time = faker.random_int(20, 500)
        user_id = faker.random_int(1, 4)
        auction_image = "default.jpg"
        category_id = faker.random_int(1, 8)

        new_item = Item(name=name, category_id=category_id, description=description, country=country, min_price=min_price, auction_image=auction_image, end_day=datetime(int(end_y), int(end_m), int(end_d)), time=time, user_id=user_id)
        db.session.add(new_item)
        db.session.commit()
Exemplo n.º 18
0
    def _drop(self, image_size):
        '''

        Drop the items on random free paths.

        This method initializes the items and the free paths list and updates
        the materials and free paths list.
        '''
        materials = const.MATERIALS.copy()
        for material in materials:
            location = random.choice(self.free_paths)
            image = PgImage.load(materials[material]["image_file"], image_size)
            materials[material].pop("image_file")
            kwargs = {"position": location, "image": image}
            materials[material].update(kwargs)
            item = Item(materials[material])
            self.materials.append(item)
            self.free_paths.remove(location)
Exemplo n.º 19
0
    def __init_database(self) -> IStoreDatabase:
        database = StoreDatabase()
        items = {
            Item("Milk"): 4.99,
            Item("Mineral Water"): 3.00,
            Item("Bread"): 0.80,
            Item("Diapers"): 1.39,
            OrdinaryPack(6, "Beer"): 1.00,
            Item("Cheese"): 4.00,
            OrdinaryPack(10, "Tissues"): 1.50,
        }
        discounts = {
            (OrdinaryPack(10, "Tissues"), ): 0.1,
            (Item("Bread"), Item("Cheese")): 0.05,
            (Item("Mineral Water"), ): 0.5,
        }
        for item in items.items():
            database.add_item(item)

        for discount in discounts.items():
            database.add_discount(discount)

        return database
Exemplo n.º 20
0
def test_receipt_calculate_price_with_discount() -> None:
    items: List[IItem] = [
        Item("Milk"), Item("Lemonade"),
        OrdinaryPack(7, "Beer")
    ]
    receipt = Receipt(items)
    catalogue = {
        Item("Milk"): 3.00,
        Item("Lemonade"): 2.00,
        OrdinaryPack(2, "Beer"): 1.00,
    }
    discounts = {
        (Item("Milk"), ): 1,
        (Item("Lemonade"), OrdinaryPack(7, "Beer")): 0.5,
    }
    price = receipt.calculate_price(catalogue, discounts)
    assert price == (3 * 0 + 2.00 * 0.5 + 7 * 1 * 0.5)
Exemplo n.º 21
0
from mongoengine import connect
connect("comprank")
from app.topic import Topic
from app.comparison import Comparison
from app.item import Item
from app.category import Category

import csv

with open('data/tuxc.tsv') as names:
    reader = csv.DictReader(names, dialect='excel-tab')
    for row in reader:
        first = row['first']
        last = row['last']
        name = first + ' ' + last
        p = Item(name=name, description='XC Student Athlete', format='text')
        p.save()
Exemplo n.º 22
0
def test_create_customer(actor_factory: DefaultActorFactory) -> None:
    cashier = actor_factory.create_cashier()
    items = [Item("Milk"), Item("Lemonade"), OrdinaryPack(5, "Beer")]
    customer = actor_factory.create_customer(cashier, items)
    assert customer is not None
    assert isinstance(cashier, Cashier)
Exemplo n.º 23
0
def test_show_items(actor_factory: DefaultActorFactory) -> None:
    cashier = actor_factory.create_cashier()
    items = [Item("Milk"), Item("Lemonade"), OrdinaryPack(7, "Beer")]
    customer = actor_factory.create_customer(cashier, items)
    assert set(customer.show_items()).issubset(items)
Exemplo n.º 24
0
def test_item_count() -> None:
    item = Item("Beer")
    assert item.get_count() == 1
Exemplo n.º 25
0
def test_item_price() -> None:
    item = Item("Beer")
    catalogue = {Item("Beer"): 1.00}
    assert item.calculate_price(catalogue, {}) == 1.00
Exemplo n.º 26
0
def test_item_price_with_discount() -> None:
    item = Item("Beer")
    catalogue = {Item("Beer"): 1.00}
    discounts = {(Item("Beer"), ): 0.5}
    assert item.calculate_price(catalogue, discounts) == 0.5
Exemplo n.º 27
0
 def setUp(self):
     self.my_item = Item('milk', 5, 'Quality supermarket')
Exemplo n.º 28
0
def test_item_name() -> None:
    item = Item("Beer")
    assert item.get_name() == "Beer"