class TestCFenv(unittest.TestCase): def setUp(self): self.cfenv = CFenv() def test_space_name(self): self.assertEqual(self.cfenv.space_name, '') def test_organization_name(self): self.assertEqual(self.cfenv.organization_name, '') def test_uris(self): self.assertIsInstance(self.cfenv.uris, list) def test_configserver_uri(self): self.assertEqual(self.cfenv.configserver_uri(), '') def test_configserver_access_token_uri(self): self.assertEqual(self.cfenv.configserver_access_token_uri(), '') def test_configserver_client_id(self): self.assertEqual(self.cfenv.configserver_client_id(), '') def test_configserver_client_secret(self): self.assertEqual(self.cfenv.configserver_client_secret(), '')
class TestCFenv(unittest.TestCase): def setUp(self): self.cfenv = CFenv() def test_space_name(self): self.assertEqual(self.cfenv.space_name, '') def test_organization_name(self): self.assertEqual(self.cfenv.organization_name, '') def test_uris(self): self.assertIsInstance(self.cfenv.uris, list) def test_configserver_uri(self): self.assertEqual(self.cfenv.configserver_uri(), '') def test_configserver_access_token_uri(self): self.assertEqual(self.cfenv.configserver_access_token_uri(), '') def test_configserver_client_id(self): self.assertEqual(self.cfenv.configserver_client_id(), '') def test_configserver_client_secret(self): self.assertEqual(self.cfenv.configserver_client_secret(), '') def test_default_vcap_service_prefix(self): self.assertIn('p-config-server', self.cfenv.vcap_services.keys()) def test_custom_vcap_service_prefix(self): cfenv = CFenv(vcap_service_prefix='config-server') self.assertIn('config-server', cfenv.vcap_services.keys()) self.assertNotEqual(self.cfenv.vcap_services, cfenv.vcap_services) def test_format_vcap_path(self): path = self.cfenv._format_vcap_path('.0.credentials.uri') self.assertEqual(path, 'p-config-server.0.credentials.uri')
class CF: cfenv = attr.ib(type=CFenv, default=CFenv()) oauth2 = attr.ib(type=OAuth2, default=None) client = attr.ib(type=ConfigClient, default=None) def __attrs_post_init__(self) -> None: if not self.oauth2: self.oauth2 = OAuth2( access_token_uri=self.cfenv.configserver_access_token_uri(), client_id=self.cfenv.configserver_client_id(), client_secret=self.cfenv.configserver_client_secret(), ) if not self.client: self.client = ConfigClient( address=self.cfenv.configserver_uri(), app_name=self.cfenv.application_name, ) self.oauth2.configure() @property def vcap_services(self): return self.cfenv.vcap_services @property def vcap_application(self): return self.cfenv.vcap_application def get_config(self) -> None: header = {"Authorization": f"Bearer {self.oauth2.token}"} self.client.get_config(header) @property def config(self) -> Dict: return self.client.config def get_attribute(self, value: str) -> Any: return self.client.get_attribute(value) def get_keys(self) -> KeysView: return self.client.get_keys()
def cfenv(self): return CFenv()
def test_custom_vcap_service_prefix(self, cfenv): cfenv2 = CFenv(vcap_service_prefix="config-server") "config-server" in cfenv2.vcap_services.keys() cfenv.vcap_services != cfenv2.vcap_services
def setUp(self): self.cfenv = CFenv()
def test_custom_vcap_service_prefix(self): cfenv = CFenv(vcap_service_prefix='config-server') self.assertIn('config-server', cfenv.vcap_services.keys()) self.assertNotEqual(self.cfenv.vcap_services, cfenv.vcap_services)
def custom_cfenv(): return CFenv( vcap_services=json.loads(CUSTOM_VCAP_SERVICES), vcap_application=json.loads(CUSTOM_VCAP_APPLICATION), )
def cfenv(): return CFenv()
def test_custom_vcap_service_prefix(self, prefix): cfenv2 = CFenv(vcap_service_prefix=prefix) assert prefix in cfenv2.vcap_services.keys()