예제 #1
0
    def test_missing_static_dir(self):
        fake_dir = os.path.join(self.TEST_DIR,
                                '/this/directory/does/not/exist')

        with self.assertRaises(SystemExit) as cm:
            make_app(fake_dir)
            assert cm.code == -1  # pylint: disable=no-member
예제 #2
0
 def setUp(self):
     super(TestApp, self).setUp()
     if self.client is None:
         app = make_app()
         app.predictors = load_predictors(TEST_CONFIG_FILES)
         app.testing = True
         self.client = app.test_client
예제 #3
0
    def test_permalinks_work(self):
        db = InMemoryDemoDatabase()
        app = make_app(build_dir=self.TEST_DIR, demo_db=db)
        predictor = CountingPredictor()
        app.predictors = {"counting": predictor}
        app.testing = True
        client = app.test_client

        data = {"some": "input"}
        _, response = client.post("/predict/counting", json=data)

        assert response.status == 200
        result = json.loads(response.text)
        slug = result.get("slug")
        assert slug is not None

        print("db data", db.data)

        _, response = client.post("/permadata",
                                  json={"slug": "not the right slug"})
        assert response.status == 400

        _, response = client.post("/permadata", json={"slug": slug})
        assert response.status == 200
        result2 = json.loads(response.text)
        assert set(
            result2.keys()) == {"modelName", "requestData", "responseData"}
        assert result2["modelName"] == "counting"
        assert result2["requestData"] == data
        assert result2["responseData"] == result
예제 #4
0
    def setUp(self):
        super().setUp()
        if self.client is None:
            self.app = make_app()
            self.app.predictors = {
                name: Predictor.from_archive(load_archive(archive_file))
                for name, archive_file in TEST_ARCHIVE_FILES.items()
            }

            self.app.testing = True
            self.client = self.app.test_client
예제 #5
0
    def setUp(self):
        super().setUp()
        # Create index.html in TEST_DIR
        pathlib.Path(os.path.join(self.TEST_DIR, 'index.html')).touch()

        if self.client is None:

            self.app = make_app(build_dir=self.TEST_DIR)
            self.app.predictors = PREDICTORS
            self.app.testing = True
            self.client = self.app.test_client
예제 #6
0
    def setUp(self):
        super().setUp()
        # Create index.html in TEST_DIR
        pathlib.Path(os.path.join(self.TEST_DIR, 'index.html')).touch()

        if self.client is None:

            self.app = make_app(build_dir=self.TEST_DIR)
            self.app.predictors = {
                name: Predictor.from_archive(load_archive(archive_file),
                                             predictor_name=name)
                for name, archive_file in TEST_ARCHIVE_FILES.items()
            }

            self.app.testing = True
            self.client = self.app.test_client
예제 #7
0
    def test_permalinks_fail_gracefully_with_no_database(self):
        app = make_app(build_dir=self.TEST_DIR)
        predictor = CountingPredictor()
        app.predictors = {"counting": predictor}
        app.testing = True
        client = app.test_client

        # Make a prediction, no permalinks.
        data = {"some": "input"}
        _, response = client.post("/predict/counting", json=data)

        assert response.status == 200

        # With permalinks not enabled, the result shouldn't contain a slug.
        result = json.loads(response.text)
        assert "slug" not in result

        # With permalinks not enabled, a post to the /permadata endpoint should be a 400.
        _, response = self.client.post("/permadata", json={"slug": "someslug"})
        assert response.status == 400
예제 #8
0
    def test_disable_caching(self):
        import allennlp.service.server_sanic as server_sanic
        server_sanic.CACHE_SIZE = 0

        predictor = CountingPredictor()
        app = server_sanic.make_app(build_dir=self.TEST_DIR)
        app.predictors = {"counting": predictor}
        app.testing = True
        client = app.test_client

        data = {"input1": "this is input 1", "input2": 10}
        key = json.dumps(data)

        assert not predictor.calls

        for i in range(5):
            _, response = client.post("/predict/counting", json=data)
            assert response.status == 200
            assert json.loads(response.text) == data

            # cache is disabled, so call count should keep incrementing
            assert predictor.calls[key] == i + 1
            assert len(predictor.calls) == 1