Esempio n. 1
0
def test_Record_can_imitate_record_dict():
    mabd = MABD()
    record = mabd.get_record_from_table_by_id("people", "rec1BI0ZJlxZ0xUnI")

    assert record["id"] == "rec1BI0ZJlxZ0xUnI"
    assert record["fields"]["name"] == "Caroline"
    assert record["createdTime"] == "2020-05-23T17:06:03.000Z"
Esempio n. 2
0
def test_can_get_confirmed_offer_from_request():
    mabd = MABD()
    request = mabd.get_record_from_table_by_id("requests", "rec4hBg7aLIxYl3RO")
    assert request.get_confirmed_offerID() == "reche1z3Dtfexpa8n"

    request2 = mabd.get_record_from_table_by_id("requests", "rec1EqOYCFiqjfPFZ")
    assert request.get_confirmed_offerID() == None
Esempio n. 3
0
def get_readable_unfulfilled_requests_of_person(person_name: str) -> List[dict]:
    """consumes the name of a person and returns the list of all of that
person's requests, represented as dicts with readable values.

    """
    interface = MABD()
    return interface.get_readable_unfulfilled_requests_of_person(person_name)
Esempio n. 4
0
def test_can_get_readable_representation_of_matching_offers_by_requestID():
    mabd = MABD()
    requestID = "rect8dK5CN0kF4f5F"
    offer_dicts = mabd.get_readable_matching_offers_for_requestID(requestID)

    assert type(offer_dicts) is list
    assert len(offer_dicts) == 1
    assert offer_dicts[0]["item_name"] == "Four-seater Ikea sofa + footstool"
Esempio n. 5
0
def get_readable_confirmed_offer_for_requestID(request_id: str) -> Union[dict, bool]:
    """consumes the id of an open request and produces a readable
representation of the corresponding request's confirmed offer, represented as
dicts with readable values; or False, if there is no such offer.

    """
    interface = MABD()
    return interface.get_readable_confirmed_offer_for_requestID(request_id)
Esempio n. 6
0
def get_readable_matching_offers_for_requestID(request_id: str) -> List[dict]:
    """consumes the id of an open request and produces the list of all of
the corresponding request's matching offers, represented as dicts with
readable values.

    """
    interface = MABD()
    return interface.get_readable_matching_offers_for_requestID(request_id)
Esempio n. 7
0
def do_delivery_fulfilment(delivery_id: str) -> Union[Delivery, bool]:
    """consumes the value of the delivery_id column of a delivery and
produces the Delivery if this succeeds, and False otherwise. As a side-effect, processes
all of the requests and offers associated with the delivery.

    """
    interface = MABD()
    return interface.do_delivery_fulfilment(delivery_id)
Esempio n. 8
0
def get_pretty_unfulfilled_deliveries() -> List[str]:
    """consumes nothing and produces a list of all the unfulfilled
deliveries, represented as strings.

    """
    interface = MABD()
    deliveries = interface.get_unfulfilled_delivery_records()
    return [interface.get_pprinted_delivery(delivery) for delivery in deliveries]
Esempio n. 9
0
def get_name_of_requested_item_from_requestID(requestID: str) -> str:
    """consumes a requestID and produces the name of the corresponding
request.

    """
    interface = MABD()
    request = interface.get_record_from_table_by_id("requests", requestID)
    item_name = request.get_field("item")
    return item_name
Esempio n. 10
0
def do_offer_confirmation(request_id: str, offer_number: int) -> Union[Offer, bool]:
    """consumes a request_id and an offer number, and produces the
corresponding Request with the corresponding offer added to its
"rejected offers" attribute, if it was previously absent, or False if
this was not possible. As a side effect, produces the same effect on the airtable.

    """
    interface = MABD()
    return interface.request_id_do_offer_confirmation(request_id, offer_number)
Esempio n. 11
0
def test_Delivery_prints_itself_nicely(capsys):
    mabd = MABD()
    delivery = mabd.get_delivery_by_number(1)

    print(delivery)
    captured = capsys.readouterr()

    assert "Delivery with" in captured.out
    assert "fulfilled?: True" in captured.out
    assert "number: 1" in captured.out
Esempio n. 12
0
def test_get_generic_record_for_records_without_subclassed_datastructures():
    mabd = MABD()

    person1 = mabd.get_record_from_table_by_id("people", "rec1BI0ZJlxZ0xUnI")
    assert type(person1) is Record

    driver1 = mabd.get_record_from_table_by_id("drivers", "rec0UsfN8i2IYAtZC")
    assert type(driver1) is Record

    status1 = mabd.get_record_from_table_by_id("statuses", "rec370ei78Jt6y7w6")
    assert type(status1) is Record
Esempio n. 13
0
def test_can_do_delivery_fulfilment(monkeypatch, mock_get_airtable):
    interface = MABD()

    before_fulfilment = interface.get_delivery_by_number(2)
    before_fulfilment_columns = before_fulfilment.get_columns()
    assert "fulfilled?" not in before_fulfilment_columns

    fulfilment = api.do_delivery_fulfilment(2)
    assert type(fulfilment) is Delivery
    fulfilment_columns = fulfilment.get_columns()
    assert "fulfilled?" in fulfilment_columns
    assert fulfilment.get_field("fulfilled?") is True
Esempio n. 14
0
def test_can_get_minimal_representation_from_record():
    mabd = MABD()

    record = mabd.get_record_from_table_by_id("requests", "rec1EqOYCFiqjfPFZ")

    minimal_representation = mabd.request_get_minimal_representation(record)

    for key in ["item", "requested_by"]:
        assert key in minimal_representation.keys()

    assert minimal_representation["item"] == "Chest of drawers"
    assert minimal_representation["requested_by"] == "Ayoub"
Esempio n. 15
0
def test_can_get_unfulfilled_requests_for_person():
    mabd = MABD()
    requester = "Lubna"
    requests = mabd.get_unfulfilled_requests_of_person(requester)

    request_items = [request.get_field("item") for request in requests]

    assert "Sofa" in request_items
    assert "Wardrobe" in request_items

    assert "TV" not in request_items
    assert "Coffee table" not in request_items
Esempio n. 16
0
def get_readable_unfulfilled_deliveries() -> List[dict]:
    """consumes nothing and produces a list of all the unfulfilled
deliveries, represented as a minimal dict with the keys `id`, `to`,
`from`, `driver`, and `date`.

    """
    interface = MABD()
    unfulfilled_deliveries = interface.get_unfulfilled_delivery_records()
    minimal_representations = [
        interface.delivery_get_minimal_representation(delivery)
        for delivery in unfulfilled_deliveries
    ]
    return minimal_representations
Esempio n. 17
0
def test_can_get_person_record_by_name():
    mabd = MABD()
    person_name = "Lubna"
    person_record = mabd.get_person_by_person_name(person_name)

    assert person_record is not False
    assert type(person_record) is Record

    assert person_record.get_id() == "rec95fxPGFAmWsi0I"

    person_name = "No-one"
    person_record = mabd.get_person_by_person_name(person_name)

    assert person_record is False
Esempio n. 18
0
def test_delivery_get_all_requestIDs_can_handle_deliveries_without_requests():
    mabd = MABD()

    delivery2 = mabd.get_delivery_by_number(2)
    requestIDs = delivery2.get_all_requestIDs()

    assert len(requestIDs) == 2

    delivery2_without_requests = mabd.update_delivery(
        delivery2.get_id(), {"requests": []}
    )

    requestIDs = delivery2_without_requests.get_all_requestIDs()

    assert requestIDs == []
Esempio n. 19
0
def test_can_get_record_from_table_by_id():
    mabd = MABD()
    record_id0 = "rec1EqOYCFiqjfPFZ"
    request = mabd.get_record_from_table_by_id("requests", record_id0)

    assert type(request) is Request
    assert request.get_id() == record_id0

    record_id1 = "recEwRhLHhsKIdKc4"
    offer = mabd.get_record_from_table_by_id("offers", record_id1)

    assert type(offer) is Offer
    assert offer.get_id() == record_id1

    record_id2 = "recyRmCERIeiniXaJ"
    delivery = mabd.get_record_from_table_by_id("deliveries", record_id2)

    assert type(delivery) is Delivery
    assert delivery.get_id() == record_id2
Esempio n. 20
0
def test_can_update_delivery_by_id():
    mabd = MABD()
    delivery_id = "recNoBUi8dqEwovSK"

    delivery = mabd.get_record_from_table_by_id("deliveries", delivery_id)

    assert delivery.get_fulfilment() == False
    assert mabd.get_delivery_by_number(3).get_fulfilment() == False

    update_dict = {"fulfilled?": True}

    updated_delivery = mabd.update_delivery(delivery_id, update_dict)

    assert updated_delivery.get_fulfilment() == True
    assert mabd.get_delivery_by_number(3).get_fulfilment() == True
Esempio n. 21
0
def test_MABD_do_delivery_fulfilment_returns_false_if_delivery_does_not_exist():
    mabd = MABD()
    result = mabd.do_delivery_fulfilment(3002)
    assert result == False
Esempio n. 22
0
def test_can_get_all_requestIDs_fulfilled_by_delivery():
    mabd = MABD()
    deliveries = mabd.get_airtable("deliveries")
    first_delivery = mabd.get_delivery_by_number(1)
    returned_requests = first_delivery.get_all_requestIDs()
    assert len(returned_requests) == 3
Esempio n. 23
0
def test_can_get_matching_offers_from_request():
    mabd = MABD()
    request = mabd.get_record_from_table_by_id("requests", "recHE4q1ZkuXpUcde")
    assert request.get_matching_offerIDs() == ["recbuFMiAi5wNCswt"]
Esempio n. 24
0
def get_readable_offer_by_offer_number(offer_number: int) -> dict:
    """ consumes an offer-uid and produces the corresponding offer, 
represented as a readable dict.
"""
    interface = MABD()
    return interface.get_readable_offer_by_offer_number(offer_number)
Esempio n. 25
0
def test_getting_non_existent_record_from_table_returns_None():
    mabd = MABD()

    no_record = mabd.get_record_from_table_by_id("requests", "blahhhh")
    assert no_record is None