async def test_get_tenants(ecosystem_admin_client: AsyncClient, member_admin_client: AsyncClient): name = uuid4().hex response = await ecosystem_admin_client.post( BASE_PATH, json={ "image_url": "https://image.ca", "name": name, "roles": ["verifier"], }, ) assert response.status_code == 200 created_tenant = response.json() tenant_id = created_tenant["tenant_id"] response = await ecosystem_admin_client.get(BASE_PATH) assert response.status_code == 200 tenants = response.json() assert len(tenants) >= 1 # Make sure created tenant is returned assert_that(tenants).extracting("tenant_id").contains(tenant_id) # Make sure tenant is not returned when retrieving member tenants response = await member_admin_client.get(BASE_PATH) assert response.status_code == 200 member_tenants = response.json() assert_that(member_tenants).extracting("tenant_id").does_not_contain( tenant_id)
def test_login_success(): signer = URLSafeSerializer('some_secret') token = make_login_token(signer, 'ABC', 42) game, player = read_login_token(signer, token) assert_that(game).is_equal_to('ABC') assert_that(player).is_equal_to(42)
def test_login_fails(): rubbish = 'dsdasdsada' signer = URLSafeSerializer('lala') game, player = read_login_token(signer, rubbish) assert_that(game).is_none() assert_that(player).is_none()
async def test_send_message(bob_and_alice_connection: BobAliceConnect, alice_member_client: AsyncClient): message = Message( connection_id=bob_and_alice_connection["alice_connection_id"], content="Donda") response = await alice_member_client.post( "/generic/messaging/send-message", json=message.dict()) assert_that(response.status_code).is_equal_to(204)
async def test_send_trust_ping(bob_and_alice_connection: BobAliceConnect, alice_member_client: AsyncClient): trustping_msg = TrustPingMsg( connection_id=bob_and_alice_connection["alice_connection_id"], comment="Donda") response = await alice_member_client.post("/generic/messaging/trust-ping", json=trustping_msg.dict()) response_data = response.json() assert_that(response.status_code).is_equal_to(200) assert_that(response_data).contains("thread_id")
def test_nullable_online_store(test_nullable_online_store) -> None: project = f"test_nullable_online_store{str(uuid.uuid4()).replace('-', '')[:8]}" runner = CliRunner() with tempfile.TemporaryDirectory() as repo_dir_name: try: repo_path = Path(repo_dir_name) feature_store_yaml = make_feature_store_yaml( project, test_nullable_online_store, repo_path) repo_config = repo_path / "feature_store.yaml" repo_config.write_text(dedent(feature_store_yaml)) repo_example = repo_path / "example.py" repo_example.write_text( get_example_repo("example_feature_repo_1.py")) result = runner.run(["apply"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) finally: runner.run(["teardown"], cwd=repo_path)
def test_add_guess_to_empty(): history = History.blank() add_guess(history, 'yellow') assert_that(history.entries).is_length(1) assert_that(history.entries[0]).has_kind(Kind.GUESS) assert_that(history.entries[0]).has_context({"word": "yellow"})
def test_request_response(mock): mock_users_url = f'http://localhost:{mock}/users' # The patch.dict() function temporarily replaces the value of the USERS_URL variable. In fact, it does # so only within the scope of the with statement. After that code runs, the USERS_URL variable is # restored to its original value. This code patches the URL to use the mock server address. with patch.dict('users.services.__dict__', {'USERS_URL': mock_users_url}): response = get_users() assert_that(response.status_code).is_equal_to(requests.codes.ok) assert_that(response.headers).contains_entry( {'Content-Type': 'application/json; charset=utf-8'}) response_json = response.json() assert_that(response_json).is_instance_of(list) assert_that(response_json).is_empty()
def test_buy_single_card_too_many_non_camel(): game = Game.initialize() set_up(game) game.next_up = 1 # Give next player 7 cards game.player1.cards = [Card(kind=CardKinds.Leather)] * 7 open_cards = list(game.open_cards) player_s_cards = list(game.player2.cards) top_card = game.cards[0] cards_left = len(game.cards) outcome = buy_one(game, 2) with soft_assertions(): assert_that(outcome).is_equal_to(Outcomes.TOO_MANY_CARDS) assert_that(game.cards).is_length(cards_left) assert_that(game.player1.cards).is_length(7)
def test_non_camel_cards_none(): player = Player.initialize() player.cards = [Card.camel(), Card.camel(), Card.camel()] assert_that(non_camel_cards(player=player)).is_empty()
def test_camel_cards_only(): player = Player.initialize() player.cards = [Card.camel(), Card.camel(), Card.camel()] assert_that(camel_cards(player=player)).is_length(3)
def test_camel_cards_none(): player = Player.initialize() player.cards = [Card(kind=CardKinds.Gems), Card(kind=CardKinds.Gold)] assert_that(camel_cards(player=player)).is_empty()
def test_3rd_party_registry_store() -> None: """ Test running apply on third party registry stores """ runner = CliRunner() # Check with incorrect built-in provider name (no dots) with setup_third_party_registry_store_repo("feast123") as repo_path: return_code, output = runner.run_with_output(["apply"], cwd=repo_path) assertpy.assert_that(return_code).is_equal_to(1) assertpy.assert_that(output).contains( b'Registry store class name should end with "RegistryStore"') # Check with incorrect third-party registry store name (with dots) with setup_third_party_registry_store_repo( "feast_foo.RegistryStore") as repo_path: return_code, output = runner.run_with_output(["apply"], cwd=repo_path) assertpy.assert_that(return_code).is_equal_to(1) assertpy.assert_that(output).contains( b"Could not import RegistryStore module 'feast_foo'") # Check with incorrect third-party registry store name (with dots) with setup_third_party_registry_store_repo( "foo.FooRegistryStore") as repo_path: return_code, output = runner.run_with_output(["apply"], cwd=repo_path) assertpy.assert_that(return_code).is_equal_to(1) assertpy.assert_that(output).contains( b"Could not import RegistryStore 'FooRegistryStore' from module 'foo'" ) # Check with correct third-party registry store name with setup_third_party_registry_store_repo( "foo.registry_store.FooRegistryStore") as repo_path: return_code, output = runner.run_with_output(["apply"], cwd=repo_path) assertpy.assert_that(return_code).is_equal_to(0)
def test_example_input_result_part1(): assertpy.assert_that( example_philosophy.count_valid_passwords()).is_equal_to(2)
def test_non_camel_cards_none_from_card_list(): cards = [Card.camel(), Card.camel(), Card.camel()] assert_that(non_camel_cards(cards=cards)).is_empty()
def test_non_camel_cards_some_from_card_list(): cards = [Card(kind=CardKinds.Leather), Card.camel(), Card(kind=CardKinds.Gems), Card.camel(), Card(kind=CardKinds.Gold)] assert_that(non_camel_cards(cards=cards)).is_length(3)
def test_example_input_result_part1(): assertpy.assert_that(binary_boarding.find_highest_id()).is_equal_to(820)
def test_buy_single_card(): game = Game.initialize() set_up(game) game.next_up = 2 index = 3 # Let's keep the current open cards as reference open_cards = list(game.open_cards) player_s_cards = list(game.player2.cards) top_card = game.cards[0] cards_left = len(game.cards) outcome = buy_one(game, index) with soft_assertions(): assert_that(Card.camel()).is_equal_to(Card.camel()) assert_that(game).has_next_up(1) assert_that(game.open_cards).is_length(5) assert_that(game.cards).is_length(cards_left - 1) assert_that( game.open_cards).is_equal_to(open_cards[:index] + [top_card] + open_cards[index + 1:]) assert_that(game.player2.cards).is_equal_to(player_s_cards + [open_cards[index]]) assert_that(outcome).is_equal_to(Outcomes.NEXT_PLAYER)
def test_universal_cli(environment: Environment): project = f"test_universal_cli_{str(uuid.uuid4()).replace('-', '')[:8]}" runner = CliRunner() with tempfile.TemporaryDirectory() as repo_dir_name: try: repo_path = Path(repo_dir_name) feature_store_yaml = make_feature_store_yaml( project, environment.test_repo_config, repo_path) repo_config = repo_path / "feature_store.yaml" repo_config.write_text(dedent(feature_store_yaml)) repo_example = repo_path / "example.py" repo_example.write_text( get_example_repo("example_feature_repo_1.py")) result = runner.run(["apply"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) # Store registry contents, to be compared later. fs = FeatureStore(repo_path=str(repo_path)) registry_dict = fs.registry.to_dict(project=project) # Save only the specs, not the metadata. registry_specs = { key: [fco["spec"] if "spec" in fco else fco for fco in value] for key, value in registry_dict.items() } # entity & feature view list commands should succeed result = runner.run(["entities", "list"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) result = runner.run(["feature-views", "list"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) result = runner.run(["feature-services", "list"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) result = runner.run(["data-sources", "list"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) # entity & feature view describe commands should succeed when objects exist result = runner.run(["entities", "describe", "driver"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) result = runner.run( ["feature-views", "describe", "driver_locations"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) result = runner.run( ["feature-services", "describe", "driver_locations_service"], cwd=repo_path, ) assertpy.assert_that(result.returncode).is_equal_to(0) assertpy.assert_that(fs.list_feature_views()).is_length(4) result = runner.run( ["data-sources", "describe", "customer_profile_source"], cwd=repo_path, ) assertpy.assert_that(result.returncode).is_equal_to(0) assertpy.assert_that(fs.list_data_sources()).is_length(4) # entity & feature view describe commands should fail when objects don't exist result = runner.run(["entities", "describe", "foo"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(1) result = runner.run(["feature-views", "describe", "foo"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(1) result = runner.run(["feature-services", "describe", "foo"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(1) result = runner.run(["data-sources", "describe", "foo"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(1) # Doing another apply should be a no op, and should not cause errors result = runner.run(["apply"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) basic_rw_test( FeatureStore(repo_path=str(repo_path), config=None), view_name="driver_locations", ) # Confirm that registry contents have not changed. registry_dict = fs.registry.to_dict(project=project) assertpy.assert_that(registry_specs).is_equal_to({ key: [fco["spec"] if "spec" in fco else fco for fco in value] for key, value in registry_dict.items() }) result = runner.run(["teardown"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) finally: runner.run(["teardown"], cwd=repo_path)
def test_camel_cards_none_from_card_list(): cards = [Card(kind=CardKinds.Gems), Card(kind=CardKinds.Gold)] assert_that(camel_cards(cards=cards)).is_empty()
def test_camel_cards_only_from_card_list(): cards = [Card.camel(), Card.camel(), Card.camel()] assert_that(camel_cards(cards=cards)).is_length(3)
async def test_create_tenant_ecosystem_verifier( ecosystem_admin_client: AsyncClient, ecosystem_admin_acapy_client: AcaPyClient): name = uuid4().hex response = await ecosystem_admin_client.post( BASE_PATH, json={ "image_url": "https://image.ca", "name": name, "roles": ["verifier"], }, ) assert response.status_code == 200 tenant = response.json() tenant_id = tenant["tenant_id"] wallet = await ecosystem_admin_acapy_client.multitenancy.get_wallet( wallet_id=tenant_id) actor = await trust_registry.actor_by_id(tenant_id) if not actor: raise Exception("Missing actor") acapy_token: str = tenant["access_token"].split(".", 1)[1] async with get_tenant_controller(Role.ECOSYSTEM, acapy_token) as tenant_controller: connections = await tenant_controller.connection.get_connections( alias=f"Trust Registry {name}") connection = connections.results[0] # Connection invitation assert_that(connection).has_state("invitation") assert_that(actor).has_name(tenant["tenant_name"]) assert_that(actor).has_did( ed25519_verkey_to_did_key(connection.invitation_key)) assert_that(actor).has_roles(["verifier"]) # Tenant assert_that(tenant).has_tenant_id(wallet.wallet_id) assert_that(tenant).has_tenant_name(name) assert_that(tenant).has_created_at(wallet.created_at) assert_that(tenant).has_updated_at(wallet.updated_at) assert wallet.settings["wallet.name"].startswith("ecosystem.")
def test_camel_cards_some(): player = Player.initialize() player.cards = [Card.camel(), Card(kind=CardKinds.Gems), Card(kind=CardKinds.Gems), Card.camel(), Card(kind=CardKinds.Gold)] assert_that(camel_cards(player=player)).is_length(2)
def test_example_input_result_part1(): assertpy.assert_that(toboggan_trajectory.count_trees(3, 1)).is_equal_to(7)
def test_non_camel_cards_only_from_card_list(): cards = [Card(kind=CardKinds.Gems), Card(kind=CardKinds.Gold)] assert_that(non_camel_cards(cards=cards)).is_length(2)
def test_example_input_result(): assertpy.assert_that( example_repair.multiply_2020_combination(2)).is_equal_to(514579)
async def test_update_tenant_ecosystem_verifier_to_issuer( ecosystem_admin_client: AsyncClient, ecosystem_admin_acapy_client: AcaPyClient, governance_acapy_client: AcaPyClient, ): name = uuid4().hex response = await ecosystem_admin_client.post( BASE_PATH, json={ "image_url": "https://image.ca", "name": name, "roles": ["verifier"], }, ) assert response.status_code == 200 tenant = response.json() tenant_id = tenant["tenant_id"] actor = await trust_registry.actor_by_id(tenant_id) wallet = await ecosystem_admin_acapy_client.multitenancy.get_wallet( wallet_id=tenant_id) acapy_token: str = tenant["access_token"].split(".", 1)[1] async with get_tenant_controller(Role.ECOSYSTEM, acapy_token) as tenant_controller: connections = await tenant_controller.connection.get_connections( alias=f"Trust Registry {name}") connection = connections.results[0] # Connection invitation assert_that(connection).has_state("invitation") assert actor assert_that(actor).has_name(name) assert_that(actor).has_did( ed25519_verkey_to_did_key(connection.invitation_key)) assert_that(actor).has_roles(["verifier"]) # Tenant assert_that(tenant).has_tenant_id(wallet.wallet_id) assert_that(tenant).has_image_url("https://image.ca") assert_that(tenant).has_tenant_name(name) assert_that(tenant).has_created_at(wallet.created_at) assert_that(tenant).has_updated_at(wallet.updated_at) assert wallet.settings["wallet.name"].startswith("ecosystem.") new_name = uuid4().hex new_image_url = "https://some-ssi-site.org/image.png" new_roles = ["issuer", "verifier"] response = await ecosystem_admin_client.put( f"{BASE_PATH}/{tenant_id}", json={ "image_url": new_image_url, "name": new_name, "roles": new_roles, }, ) assert response.status_code == 200 new_tenant = response.json() new_actor = await trust_registry.actor_by_id(tenant_id) endorser_did = await acapy_wallet.get_public_did(governance_acapy_client) async with get_tenant_controller(Role.ECOSYSTEM, acapy_token) as tenant_controller: public_did = await acapy_wallet.get_public_did(tenant_controller) _connections = (await tenant_controller.connection.get_connections()).results connections = [ connection for connection in _connections if connection.their_public_did == endorser_did.did ] endorser_connection = connections[0] async with ecosystem_client(token=tenant["access_token"]) as client: # Wait for connection to be completed assert check_webhook_state( client, "connections", { "state": "completed", "connection_id": endorser_connection.connection_id, }, ) # Connection invitation assert_that(endorser_connection).has_their_public_did(endorser_did.did) assert new_actor assert_that(new_actor).has_name(new_name) assert_that(new_actor).has_did(f"did:sov:{public_did.did}") assert_that(new_actor["roles"]).contains_only("issuer", "verifier") assert new_actor["didcomm_invitation"] is None # Tenant assert_that(new_tenant).has_tenant_id(wallet.wallet_id) assert_that(new_tenant).has_image_url(new_image_url) assert_that(new_tenant).has_tenant_name(new_name) assert_that(new_tenant).has_created_at(wallet.created_at) assert wallet.settings["wallet.name"].startswith("ecosystem.")
def test_3rd_party_providers() -> None: """ Test running apply on third party providers """ runner = CliRunner() # Check with incorrect built-in provider name (no dots) with setup_third_party_provider_repo("feast123") as repo_path: return_code, output = runner.run_with_output(["apply"], cwd=repo_path) assertpy.assert_that(return_code).is_equal_to(1) assertpy.assert_that(output).contains( b"Provider 'feast123' is not implemented") # Check with incorrect third-party provider name (with dots) with setup_third_party_provider_repo("feast_foo.Provider") as repo_path: return_code, output = runner.run_with_output(["apply"], cwd=repo_path) assertpy.assert_that(return_code).is_equal_to(1) assertpy.assert_that(output).contains( b"Could not import Provider module 'feast_foo'") # Check with incorrect third-party provider name (with dots) with setup_third_party_provider_repo("foo.FooProvider") as repo_path: return_code, output = runner.run_with_output(["apply"], cwd=repo_path) assertpy.assert_that(return_code).is_equal_to(1) assertpy.assert_that(output).contains( b"Could not import Provider 'FooProvider' from module 'foo'") # Check with correct third-party provider name with setup_third_party_provider_repo( "foo.provider.FooProvider") as repo_path: return_code, output = runner.run_with_output(["apply"], cwd=repo_path) assertpy.assert_that(return_code).is_equal_to(0)
async def test_create_tenant_ecosystem_issuer( ecosystem_admin_client: AsyncClient, ecosystem_admin_acapy_client: AcaPyClient, governance_acapy_client: AcaPyClient, ): name = uuid4().hex response = await ecosystem_admin_client.post( BASE_PATH, json={ "image_url": "https://image.ca", "name": name, "roles": ["issuer"], }, ) assert response.status_code == 200 tenant = response.json() tenant_id = tenant["tenant_id"] wallet = await ecosystem_admin_acapy_client.multitenancy.get_wallet( wallet_id=tenant_id) acapy_token: str = tenant["access_token"].split(".", 1)[1] actor = await trust_registry.actor_by_id(tenant_id) endorser_did = await acapy_wallet.get_public_did(governance_acapy_client) async with get_tenant_controller(Role.ECOSYSTEM, acapy_token) as tenant_controller: public_did = await acapy_wallet.get_public_did(tenant_controller) connections = await tenant_controller.connection.get_connections() connections = [ connection for connection in connections.results if connection.their_public_did == endorser_did.did ] if not actor: raise Exception("Missing actor") connection = connections[0] async with ecosystem_client(token=tenant["access_token"]) as client: # Wait for connection to be completed assert check_webhook_state( client, "connections", { "state": "completed", "connection_id": connection.connection_id, }, ) # Actor assert_that(actor).has_name(tenant["tenant_name"]) assert_that(actor).has_did(f"did:sov:{public_did.did}") assert_that(actor).has_roles(["issuer"]) # Connection with endorser assert_that(connection).has_their_public_did(endorser_did.did) # Tenant assert_that(tenant).has_tenant_id(wallet.wallet_id) assert_that(tenant).has_tenant_name(name) assert_that(tenant).has_created_at(wallet.created_at) assert_that(tenant).has_updated_at(wallet.updated_at) assert wallet.settings["wallet.name"].startswith("ecosystem.")
def test_universal_cli(test_repo_config) -> None: project = f"test_universal_cli_{str(uuid.uuid4()).replace('-', '')[:8]}" runner = CliRunner() with tempfile.TemporaryDirectory() as repo_dir_name: feature_store_yaml = make_feature_store_yaml(project, test_repo_config, repo_dir_name) repo_path = Path(repo_dir_name) repo_config = repo_path / "feature_store.yaml" repo_config.write_text(dedent(feature_store_yaml)) repo_example = repo_path / "example.py" repo_example.write_text(get_example_repo("example_feature_repo_1.py")) result = runner.run(["apply"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) # Store registry contents, to be compared later. fs = FeatureStore(repo_path=str(repo_path)) registry_dict = fs.registry.to_dict(project=project) # entity & feature view list commands should succeed result = runner.run(["entities", "list"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) result = runner.run(["feature-views", "list"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) result = runner.run(["feature-services", "list"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) # entity & feature view describe commands should succeed when objects exist result = runner.run(["entities", "describe", "driver"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) result = runner.run(["feature-views", "describe", "driver_locations"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) result = runner.run( ["feature-services", "describe", "driver_locations_service"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) assertpy.assert_that(fs.list_feature_views()).is_length(3) # entity & feature view describe commands should fail when objects don't exist result = runner.run(["entities", "describe", "foo"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(1) result = runner.run(["feature-views", "describe", "foo"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(1) result = runner.run(["feature-services", "describe", "foo"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(1) # Doing another apply should be a no op, and should not cause errors result = runner.run(["apply"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0) basic_rw_test( FeatureStore(repo_path=str(repo_path), config=None), view_name="driver_locations", ) # Confirm that registry contents have not changed. assertpy.assert_that(registry_dict).is_equal_to( fs.registry.to_dict(project=project)) result = runner.run(["teardown"], cwd=repo_path) assertpy.assert_that(result.returncode).is_equal_to(0)