"""Functional tests of the HEAD /upc/ endpoint.""" from tests.factories.upc import UpcFactory from tests.testutils import db @db.test_schema def test_head_upc_not_found(client, test_upc): """Test that a 404 is returned if no product exists with the given UPC.""" upc_response = client.head('/upc/{}'.format(test_upc)) assert upc_response.status_code == 404 @db.test_schema def test_head_upc_found_upc(client, test_upc): """Test that a 200 is returned if a UPC exists with the given UPC.""" db.seed_models(UpcFactory.build(upc=test_upc)) upc_response = client.head('/upc/{}'.format(test_upc)) assert upc_response.status_code == 200 @db.test_schema def test_head_upc_found_product(client): """Test that a 200 is returned if a product exists with the given UPC.""" fixture_upc = 888831283041 db.insert_vw_product() upc_response = client.head('/upc/{}'.format(fixture_upc)) assert upc_response.status_code == 200 @db.test_schema def test_head_upc_leading_zeroes_in_upcs(client): """Test that leading zeroes are ignored when searching for a UPC. This case handles querying against the upcs table. """ fixture_upc = '0888831283041' db.insert_vw_product() upc_response = client.head('/upc/{}'.format(fixture_upc)) assert upc_response.status_code == 200 @db.test_schema def test_head_upc_leading_zeroes_in_product(client, test_upc): """Test taht leading zeroes are ignored when searching for a UPC. This case handles querying against the product view. """ db.seed_models(UpcFactory.build(upc=test_upc)) upc_response = client.head('/upc/0{}'.format(test_upc)) assert upc_response.status_code == 200