def test_get_agent_unbindings_distributor_deleted(self, m_model): """ Test that AgentManager._unbindings does not raise an exception when the distributor is deleted and returns None as the distributor_type_id. """ m_model.Distributor.objects.get_or_404.side_effect = MissingResource bindings = [ { 'consumer_id': '10', 'repo_id': '20', 'distributor_id': '30', 'binding_config': {} }, { 'consumer_id': '40', 'repo_id': '50', 'distributor_id': '60', 'binding_config': {} }, ] agent_bindings = AgentManager._unbindings(bindings) # validation self.assertTrue(m_model.Distributor.objects.get_or_404.called) self.assertEqual(len(agent_bindings), 2) for binding, agent_binding in itertools.izip(bindings, agent_bindings): self.assertEqual(binding['repo_id'], agent_binding['repo_id']) self.assertEqual(None, agent_binding['type_id'])
def test_get_agent_unbindings(self, m_model): distributor = model.Distributor(distributor_type_id='3838') m_model.Distributor.objects.get_or_404.return_value = distributor bindings = [ { 'consumer_id': '10', 'repo_id': '20', 'distributor_id': '30', 'binding_config': {} }, { 'consumer_id': '40', 'repo_id': '50', 'distributor_id': '60', 'binding_config': {} }, ] agent_bindings = AgentManager._unbindings(bindings) for binding in bindings: m_model.Distributor.objects.get_or_404.assert_any_call( repo_id=binding['repo_id'], distributor_id=binding['distributor_id']) self.assertEqual(len(agent_bindings), 2) for binding, agent_binding in itertools.izip(bindings, agent_bindings): self.assertEqual(binding['repo_id'], agent_binding['repo_id']) self.assertEqual(distributor['distributor_type_id'], agent_binding['type_id'])
def test_get_agent_unbindings_distributor_deleted(self, mock_managers): # Test that AgentManager._unbindings does not raise an exception # when the distributor is deleted and returns None as the distributor_type_id. class MockedRepoDistributorManager: def get_distributor(*args): raise MissingResource() mock_managers.repo_distributor_manager = Mock( return_value=MockedRepoDistributorManager()) # test bindings = [ { 'consumer_id': '10', 'repo_id': '20', 'distributor_id': '30', 'binding_config': {} }, { 'consumer_id': '40', 'repo_id': '50', 'distributor_id': '60', 'binding_config': {} }, ] agent_bindings = AgentManager._unbindings(bindings) # validation self.assertEqual(len(agent_bindings), 2) for binding, agent_binding in itertools.izip(bindings, agent_bindings): self.assertEqual(binding['repo_id'], agent_binding['repo_id']) self.assertEqual(None, agent_binding['type_id'])
def test_get_agent_unbindings_distributor_deleted(self, m_model): """ Test that AgentManager._unbindings does not raise an exception when the distributor is deleted and returns None as the distributor_type_id. """ m_model.Distributor.objects.get_or_404.side_effect = MissingResource bindings = [ {'consumer_id': '10', 'repo_id': '20', 'distributor_id': '30', 'binding_config': {}}, {'consumer_id': '40', 'repo_id': '50', 'distributor_id': '60', 'binding_config': {}}, ] agent_bindings = AgentManager._unbindings(bindings) # validation self.assertTrue(m_model.Distributor.objects.get_or_404.called) self.assertEqual(len(agent_bindings), 2) for binding, agent_binding in itertools.izip(bindings, agent_bindings): self.assertEqual(binding['repo_id'], agent_binding['repo_id']) self.assertEqual(None, agent_binding['type_id'])
def test_get_agent_unbindings(self, m_model): distributor = model.Distributor(distributor_type_id='3838') m_model.Distributor.objects.get_or_404.return_value = distributor bindings = [ {'consumer_id': '10', 'repo_id': '20', 'distributor_id': '30', 'binding_config': {}}, {'consumer_id': '40', 'repo_id': '50', 'distributor_id': '60', 'binding_config': {}}, ] agent_bindings = AgentManager._unbindings(bindings) for binding in bindings: m_model.Distributor.objects.get_or_404.assert_any_call( repo_id=binding['repo_id'], distributor_id=binding['distributor_id']) self.assertEqual(len(agent_bindings), 2) for binding, agent_binding in itertools.izip(bindings, agent_bindings): self.assertEqual(binding['repo_id'], agent_binding['repo_id']) self.assertEqual(distributor['distributor_type_id'], agent_binding['type_id'])
def test_get_agent_unbindings_distributor_deleted(self, mock_repo_distributor_manager): # Test that AgentManager._unbindings does not raise an exception # when the distributor is deleted and returns None as the distributor_type_id. def test_get_distributor(): raise MissingResource() mock_repo_distributor_manager.get_distributor = test_get_distributor # test bindings = [ {'consumer_id': '10', 'repo_id': '20', 'distributor_id': '30', 'binding_config': {}}, {'consumer_id': '40', 'repo_id': '50', 'distributor_id': '60', 'binding_config': {}}, ] agent_bindings = AgentManager._unbindings(bindings) # validation self.assertEqual(len(agent_bindings), 2) for binding, agent_binding in itertools.izip(bindings, agent_bindings): self.assertEqual(binding['repo_id'], agent_binding['repo_id']) self.assertEqual(None, agent_binding['type_id'])
def test_get_agent_unbindings(self, mock_factory): distributor = {'distributor_type_id': '3838'} mock_distributor_manager = Mock() mock_distributor_manager.get_distributor = Mock( return_value=distributor) mock_factory.repo_distributor_manager = Mock( return_value=mock_distributor_manager) # test manager bindings = [ { 'consumer_id': '10', 'repo_id': '20', 'distributor_id': '30', 'binding_config': {} }, { 'consumer_id': '40', 'repo_id': '50', 'distributor_id': '60', 'binding_config': {} }, ] agent_bindings = AgentManager._unbindings(bindings) # validation for binding in bindings: mock_distributor_manager.get_distributor.assert_any_call( binding['repo_id'], binding['distributor_id']) self.assertEqual(len(agent_bindings), 2) for binding, agent_binding in itertools.izip(bindings, agent_bindings): self.assertEqual(binding['repo_id'], agent_binding['repo_id']) self.assertEqual(distributor['distributor_type_id'], agent_binding['type_id'])
def test_get_agent_unbindings(self, mock_factory): distributor = {'distributor_type_id': '3838'} mock_distributor_manager = Mock() mock_distributor_manager.get_distributor = Mock(return_value=distributor) mock_factory.repo_distributor_manager = Mock(return_value=mock_distributor_manager) # test manager bindings = [ {'consumer_id': '10', 'repo_id': '20', 'distributor_id': '30', 'binding_config': {}}, {'consumer_id': '40', 'repo_id': '50', 'distributor_id': '60', 'binding_config': {}}, ] agent_bindings = AgentManager._unbindings(bindings) # validation for binding in bindings: mock_distributor_manager.get_distributor.assert_any_call( binding['repo_id'], binding['distributor_id']) self.assertEqual(len(agent_bindings), 2) for binding, agent_binding in itertools.izip(bindings, agent_bindings): self.assertEqual(binding['repo_id'], agent_binding['repo_id']) self.assertEqual(distributor['distributor_type_id'], agent_binding['type_id'])