import pytest from atlas_um.pgdb import ClaimValue class TestClaimValue: CORE_IMAGES_HOST = "core-images.test" @pytest.fixture def app_config(self): def inner(app): app.config["CORE_IMAGES_HOST"] = self.CORE_IMAGES_HOST return inner def test_boolean_components_round_trip( self, claim_value_factory, faker, pgdb_session ): components = faker.pybool() claim_value = claim_value_factory.build(components=components) pgdb_session.add(claim_value) pgdb_session.commit() persisted = pgdb_session.query(ClaimValue).one() assert persisted.components == components def test_string_components_round_trip( self, claim_value_factory, faker, pgdb_session ): components = faker.pystr() claim_value = claim_value_factory.build(components=components) pgdb_session.add(claim_value) pgdb_session.commit() persisted = pgdb_session.query(ClaimValue).one() assert persisted.components == components def test_dict_components_round_trip( self, claim_value_factory, faker, pgdb_session ): components = faker.pydict( variable_nb_elements=True, value_types=("str", "float", "int", "uri", "email"), ) claim_value = claim_value_factory.build(components=components) pgdb_session.add(claim_value) pgdb_session.commit() persisted = pgdb_session.query(ClaimValue).one() assert persisted.components == components def test_resource_group(self, claim_name_factory, claim_value_factory): claim_name = claim_name_factory.build() claim_value = claim_value_factory.build(claim_name=claim_name) assert claim_value.resource_group == claim_name.resource_group def test_image(self, app, claim_name_factory, claim_value_factory): app.config.CORE_IMAGES_HOST = "CORE_IMAGES_HOST" test_images_urls = "/v999/something/images" claim_name = claim_name_factory.build(images_url=test_images_urls) claim_value = claim_value_factory.build(claim_name=claim_name) expected_url = ( f"https://" f"{self.CORE_IMAGES_HOST}" f"{test_images_urls}/" f"{claim_value.external_id}" ) assert claim_value.image == expected_url