Beispiel #1
0
def test_prefers_current_stock_batches_to_shipments():
    in_stock_batch = Batch("in-stock-batch", "RETRO-CLOCK", 100, eta=None)
    shipment_batch = Batch("shipment-batch", "RETRO-CLOCK", 100, eta=tomorrow)
    line = OrderLine("oref", "RETRO-CLOCK", 10)
    allocate(line, [in_stock_batch, shipment_batch])
    assert in_stock_batch.available_quantity == 90
    assert shipment_batch.available_quantity == 100
Beispiel #2
0
def test_allocate_prefers_warehouse():
    batch_warehouse = Batch(sku="SMALL-TABLE", qty=20)
    batch_shipping = Batch(sku="SMALL-TABLE", qty=20, eta=10)
    order_line = OrderLine(ref="bla", sku="SMALL-TABLE", qty=20)
    allocate(order_line, [batch_shipping, batch_warehouse])

    assert batch_warehouse.qty == 0
    assert batch_shipping.qty == 20
Beispiel #3
0
def test_prefers_earlier_batches():
    earliest = Batch('speedy-batch', 'MINIMALIST-SPOON', 100, eta=today)
    medium = Batch("normal-batch", 'MINIMALIST-SPOON', 100, eta=tomorrow)
    latest = Batch("slow-batch", "MINIMALIST-SPOON", 100, eta=later)
    line = OrderLine("order1", "MINIMALIST-SPOON", 10)
    allocate(line, [medium, earliest, latest])
    assert earliest.available_quantity == 90
    assert medium.available_quantity == 100
    assert latest.available_quantity == 100
def test_allocating_in_stock_over_shipment():
    in_stock_batch = Batch('in-stock-batch', 'CLOCK', 100, eta=None)
    shipment_batch = Batch("shipment-batch", "CLOCK", 100, eta=tomorrow)
    line = OrderLine("oref", "CLOCK", 10)

    allocate(line, [in_stock_batch, shipment_batch])

    assert in_stock_batch.available_quantity == 90
    assert shipment_batch.available_quantity == 100
Beispiel #5
0
def test_allocate_quickest_warehouse():
    batch_warehouse_slow = Batch(sku="SMALL-TABLE", qty=20, eta=10)
    batch_shipping_unavaiable = Batch(sku="SMALL-TABLE", qty=2, eta=1)
    batch_shipping_ok = Batch(sku="SMALL-TABLE", qty=20, eta=5)
    order_line = OrderLine(ref="bla", sku="SMALL-TABLE", qty=20)
    allocate(
        order_line, [batch_warehouse_slow, batch_shipping_unavaiable, batch_shipping_ok]
    )
    assert batch_warehouse_slow.qty == 20
    assert batch_shipping_unavaiable.qty == 2
    assert batch_shipping_ok.qty == 0
Beispiel #6
0
def test_returns_allocated_batch_ref():
    in_stock_batch = Batch("in-stock-batch-ref",
                           "HIGHBROW-POSTER",
                           100,
                           eta=None)
    shipment_batch = Batch("shipment-batch-ref",
                           "HIGHBROW-POSTER",
                           100,
                           eta=tomorrow)
    line = OrderLine("oref", "HIGHBROW-POSTER", 10)
    allocation = allocate(line, [in_stock_batch, shipment_batch])
    assert allocation == in_stock_batch.reference
def test_allocating_to_batch_reduces_availability():
    batch = Batch("batch-001",
                  "SMALL-TABLE",
                  qty=20,
                  eta=datetime.date.today())
    line = OrderLine('order-ref', "SMALL-TABLE", 2)
    batch.allocate(line)
    assert batch.available_quantity == 18
Beispiel #8
0
def get_posts():
    batch = Batch()
    db_session.add(batch)
    db_session.commit()

    s = requests.Session()
    s.headers.update({'Accept-Language': 'sv', 'Accept': 'application/json'})

    for county in County.query.all():
        app.logger.info('Getting posts for %s' % county)
        _get_posts(s, batch, county.id, 10000, 1)
    batch.end_time = datetime.now()
    batch.complete = True
    batch.last_in = db_session.query(func.max(Post.external_id)).scalar()
    db_session.add(batch)
    db_session.commit()
Beispiel #9
0
def main():
    today = strftime('%Y%m%d')
    batch_name = 'Median_Home_Values_Data_%s.csv' % today

    # Mark all current jobs_data batches inactive
    db_session.query(Batch).filter_by(datasource_id=5).update(
        {'is_active': False})
    batch = Batch(datasource_id=5, name=batch_name, is_active=True)
    db_session.add(batch)
    db_session.flush()
    db_session.commit()

    cities = db_session.query(City).order_by(City.code)
    for city in cities:
        print "city: %s" % city.code
        data = get_home_values(city.code)
        push_to_hadoop(data, batch_name)
        push_to_sql(data, city.code, batch.batch_id)
Beispiel #10
0
def main():
    today = strftime('%Y%m%d')
    batch_name = 'Jobs_Data_%s.csv' % today

    # Mark all current jobs_data batches inactive
    db_session.query(Batch).filter_by(datasource_id=6).update(
        {'is_active': False})
    batch = Batch(datasource_id=6, name=batch_name, is_active=True)
    db_session.add(batch)
    db_session.flush()
    db_session.commit()

    categories = range(1, 34)
    for c in categories:
        print "processing category %s" % c
        data = get_job_stats(c)
        push_to_hadoop(data, batch_name, c)
        push_to_sql(data['response']['cities'], batch.batch_id, c)

    db_session.close()
Beispiel #11
0
def batch(product):
    return Batch('ref-0001', product, 20, eta=date.today())
Beispiel #12
0
def test_allocation():
    batch = Batch(sku="SMALL-TABLE", qty=20)
    order_line = OrderLine(sku="SMALL-TABLE", qty=2, ref="some order")
    allocate(order_line, batch)
    assert batch.qty == 18
Beispiel #13
0
def test_cant_allocate_twice():
    batch = Batch(sku="SMALL-TABLE", qty=20)
    order_line = OrderLine(ref="some orderline", sku="SMALL-TABLE", qty=2)
    allocate(order_line, batch)
    allocate(order_line, batch)
    assert batch.qty == 18
Beispiel #14
0
def test_allocation_not_enough():
    batch = Batch(sku="BLUE-CUSHION", qty=1)
    order_line = OrderLine(sku="BLUE-CUSHION", qty=2, ref="some order")
    allocate(order_line, batch)
    assert batch.qty == 1
Beispiel #15
0
def test_raises_out_of_stock_exception_if_cannot_allocate():
    batch = Batch('batch1', 'SMALL-FORK', 10, eta=today)
    allocate(OrderLine('order1', 'SMALL-FORK', 10), [batch])
    with pytest.raises(OutOfStock, match='SMALL-FORK'):
        allocate(OrderLine('order2', 'SMALL-FORK', 1), [batch])
Beispiel #16
0
def make_batch_and_line(sku,batch_qty,line_qty):
    return (
        Batch("batch-001",sku,batch_qty,eta=date.today()),
        OrderLine("order-123",sku,line_qty)
    )
Beispiel #17
0
def test_cannot_allocate_if_skus_do_not_match():
    batch=Batch("batch-001","UNCONFORTABLE-CHARE",100,eta=None)
    different_sku_line=OrderLine("order-123","EXPENIVE-TOASTER",10)
    assert batch.can_allocate(different_sku_line) is False
def test_matching_in_allocation():
    batch = Batch('Batch-03', 'Nails', qty=50, eta=datetime.date.today())
    line = OrderLine('R-32', 'Wood', qty=3)
    batch.can_allocate(line) is False