Esempio n. 1
0
 def setUp(self):
     self.api = RepoGroupDistributorAPI(mock.MagicMock())
Esempio n. 2
0
 def setUp(self):
     self.api = RepoGroupDistributorAPI(mock.MagicMock())
Esempio n. 3
0
class TestRepoGroupDistributorAPI(unittest.TestCase):
    """
    A set of tests for the RepoGroupDistributorAPI
    """
    def setUp(self):
        self.api = RepoGroupDistributorAPI(mock.MagicMock())

    def test_distributors(self):
        """
        Test that the server is called with the expected path and that the
        RepoGroupDistributorAPI.distributors method passes the server return value back up.
        """
        result = self.api.distributors('group_id')
        expected_path = self.api.PATH % 'group_id'
        self.api.server.GET.assert_called_once_with(expected_path)
        self.assertEqual(result, self.api.server.GET.return_value)

    def test_create(self):
        """
        Test creating a distributor and associating it with a group
        """
        # Setup
        group_id = 'test_id'
        expected_path = self.api.PATH % group_id
        distributor_type = 'fake_type'
        distributor_config = {'fake': 'config'}
        expected_data = {
            distributor_constants.DISTRIBUTOR_TYPE_ID_KEY: distributor_type,
            distributor_constants.DISTRIBUTOR_CONFIG_KEY: distributor_config,
            distributor_constants.DISTRIBUTOR_ID_KEY: None
        }

        # Test
        result = self.api.create(group_id, distributor_type,
                                 distributor_config)
        self.api.server.POST.assert_called_once_with(expected_path,
                                                     expected_data)
        self.assertEqual(result, self.api.server.POST.return_value)

    def test_distributor(self):
        """
        Test retrieving a distributor that is associated with a group
        """
        # Setup
        group_id, distributor_id = 'test_id', 'test_distributor_id'
        expected_path = self.api.PATH % group_id + distributor_id + '/'

        # Test
        result = self.api.distributor(group_id, distributor_id)
        self.api.server.GET.assert_called_once_with(expected_path)
        self.assertEqual(result, self.api.server.GET.return_value)

    def test_delete(self):
        """
        Test removing a distributor that is associated with a group
        """
        # Setup
        group_id, distributor_id = 'test_id', 'test_distributor_id'
        expected_path = self.api.PATH % group_id + distributor_id + '/'

        # Test
        result = self.api.delete(group_id, distributor_id)
        self.api.server.DELETE.assert_called_once_with(expected_path)
        self.assertEqual(result, self.api.server.DELETE.return_value)

    def test_update(self):
        """
        Test updating a distributor that is associated with a group
        """
        # Setup
        group_id, distributor_id = 'test_id', 'test_distributor_id'
        distributor_config = {'fake': 'config'}
        expected_path = self.api.PATH % group_id + distributor_id + '/'

        # Test
        result = self.api.update(group_id, distributor_id, distributor_config)
        self.api.server.PUT.assert_called_once_with(expected_path,
                                                    distributor_config)
        self.assertEqual(result, self.api.server.PUT.return_value)
Esempio n. 4
0
class TestRepoGroupDistributorAPI(unittest.TestCase):
    """
    A set of tests for the RepoGroupDistributorAPI
    """
    def setUp(self):
        self.api = RepoGroupDistributorAPI(mock.MagicMock())

    def test_distributors(self):
        """
        Test that the server is called with the expected path and that the
        RepoGroupDistributorAPI.distributors method passes the server return value back up.
        """
        result = self.api.distributors('group_id')
        expected_path = self.api.PATH % 'group_id'
        self.api.server.GET.assert_called_once_with(expected_path)
        self.assertEqual(result, self.api.server.GET.return_value)

    def test_create(self):
        """
        Test creating a distributor and associating it with a group
        """
        # Setup
        group_id = 'test_id'
        expected_path = self.api.PATH % group_id
        distributor_type = 'fake_type'
        distributor_config = {'fake': 'config'}
        expected_data = {distributor_constants.DISTRIBUTOR_TYPE_ID_KEY: distributor_type,
                         distributor_constants.DISTRIBUTOR_CONFIG_KEY: distributor_config,
                         distributor_constants.DISTRIBUTOR_ID_KEY: None}

        # Test
        result = self.api.create(group_id, distributor_type, distributor_config)
        self.api.server.POST.assert_called_once_with(expected_path, expected_data)
        self.assertEqual(result, self.api.server.POST.return_value)

    def test_distributor(self):
        """
        Test retrieving a distributor that is associated with a group
        """
        # Setup
        group_id, distributor_id = 'test_id', 'test_distributor_id'
        expected_path = self.api.PATH % group_id + distributor_id + '/'

        # Test
        result = self.api.distributor(group_id, distributor_id)
        self.api.server.GET.assert_called_once_with(expected_path)
        self.assertEqual(result, self.api.server.GET.return_value)

    def test_delete(self):
        """
        Test removing a distributor that is associated with a group
        """
        # Setup
        group_id, distributor_id = 'test_id', 'test_distributor_id'
        expected_path = self.api.PATH % group_id + distributor_id + '/'

        # Test
        result = self.api.delete(group_id, distributor_id)
        self.api.server.DELETE.assert_called_once_with(expected_path)
        self.assertEqual(result, self.api.server.DELETE.return_value)

    def test_update(self):
        """
        Test updating a distributor that is associated with a group
        """
        # Setup
        group_id, distributor_id = 'test_id', 'test_distributor_id'
        distributor_config = {'fake': 'config'}
        expected_path = self.api.PATH % group_id + distributor_id + '/'

        # Test
        result = self.api.update(group_id, distributor_id, distributor_config)
        self.api.server.PUT.assert_called_once_with(expected_path, distributor_config)
        self.assertEqual(result, self.api.server.PUT.return_value)