def setUp(self): mock_clients = self._create_service_mock('org_management') self.org_management_service = OrgManagementService() self.org_management_service.clients = mock_clients # Rename to save some typing self.mock_create = mock_clients.resource_registry.create self.mock_read = mock_clients.resource_registry.read self.mock_update = mock_clients.resource_registry.update self.mock_delete = mock_clients.resource_registry.delete self.mock_create_association = mock_clients.resource_registry.create_association self.mock_delete_association = mock_clients.resource_registry.delete_association self.mock_find_objects = mock_clients.resource_registry.find_objects self.mock_find_resources = mock_clients.resource_registry.find_resources self.mock_find_subjects = mock_clients.resource_registry.find_subjects # Exchange Space self.org = Mock() self.org.name = "Foo" self.user_role = Mock() self.user_role.name = "Member" self.user_role2 = Mock() self.user_role2.name = "Member"
def setUp(self): mock_clients = self._create_service_mock('org_management') self.org_management_service = OrgManagementService() self.org_management_service.clients = mock_clients # Rename to save some typing self.mock_create = mock_clients.resource_registry.create self.mock_read = mock_clients.resource_registry.read self.mock_update = mock_clients.resource_registry.update self.mock_delete = mock_clients.resource_registry.delete self.mock_create_association = mock_clients.resource_registry.create_association self.mock_delete_association = mock_clients.resource_registry.delete_association self.mock_find_objects = mock_clients.resource_registry.find_objects self.mock_find_resources = mock_clients.resource_registry.find_resources self.mock_find_subjects = mock_clients.resource_registry.find_subjects # Exchange Space self.org = Mock() self.org.name = "Foo" self.user_role = Mock() self.user_role2 = Mock()
class TestOrgManagementService(PyonTestCase): def setUp(self): mock_clients = self._create_service_mock("org_management") self.org_management_service = OrgManagementService() self.org_management_service.clients = mock_clients # Rename to save some typing self.mock_create = mock_clients.resource_registry.create self.mock_read = mock_clients.resource_registry.read self.mock_update = mock_clients.resource_registry.update self.mock_delete = mock_clients.resource_registry.delete self.mock_create_association = mock_clients.resource_registry.create_association self.mock_delete_association = mock_clients.resource_registry.delete_association self.mock_find_objects = mock_clients.resource_registry.find_objects self.mock_find_resources = mock_clients.resource_registry.find_resources self.mock_find_subjects = mock_clients.resource_registry.find_subjects # Org self.org = Mock() self.org.name = "Foo" self.org.org_governance_name = "" self.user_role = Mock() self.user_role2 = Mock() @patch("pyon.ion.directory.Directory.__init__", Mock(return_value=None)) def test_create_org(self): self.mock_find_objects.return_value = ([self.user_role], [self.user_role2]) self.mock_create.return_value = ["111", 1] org_id = self.org_management_service.create_org(self.org) assert org_id == "111" self.mock_create.assert_called_once_with(self.org) def test_read_and_update_org(self): self.mock_read.return_value = self.org org = self.org_management_service.read_org("111") assert org is self.mock_read.return_value self.mock_read.assert_called_once_with("111", "") org.name = "Bar" self.mock_update.return_value = ["111", 2] self.org_management_service.update_org(org) self.mock_update.assert_called_once_with(org) def test_delete_org(self): self.org_management_service.delete_org("111") self.mock_delete.assert_called_once_with("111") def test_read_org_not_found(self): self.mock_read.side_effect = NotFound("Org bad does not exist") # TEST: Execute the service operation call with self.assertRaises(NotFound) as cm: self.org_management_service.read_org("bad") ex = cm.exception self.assertEqual(ex.message, "Org bad does not exist") self.mock_read.assert_called_once_with("bad", "") def test_delete_org_not_found(self): self.mock_delete.side_effect = NotFound("Org bad does not exist") # TEST: Execute the service operation call with self.assertRaises(NotFound) as cm: self.org_management_service.delete_org("bad") ex = cm.exception self.assertEqual(ex.message, "Org bad does not exist") self.mock_delete.assert_called_once_with("bad")
class TestOrgManagementService(PyonTestCase): def setUp(self): mock_clients = self._create_service_mock('org_management') self.org_management_service = OrgManagementService() self.org_management_service.clients = mock_clients # Rename to save some typing self.mock_create = mock_clients.resource_registry.create self.mock_read = mock_clients.resource_registry.read self.mock_update = mock_clients.resource_registry.update self.mock_delete = mock_clients.resource_registry.delete self.mock_create_association = mock_clients.resource_registry.create_association self.mock_delete_association = mock_clients.resource_registry.delete_association self.mock_find_objects = mock_clients.resource_registry.find_objects self.mock_find_resources = mock_clients.resource_registry.find_resources self.mock_find_subjects = mock_clients.resource_registry.find_subjects # Exchange Space self.org = Mock() self.org.name = "Foo" self.user_role = Mock() self.user_role2 = Mock() @patch('pyon.ion.directory.Directory.__init__', Mock(return_value=None)) def test_create_org(self): self.mock_find_objects.return_value = ([self.user_role], [self.user_role2]) self.mock_create.return_value = ['111', 1] org_id = self.org_management_service.create_org(self.org) assert org_id == '111' self.mock_create.assert_called_once_with(self.org) def test_read_and_update_org(self): self.mock_read.return_value = self.org org = self.org_management_service.read_org('111') assert org is self.mock_read.return_value self.mock_read.assert_called_once_with('111', '') org.name = 'Bar' self.mock_update.return_value = ['111', 2] self.org_management_service.update_org(org) self.mock_update.assert_called_once_with(org) def test_delete_org(self): self.org_management_service.delete_org('111') self.mock_delete.assert_called_once_with('111') def test_read_org_not_found(self): self.mock_read.side_effect = NotFound('Org bad does not exist') # TEST: Execute the service operation call with self.assertRaises(NotFound) as cm: self.org_management_service.read_org('bad') ex = cm.exception self.assertEqual(ex.message, 'Org bad does not exist') self.mock_read.assert_called_once_with('bad', '') def test_delete_org_not_found(self): self.mock_delete.side_effect = NotFound('Org bad does not exist') # TEST: Execute the service operation call with self.assertRaises(NotFound) as cm: self.org_management_service.delete_org('bad') ex = cm.exception self.assertEqual(ex.message, 'Org bad does not exist') self.mock_delete.assert_called_once_with('bad')