def test_app_with_data(): tmpdir = tempfile.mkdtemp() for filename in os.listdir("tests/data"): shutil.copy(os.path.join("tests/data", filename), tmpdir) write_app = app.create_app(DATA_DIR=tmpdir) yield write_app shutil.rmtree(tmpdir, ignore_errors=True)
def test_set_new_default_feature_weights(client_with_data): resp = client_with_data.put("/datasets/feature_weights/default", json=NEW_DEFAULT_ID) assert resp.status_code == 200 assert resp.json["msg"] == "Successfully set default feature weight id." assert (client_with_data.get("/datasets/feature_weights/default") ).json == NEW_DEFAULT_ID second_app = app.create_app( DATA_DIR=client_with_data.application.config["DATA_DIR"]) second_app.config["TESTING"] = True second_client = second_app.test_client() assert (second_client.get("/datasets/feature_weights/default") ).json == NEW_DEFAULT_ID
def test_set_book_new_default_feature_weights(client_with_data): resp = client_with_data.put( f"/datasets/books/{BOOK_VUID}/feature_weights_id", json=NEW_DEFAULT_ID) assert resp.status_code == 200 assert resp.json[ "msg"] == "Successfully set the book's default feature weight id." # assert (client_with_data.get(f"/datasets/books/{BOOK_VUID}/feature_weights_id")).json == DEFAULT_ID assert resp.json["feature_weight_set_id"] == NEW_DEFAULT_ID second_app = app.create_app( DATA_DIR=client_with_data.application.config["DATA_DIR"]) second_app.config["TESTING"] = True second_client = second_app.test_client() # assert (second_client.get(f"/datasets/books/{BOOK_VUID}/feature_weights_id")).json == DEFAULT_ID assert resp.json["feature_weight_set_id"] == NEW_DEFAULT_ID
def test_new_feature_weights(client_with_data): resp = client_with_data.post("/datasets/feature_weights", json=NEW_FEATURE_WEIGHTS) assert resp.status_code == 200 assert resp.json["msg"] == "Feature weights successfully imported." new_feature_weights_id = resp.json["feature_weight_set_id"] assert (client_with_data.get( f"/datasets/feature_weights/{new_feature_weights_id}") ).json == NEW_FEATURE_WEIGHTS second_app = app.create_app( DATA_DIR=client_with_data.application.config["DATA_DIR"]) second_app.config["TESTING"] = True second_client = second_app.test_client() assert ( second_client.get(f"/datasets/feature_weights/{new_feature_weights_id}" )).json == NEW_FEATURE_WEIGHTS
def test_app2(): tmpdir = tempfile.mkdtemp() write_app = app.create_app(DATA_DIR=tmpdir) yield write_app shutil.rmtree(tmpdir, ignore_errors=True)
import time import pytest from flask import current_app from validator import app, __version__ as app_version myapp = app.create_app(DATA_DIR="tests/data") start_time = time.ctime() @pytest.fixture(scope="module") def client(): myapp.config["TESTING"] = True client = myapp.test_client() yield client def test_404(client): """Top level does nothing.""" resp = client.get("/") assert resp.status_code == 404 def test_ping(client): """ping -> pong""" resp = client.get("/ping") assert resp.data.decode(resp.content_encoding or "utf-8") == "pong"
"lazy_math_mode": False, }) FEATURES_NEW = OrderedDict({ "stem_word_count": 2.2, "option_word_count": 2.2, "innovation_word_count": 0, "domain_word_count": 0, "bad_word_count": -3, "common_word_count": 0.7, "intercept": 0, "lazy_math_mode": True, }) # Configure the app testapp = app.create_app(test_config={"TESTING": True}) client = testapp.test_client() parser = validate_api.parser # Load the test data and append together df1 = pd.read_csv("algo_tests/data/valid_test_1000.csv") df2 = pd.read_csv("algo_tests/data/invalid_test_1000.csv") df = df1.append(df2).reset_index() # The idea here is that we will be able to pass in the route along with any parameters and get the validity label out def do_api_call(data, route, algo_params): params = {"response": data.response, "uid": data.uid} params.update(algo_params) resp = client.get(route, query_string=urlencode(params))
from validator.app import create_app application = create_app()