Esempio n. 1
0
        def test_predictor(predictior_name, datasource_name):
            check_predictor_not_exists(predictior_name)

            data = {
                'to_predict': list(TO_PREDICT.keys()),
                'data_source_name': datasource_name
            }
            res = requests.put(f'{HTTP_API_ROOT}/predictors/{predictior_name}',
                               json=data)
            assert res.status_code == 200

            # wait for https://github.com/mindsdb/mindsdb/issues/1459
            import time
            time.sleep(5)

            check_predictor_exists(predictior_name)

            import time
            time.sleep(10)

            wait_predictor_learn(predictior_name)

            res = requests.post(
                f'{HTTP_API_ROOT}/predictors/{predictior_name}/predict',
                json={'when': CONDITION})
            assert res.status_code == 200
            res = res.json()
            assert len(res) == 1
            res = res[0]
            for field in TO_PREDICT:
                assert field in res
                assert res[field]['predicted_value'] is not None
                assert res[field]['confidence'] > 0
Esempio n. 2
0
    def test_6_delete(self):
        for predictor_name in [TEST_PREDICTOR, TEST_PREDICTOR_CSV]:
            res = requests.delete(
                f'{HTTP_API_ROOT}/predictors/{predictor_name}')
            assert res.status_code == 200
            check_predictor_not_exists(predictor_name)

        for ds_name in [TEST_DS_CSV, TEST_DS]:
            res = requests.delete(f'{HTTP_API_ROOT}/datasources/{ds_name}')
            assert res.status_code == 200
            check_ds_not_exists(ds_name)
Esempio n. 3
0
    def test_3_wrong_predictor(self):
        '''
        try create predictor with wrong parameters,
        close mindsdb while model training
        check mindsdb can start again
        '''
        check_predictor_not_exists(TEST_PREDICTOR)

        data = {
            'to_predict': list(TO_PREDICT.keys()),
            'data_source_name': 'wrong ds'
        }
        res = requests.put(f'{HTTP_API_ROOT}/predictors/{TEST_PREDICTOR}',
                           json=data)
        assert 'Can not find datasource' in res.json()['message']

        check_predictor_not_exists(TEST_PREDICTOR)

        data = {
            'to_predict': list(TO_PREDICT.keys()),
            'data_source_name': TEST_DS
        }
        res = requests.put(f'{HTTP_API_ROOT}/predictors/{TEST_PREDICTOR}',
                           json=data)
        assert res.status_code == 200

        stop_mindsdb()

        self.mdb, datastore = run_environment(
            config,
            apis=['mysql', 'http'],
            override_integration_config={'default_mariadb': {
                'publish': True
            }},
            mindsdb_database=MINDSDB_DATABASE,
            clear_storage=False)

        # TODO add after this issue will be closed: https://github.com/mindsdb/mindsdb/issues/948
        # check_predictor_not_exists(TEST_PREDICTOR)

        data = {
            'to_predict': list(TO_PREDICT.keys()),
            'data_source_name': TEST_DS
        }
        res = requests.put(f'{HTTP_API_ROOT}/predictors/{TEST_PREDICTOR}_2',
                           json=data)
        assert res.status_code == 200

        wait_predictor_learn(f'{TEST_PREDICTOR}_2')
Esempio n. 4
0
 def test_5_delete(self):
     res = requests.delete(f'{HTTP_API_ROOT}/predictors/{TEST_PREDICTOR}')
     assert res.status_code == 200
     check_predictor_not_exists(TEST_PREDICTOR)