def test_valid_ClusterConfig(self, fastapi_client: TestClient) -> None: server_api = get_server_api() logger.debug("server_api : %s", server_api) login_data = { "username": settings.FIRST_SUPERUSER, "password": settings.FIRST_SUPERUSER_PASSWORD, } r = fastapi_client.post( f"{server_api}{settings.API_V1_STR}/login/access-token", data=login_data ) tokens = r.json() cluster_data = { "ultron_cluster_url": server_api, "ultron_acs_token": tokens["access_token"], } c = ClusterConfig(**cluster_data) assert c.ultron_cluster_url == "http://localhost:11267" assert c.ultron_acs_token assert c.ultron_uuid == "cd8f5f9f-e3e8-569f-87ef-f03c6cfc29bc" assert str(c) == f"http://localhost:11267{c.ultron_acs_token}"
def test_create_user_new_email_with_starlette_client( self, superuser_token_headers: Dict[str, str], mocker: MockFixture, fastapi_client: TestClient, db: Session, ) -> None: # SOURCE: https://github.com/tiangolo/fastapi/issues/300 server_api = get_server_api() logger.debug("server_api : %s", server_api) data = _MakeRandomNormalUserFactory() r = fastapi_client.post( f"{server_api}{settings.API_V1_STR}/users/", headers=superuser_token_headers, json=data.dict(), # pylint: disable=no-member ) assert 200 <= r.status_code < 300 created_user = r.json() user = crud.user.get_by_email(db, email=data.email) assert user.email == created_user["email"]
def test_create_user_new_email( self, superuser_token_headers: Dict[str, str], mocker: MockFixture, fastapi_client: TestClient, db: Session, ) -> None: server_api = get_server_api() logger.debug("server_api : %s", server_api) # username = random_lower_string() # password = random_lower_string() data = _MakeRandomNormalUserFactory() # data = {"email": data.email, "password": data.password} r = fastapi_client.post( f"{server_api}{settings.API_V1_STR}/users/", headers=superuser_token_headers, json=data.dict(), # pylint: disable=no-member ) assert 200 <= r.status_code < 300 created_user = r.json() user = crud.user.get_by_email(db, email=data.email) assert user.email == created_user["email"]
def test_refresh_processed(superuser_token_headers): server_api = get_server_api() data = { "version": "version 1", "date_from": "2018-05-26", "date_to": "2019-12-28", "sampling": 20, "split": 80, } response = requests.post( f"{server_api}{config.API_V1_STR}/data/processed-data/", headers=superuser_token_headers, json=data, ) content = response.json() assert response.status_code == 202 assert "updated" in content assert content["version"] == data["version"] assert datetime.strptime(content["date_from"], "%Y-%m-%dT%H:%M:%S") == datetime.strptime( data["date_from"], "%Y-%m-%d") assert datetime.strptime(content["date_to"], "%Y-%m-%dT%H:%M:%S") == datetime.strptime( data["date_to"], "%Y-%m-%d") try: content["sampling"] = int(content["sampling"]) except ValueError: raise AssertionError("sampling is not an int") assert content["sampling"] == data["sampling"] try: content["split"] = int(content["split"]) except ValueError: raise AssertionError("split is not an int") assert content["split"] == data["split"] assert isinstance(content["transformations"], list) assert "email" in content
def update_one_dsi( as_test=True, version_n=None, update_data=None, dsi_uuid=None, access_token=None, ): server_api = get_server_api() # log_.debug ('=== server_api : %s', server_api) ### get test user if access_token == None: test_user_access_token = client_login(as_test=False, only_access_token=True) else: test_user_access_token = access_token log_.debug('=== update_one_dsi / test_user_access_token : %s', test_user_access_token) ### create a test DSI if dsi_uuid == None: test_dsi = create_one_dsi(as_test=False) log_.debug('=== update_one_dsi / test_dsi : \n%s', pformat(test_dsi)) assert test_dsi['data']['is_test_data'] == True test_dsi_uuid = test_dsi['data']['dsi_uuid'] else: test_dsi_uuid = dsi_uuid log_.debug('=== update_one_dsi / test_dsi_uuid : %s', test_dsi_uuid) ### mockup update field if update_data == None: update_data = { "update_data": { "licence": "my-test-licence", "auth_preview": "private" } } params_update = {'version_n': version_n} headers = { 'accept': 'application/json', 'access_token': test_user_access_token, } # url = f"{server_api}{config.API_V1_STR}/dsi/update/{test_dsi_uuid}" url = f"{config.API_V1_STR}/dsi/update/{test_dsi_uuid}" ### update doc # response = requests.put( response = client.put(url, json=update_data, params=params_update, headers=headers) resp = response.json() log_.debug('=== update_one_dsi / resp : \n%s', pformat(resp)) if as_test: assert response.status_code == 200 for key in update_data['update_data'].keys(): assert resp['data'][key] == update_data['update_data'][key] else: return resp
def server_api() -> str: return get_server_api()
def server_api(): return get_server_api()
def test_logger_get_not_existing(self, fastapi_client: TestClient) -> None: server_api = get_server_api() logger.debug("server_api : %s", server_api) r = fastapi_client.get(f"{server_api}{settings.API_V1_STR}/logs/wrong") assert r.status_code == 404
def update_one_dsr( as_test=True, full_update=False, version_n=None, update_data=None, dsi_uuid=None, dsr_uuid=None, access_token=None, ): server_api = get_server_api() # log_.debug ('=== server_api : %s', server_api) ### get test user if access_token == None: test_user_access_token = client_login(as_test=False, only_access_token=True) else: test_user_access_token = access_token log_.debug('=== update_one_dsr / test_user_access_token : %s', test_user_access_token) ### create a test DSI and DSR if dsi_uuid == None and dsr_uuid == None: log_.debug('=== update_one_dsr / no dsi_uuid nor dsr_uuid...') test_dsr = create_one_dsr(as_test=False, dsi_uuid=dsi_uuid) log_.debug('=== update_one_dsr / test_dsr : \n%s', pformat(test_dsr)) test_dsi_uuid = test_dsr['data']['dsi_uuid'] test_dsr_uuid = test_dsr['data']['dsr_uuid'] log_.debug('=== update_one_dsr / test_dsi_uuid : %s', test_dsi_uuid) log_.debug('=== update_one_dsr / test_dsr_uuid : %s', test_dsr_uuid) else: test_dsi_uuid = dsi_uuid if dsi_uuid != None and dsr_uuid == None: test_dsr = create_one_dsr(as_test=False, dsi_uuid=dsi_uuid) test_dsr_uuid = test_dsr['data']['dsr_uuid'] else: test_dsr_uuid = dsr_uuid ### mockup update field if update_data == None: random_int = random.randint(0, 1000) update_data = { "update_data": { 'source': f'my new source - {random_int}', 'licence': 'Obbl-42', "auth_preview": "commons", "auth_modif": "team", "data": { "field_01": f"this is updated data on field_01 - {random_int}", "field_02": f"my updated field_02 data - {random_int}", "field_03": { "subfield_A": f"Update data for numerical or text... {random_int}", "subfield_B": random_int } } } } params_update = {'full_update': full_update, 'version_n': version_n} headers = { 'accept': 'application/json', 'access_token': test_user_access_token, } # url = f"{server_api}{config.API_V1_STR}/crud/dataset/{test_dsi_uuid}/dsr/update/{test_dsr_uuid}" url = f"{config.API_V1_STR}/crud/dataset/{test_dsi_uuid}/dsr/update/{test_dsr_uuid}" ### update doc # response = requests.put( response = client.put(url, json=update_data, params=params_update, headers=headers) resp = response.json() log_.debug('=== update_one_dsr / resp : \n%s', pformat(resp)) if as_test: assert response.status_code == 200 for key in update_data['update_data'].keys(): if key != 'data': assert resp['data'][key] == update_data['update_data'][key] for key in update_data['update_data']['data'].keys(): assert resp['data']['data'][key] == update_data['update_data'][ 'data'][key] else: return resp