def get(self, key, value): """Get single app by one of id or name Keyword Args: id (str): Full app id name (str): App name Returns: App: Corresponding App resource instance Raises: TypeError: No or multiple keyword arguments provided ValueError: No matching app found on server """ if key == 'id': # Server returns 204 instead of 404 for a non-existent app id response = self._swimlane.request('get', 'app/{}'.format(value)) if response.status_code == 204: raise ValueError('No app with id "{}"'.format(value)) return App(self._swimlane, response.json()) else: # Workaround for lack of support for get by name # Holdover from previous driver support, to be fixed as part of 3.x for app in self.list(): if value and value == app.name: return app # No matching app found raise ValueError('No app with name "{}"'.format(value))
def list(self): """Retrieve list of all apps Returns: :class:`list` of :class:`~swimlane.core.resources.app.App`: List of all retrieved apps """ response = self._swimlane.request('get', 'app') return [App(self._swimlane, item) for item in response.json()]
def setUp(self): self.src_app = App({ 'id': '123', 'name': 'Source', 'acronym': 'SO', 'fields': [{ 'name': 'Component', 'values': [{ 'name': 'Foo' }, { 'name': 'Bar' }, { 'name': 'Baz' }], 'fieldType': 'valuesList' }] }) self.dest_app = App({ 'id': '456', 'name': 'Destination', 'acronym': 'DE', 'fields': [{ 'name': 'Component', 'values': [{ 'name': 'Baz' }, { 'name': 'Bar' }], 'fieldType': 'valuesList' }] })
def test_find_by_acronym_does_not_exist(self, mock_client): mock_client.get.return_value = [MOCK_APP] app = App.find(acronym='SOA') self.assertIsNone(app)
def test_find_by_acronym(self, mock_client): mock_client.get.return_value = [MOCK_APP] app = App.find(acronym='MA') self.assertIsInstance(app, App) self.assertEqual(app.acronym, 'MA')
def test_find_by_name_does_not_exist(self, mock_client): mock_client.get.return_value = [MOCK_APP] app = App.find(name='Some Other App') self.assertIsNone(app)
def test_find_by_id(self, mock_client): mock_client.get.return_value = MOCK_APP app = App.find(app_id='123') self.assertIsInstance(app, App) self.assertEqual(app.id, '123')
def test_find_by_name(self, mock_client): mock_client.get.return_value = [MOCK_APP] app = App.find(name='Mock App') self.assertIsInstance(app, App) self.assertEqual(app.name, 'Mock App')
def test_field_id(self): app = App(MOCK_APP) self.assertEqual(app.field_id('Mock Field'), '456') self.assertEqual(app.field_id('Not A Field'), None)
def test_find_all(self, mock_client): mock_client.get.return_value = [MOCK_APP] apps = list(App.find_all()) self.assertEqual(len(apps), 1) self.assertIsInstance(apps[0], App)
def test_find_with_missing_attributes(self, mock_client): """Tests that no exception is raised when returned App does not provide an acronym or name attribute""" mock_client.get.return_value = [{}] self.assertIsNone(App.find(name='Some App')) self.assertIsNone(App.find(acronym='SOA'))
def test_find_by_id(self, mock_client): mock_client.get.return_value = MOCK_APP app = App.find(app_id="123") self.assertIsInstance(app, App) self.assertEqual(app.id, "123")
def test_find_by_acronym_does_not_exist(self, mock_client): mock_client.get.return_value = [MOCK_APP] app = App.find(acronym="SOA") self.assertIsNone(app)
def test_find_by_name_does_not_exist(self, mock_client): mock_client.get.return_value = [MOCK_APP] app = App.find(name="Some Other App") self.assertIsNone(app)
def test_find_by_acronym(self, mock_client): mock_client.get.return_value = [MOCK_APP] app = App.find(acronym="MA") self.assertIsInstance(app, App) self.assertEqual(app.acronym, "MA")
def test_find_by_name(self, mock_client): mock_client.get.return_value = [MOCK_APP] app = App.find(name="Mock App") self.assertIsInstance(app, App) self.assertEqual(app.name, "Mock App")
def test_init(self): app = App(MOCK_APP) for key, value in MOCK_APP.items(): self.assertEqual(getattr(app, key), value)
def test_field_id(self): app = App(MOCK_APP) self.assertEqual(app.field_id("Mock Field"), "456") self.assertEqual(app.field_id("Not A Field"), None)