Exemplo n.º 1
0
    def test_get_distributor_resource_with_nonexistent_distributor(
            self, mock_factory):
        """
        Distributor Resource should raise a MissingResource if distributor does not exist.
        """
        mock_manager = mock.MagicMock()
        mock_manager.distributors.return_value = [{
            'id': 'mock_distriburor_1'
        }, {
            'id': 'mock_distributor_2'
        }]
        mock_factory.plugin_manager.return_value = mock_manager
        request = mock.MagicMock()

        distributor_resource = DistributorResourceView()
        try:
            distributor_resource.get(request, 'nonexistent_distributor')
        except MissingResource, response:
            pass
Exemplo n.º 2
0
    def test_get_distributor_resource_with_existing_distributor(
            self, mock_factory, mock_serial):
        """
        Distributor Resource should generate a json response from the distributor data.
        """
        mock_manager = mock.MagicMock()
        mock_manager.distributors.return_value = [{
            'id': 'mock_distributor_1'
        }, {
            'id': 'mock_distributor_2'
        }]
        mock_factory.plugin_manager.return_value = mock_manager
        request = mock.MagicMock()
        request.get_full_path.return_value = '/mock/path/'

        distributor_resource = DistributorResourceView()
        response = distributor_resource.get(request, 'mock_distributor_2')

        expected_content = {'id': 'mock_distributor_2', '_href': '/mock/path/'}
        mock_serial.assert_called_once_with(expected_content)
        self.assertTrue(response is mock_serial.return_value)