Skip to content

Commit 0fc7c3e

Browse files
authored
Merge pull request #14 from platformsh/updates
relationships updates
2 parents 4f4df10 + 7ea46a9 commit 0fc7c3e

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

platformshconfig/config.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,21 @@ def formatted_credentials(self, relationship, formatter):
399399
)
400400
return self._credentialFormatters[formatter](self.credentials(relationship))
401401

402+
403+
def has_relationship(self, relationship):
404+
"""Determines if a relationship is defined, and thus has credentials available.
405+
406+
Args:
407+
relationship (string):
408+
The name of the relationship to check.
409+
410+
Returns:
411+
bool:
412+
True if the relationship is defined, False otherwise.
413+
414+
"""
415+
return relationship in self.relationshipsDef
416+
402417
def __getitem__(self, item):
403418
"""Reads an environment variable, taking the prefix into account.
404419

tests/test_config.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,22 +193,38 @@ def test_credentials_missing_relationship_throws(self):
193193
with self.assertRaises(KeyError):
194194
config.credentials('does-not-exist')
195195

196-
def test_reading_existing_variable_works(self):
196+
def test_credentials_missing_relationship_index_throws(self):
197197

198198
env = self.mockEnvironmentDeploy
199199

200200
config = Config(env)
201201

202-
self.assertEqual('someval', config.variable('somevar'))
202+
with self.assertRaises(KeyError):
203+
config.credentials('database', 3)
203204

204-
def test_credentials_missing_relationship_index_throws(self):
205+
def test_has_relationship_returns_true_for_existing_relationship(self):
205206

206207
env = self.mockEnvironmentDeploy
207208

208209
config = Config(env)
209210

210-
with self.assertRaises(KeyError):
211-
config.credentials('database', 3)
211+
self.assertTrue(config.has_relationship('database'))
212+
213+
def test_has_relationship_returns_false_for_missing_relationship(self):
214+
215+
env = self.mockEnvironmentDeploy
216+
217+
config = Config(env)
218+
219+
self.assertFalse(config.has_relationship('missing'))
220+
221+
def test_reading_existing_variable_works(self):
222+
223+
env = self.mockEnvironmentDeploy
224+
225+
config = Config(env)
226+
227+
self.assertEqual('someval', config.variable('somevar'))
212228

213229
def test_reading_missing_variable_returns_default(self):
214230

0 commit comments

Comments
 (0)