Exemplo n.º 1
0
class TestGenerateRepositoriesJSON(unittest.TestCase):
    def setUp(self):
        self.docker_client = mock.Mock()
        self.log = mock.Mock()
        self.image = "whatever"
        self.squash = Squash(self.log, self.image, self.docker_client)

    def test_generate_json(self):
        image_id = '12323dferwt4awefq23rasf'
        with mock.patch.object(six.moves.builtins, 'open',
                               mock.mock_open()) as mock_file:
            self.squash._generate_repositories_json('file', image_id, 'name',
                                                    'tag')
            mock_file().write.assert_called_once_with(
                '{"name": {"tag": "12323dferwt4awefq23rasf"}}')

    def test_handle_empty_image_id(self):
        with mock.patch.object(six.moves.builtins, 'open',
                               mock.mock_open()) as mock_file:
            with self.assertRaises(SquashError) as cm:
                self.squash._generate_repositories_json(
                    'file', None, 'name', 'tag')

            self.assertEquals(str(cm.exception),
                              'Provided image id cannot be null')
            mock_file().write.assert_not_called()
Exemplo n.º 2
0
class TestGenerateRepositoriesJSON(unittest.TestCase):

    def setUp(self):
        self.docker_client = mock.Mock()
        self.log = mock.Mock()
        self.image = "whatever"
        self.squash = Squash(self.log, self.image, self.docker_client)

    def test_generate_json(self):
        image_id = '12323dferwt4awefq23rasf'
        with mock.patch.object(six.moves.builtins, 'open', mock.mock_open()) as mock_file:
            self.squash._generate_repositories_json(
                'file', image_id, 'name', 'tag')
            mock_file().write.assert_called_once_with(
                '{"name": {"tag": "12323dferwt4awefq23rasf"}}')

    def test_handle_empty_image_id(self):
        with mock.patch.object(six.moves.builtins, 'open', mock.mock_open()) as mock_file:
            with self.assertRaises(SquashError) as cm:
                self.squash._generate_repositories_json(
                    'file', None, 'name', 'tag')

            self.assertEquals(
                str(cm.exception), 'Provided image id cannot be null')
            mock_file().write.assert_not_called()