Esempio n. 1
0
def test_ex2_list_v2_items_db_queries(client, django_assert_num_queries):
    ItemFactory.create_batch(10)

    # Two queries
    # COUNT
    # SELECT
    with django_assert_num_queries(2):
        response = client.get('/api/v2/inventory/items/')

    assert response.status_code == 200
def test_validate_xml_against_dtd():
    # DTD downloaded from http://img.cromet.fi/dtds/transferdata.dtd
    path_to_current_file = os.path.realpath(__file__)
    current_directory = os.path.dirname(path_to_current_file)
    dtd = etree.DTD(
        os.path.join(current_directory, "test_data", "transferdata.dtd"))
    items = ItemFactory.create_batch(2)

    assert dtd.validate(create_element_tree(items))
def main(num_manufacturers, num_items_per_man, num_orders):
    mans = ManufacturerFactory.create_batch(num_manufacturers)
    print(f"Created {num_manufacturers} Manufacturers")

    items = list(
        chain.from_iterable([
            ItemFactory.create_batch(num_items_per_man, manufacturer=man)
            for man in mans
        ]))
    print(f"Created {len(items)} Items")

    users = UserFactory.create_batch(50)
    for _ in range(0, num_orders):
        num_items = random.randint(5, 20)
        user = random.choice(users)
        OrderFactory.create(user=user, items=random.sample(items, num_items))
    print(f"Created {num_orders} Orders")