def test_brand_controller(mocker, login_disabled_app, request_json, brands_response_json, kinds_response_json, pricerange_response_json): with mocker.patch.object(ProductService, "get_total", return_value=10): with mocker.patch.object(ProductService, "select_brands", return_value=brands_response_json): with mocker.patch.object(ProductService, "select_kinds", return_value=kinds_response_json): with mocker.patch.object( ProductService, "select_pricerange", return_value=pricerange_response_json): with login_disabled_app.test_client() as client: response = client.post("api/brand/test") data = json.loads(response.data) SearchResultsSchema().load(data) assert response.status_code == 200 assert data["total"] == 10 assert data["pricerange"] == pricerange_response_json with login_disabled_app.test_client() as client: response = client.post("api/brand/test", json=request_json) data = json.loads(response.data) SearchResultsSchema().load(data) assert response.status_code == 200 assert data["total"] == 10 assert data["pricerange"] == pricerange_response_json
def test_search(domain_url, es_object, token_session): query = str(uuid4()) prod_list = [ ProductFactory.create(name=query), ProductFactory.create(gender=query), ProductFactory.create(kind=query), ProductFactory.create(brand=query) ] [prod_obj.save(using=es_object.connection) for prod_obj in prod_list] Index("store", using=es_object.connection).refresh() response = token_session.post( domain_url + "/api/search/%s" % query ) data = response.json() SearchResultsSchema().load(data) assert response.status_code == 200 assert data["total"] == 4 response = token_session.post( domain_url + "/api/search/%s" % query, json={ "pricerange": { "min": 1, "max": 500 } } ) data = response.json() SearchResultsSchema().load(data) assert response.status_code == 200 assert data["total"] == 4 response = token_session.post( domain_url + "/api/search/%s" % query, json={ "pricerange": { "min": 10000, "max": 20000 } } ) with pytest.raises(JSONDecodeError): response.json() assert response.status_code == 204 response = token_session.post( domain_url + "/api/search/%s" % str(uuid4()) ) with pytest.raises(JSONDecodeError): response.json() assert response.status_code == 204
def test_brand_controller(token_app, es_object): brand = str(uuid4()) prod_list = ProductFactory.create_batch(2, brand=brand) [prod_obj.save(using=es_object.connection) for prod_obj in prod_list] Index("store", using=es_object.connection).refresh() with token_app.test_client() as client: response = client.post( "api/brand/%s" % brand ) data = json.loads(response.data) SearchResultsSchema().load(data) assert response.status_code == 200 assert data["total"] == 2 with token_app.test_client() as client: response = client.post( "api/brand/%s" % brand, json={ "pricerange": { "min": 1, "max": 500 } } ) data = json.loads(response.data) SearchResultsSchema().load(data) assert response.status_code == 200 assert data["total"] == 2 with token_app.test_client() as client: response = client.post( "api/brand/%s" % brand, json={ "pricerange": { "min": 10000, "max": 20000 } } ) with pytest.raises(JSONDecodeError): json.loads(response.data) assert response.status_code == 204 with token_app.test_client() as client: response = client.post( "api/brand/%s" % str(uuid4()) ) with pytest.raises(JSONDecodeError): json.loads(response.data) assert response.status_code == 204
def test_search_controller(token_app, es_object): query = str(uuid4()) prod_list = [ ProductFactory.create(name=query), ProductFactory.create(gender=query), ProductFactory.create(kind=query), ProductFactory.create(brand=query) ] [prod_obj.save(using=es_object.connection) for prod_obj in prod_list] Index("store", using=es_object.connection).refresh() with token_app.test_client() as client: response = client.post("api/search/%s" % query) data = json.loads(response.data) SearchResultsSchema().load(data) assert response.status_code == 200 assert data["total"] == 4 with token_app.test_client() as client: response = client.post("api/search/%s" % query, json={"pricerange": { "min": 1, "max": 500 }}) data = json.loads(response.data) SearchResultsSchema().load(data) assert response.status_code == 200 assert data["total"] == 4 with token_app.test_client() as client: response = client.post( "api/search/%s" % query, json={"pricerange": { "min": 10000, "max": 20000 }}) with pytest.raises(JSONDecodeError): json.loads(response.data) assert response.status_code == 204 with token_app.test_client() as client: response = client.post("api/search/%s" % str(uuid4())) with pytest.raises(JSONDecodeError): json.loads(response.data) assert response.status_code == 204
def test_kind(domain_url, es_object, token_session): kind = str(uuid4()) prod_list = ProductFactory.create_batch(2, kind=kind) [prod_obj.save(using=es_object.connection) for prod_obj in prod_list] Index("store", using=es_object.connection).refresh() response = token_session.post(domain_url + "/api/kind/%s" % kind) data = response.json() SearchResultsSchema().load(data) assert response.status_code == 200 assert data["total"] == 2 response = token_session.post(domain_url + "/api/kind/%s" % kind, json={"pricerange": { "min": 1, "max": 500 }}) data = response.json() SearchResultsSchema().load(data) assert response.status_code == 200 assert data["total"] == 2 response = token_session.post( domain_url + "/api/kind/%s" % kind, json={"pricerange": { "min": 10000, "max": 20000 }}) with pytest.raises(JSONDecodeError): response.json() assert response.status_code == 204 response = token_session.post(domain_url + "/api/kind/%s" % str(uuid4())) with pytest.raises(JSONDecodeError): response.json() assert response.status_code == 204