コード例 #1
0
 def test_session_save_overwrites(self, sample_color, sample_repair):
     order1 = Order.create(color=sample_color,
                           repairs=sample_repair,
                           problem_description="ABBBCCC")
     order2 = Order.create(color=sample_color,
                           repairs=sample_repair,
                           problem_description="ABBBCCC")
     order1.save_to_session()
     order2.save_to_session()
     assert Order.SESSION_KW in session.keys()
     assert Order.get_from_session() == order2
     assert Order.get_from_session() != order1
コード例 #2
0
 def test_repair_cant_occur_twice(self, sample_color, sample_shop, sample_repair):
     order = Order.create(color=sample_color, shop=sample_shop)
     try:
         order.repairs = [sample_repair, sample_repair]
         assert False
     except IntegrityError:
         return True
コード例 #3
0
def model(manufacturer_name, series_name, device_name):
    """ Returns the chosen device """
    _manufacturer: Manufacturer = Manufacturer.query.filter(
        Manufacturer.name == manufacturer_name).first()
    _series: DeviceSeries = DeviceSeries.query.filter(
        DeviceSeries.name == series_name).first()
    _device: Device = Device.query.filter(Device.name == device_name).first()
    if not _manufacturer or not _series or not _device:
        abort(404)

    repair_form = SelectRepairForm(_device)
    if repair_form.validate_on_submit():
        order = Order.create(
            color=repair_form.get_color(),
            repairs=repair_form.get_repairs(),
            problem_description=repair_form.problem_description.data,
        )
        order.save()
        order.save_to_session()
        return redirect(url_for('.register_customer'))

    return render_template("shop/modell.html",
                           device=_device,
                           repair_form=repair_form,
                           manufacturer=manufacturer_name,
                           series=series_name,
                           repair_names=[
                               f"{rep.device.name} {rep.name}"
                               for rep in _device.repairs
                           ])
コード例 #4
0
 def test_set_repairs(self, sample_color, sample_shop, sample_repair,
                      another_repair):
     order = Order.create(color=sample_color, shop=sample_shop)
     order.repairs = [sample_repair, another_repair]
     assert len(order.repairs) == 2
     assert order.repairs == [sample_repair, another_repair]
     assert order.repairs == order.get_repairs()
コード例 #5
0
 def remove_repair(self, sample_color, sample_shop, sample_repair, another_repair):
     order = Order.create(color=sample_color, shop=sample_shop)
     order.repairs = [sample_repair, another_repair]
     order.repairs -= [another_repair]
     assert len(order.repairs) == 1
     assert order.repairs == [sample_repair]
     assert order.repairs == order.get_repairs()
コード例 #6
0
 def test_get_device(self, sample_color, sample_repair):
     order1 = Order.create(
         color=sample_color,
         repairs=sample_repair,
         problem_description="ABBBCCC"
     )
     assert order1.device == sample_repair.device
コード例 #7
0
 def test_customer_relation(self, sample_color, sample_customer, sample_shop):
     order = Order.create(
         color=sample_color,
         shop=sample_shop,
         customer=sample_customer
     )
     assert order.customer == sample_customer
コード例 #8
0
    def test_delete(self, sample_repair, sample_color):
        order1 = Order.create(color=sample_color,
                              repairs=sample_repair,
                              problem_description="123")
        assert len(sample_repair.orders) == 1

        order1.delete()
        assert len(sample_repair.orders) == 0
コード例 #9
0
 def test_session_save(self, sample_color, sample_repair):
     order = Order.create(
         color=sample_color,
         repairs=sample_repair,
         problem_description="Some Text"
     )
     order.save_to_session()
     assert Order.SESSION_KW in session.keys()
コード例 #10
0
        def test_fields(shipping, kva, shop):
            form = FinalSubmitForm(shop=shop,
                                   shipping_label=shipping,
                                   kva_button=kva)
            assert form.validate()

            order = Order.create(color=sample_color)
            form.populate_order(order)
            assert order.shop == shop
            assert order.kva == kva
            assert order.customer_wishes_shipping_label == shipping
            order.save()
コード例 #11
0
 def test_most_selling(self, sample_repair, sample_color, another_repair):
     assert most_selling_repairs() == []
     Order.create(color=sample_color, repairs=[sample_repair])
     assert most_selling_repairs() == [sample_repair]
     Order.create(color=sample_color, repairs=[another_repair])
     Order.create(color=sample_color, repairs=[another_repair])
     assert most_selling_repairs() == [another_repair, sample_repair]
コード例 #12
0
 def test_get_bestsellers(self, sample_repair, another_repair, sample_color):
     assert get_bestsellers() == []
     Order.create(color=sample_color, repairs=[sample_repair])
     assert get_bestsellers() == [sample_repair.device]
     Order.create(color=sample_color, repairs=[another_repair])
     Order.create(color=sample_color, repairs=[another_repair])
     assert get_bestsellers() == [another_repair.device, sample_repair.device]
コード例 #13
0
    def test_cost(self, sample_color, sample_repair, sample_shop):
        another_repair = Repair.create(name="dfgdfgdfgdfg",
                                       price=49,
                                       device=sample_repair.device)
        dto = Order.create(color=sample_color,
                           shop=sample_shop,
                           repairs=[sample_repair, another_repair],
                           problem_description="Some Text")

        assert dto.total_cost_including_tax_and_discount == 108.2
        assert dto.total_cost == 118
        assert dto.taxes == 20.56
        assert dto.discount == 9.8
コード例 #14
0
    def test_deserialize(self, sample_color, sample_repair, sample_shop):
        another_repair = Repair.create(name="dfgdfgdfgdfg",
                                       price=69,
                                       device=sample_repair.device)
        dto = Order.create(color=sample_color,
                           shop=sample_shop,
                           problem_description="Some Text")
        dto.append_repairs(repairs=[sample_repair, another_repair])

        assert dto.color == sample_color
        assert dto.repairs == [sample_repair, another_repair]
        assert dto.problem_description == "Some Text"

        serialized = dto.serialize()
        assert serialized == {
            'order_id': dto.id,
        }

        deserialized = Order.deserialize(serialized)
        assert dto == deserialized
コード例 #15
0
def sample_order(db, sample_color, sample_repair):
    return Order.create(color=sample_color, repairs=sample_repair)
コード例 #16
0
 def test_customer_not_required(self, sample_color, sample_shop):
     order = Order.create(color=sample_color, shop=sample_shop)
     assert order.customer is None
コード例 #17
0
 def test_color_required(self, db):
     try:
         Order.create()
         assert False
     except IntegrityError:
         return True