class MediaBootAnimationTest(unittest.TestCase): def setUp(self): media_file = os.path.join(__tests_root__, 'res', 'bootanimation.zip') self.media = Media(MagicMock(), 'test-boot', 'bootanimation', 1, media_file) def test_media_is_valid(self): self.assertIsNone(self.media.validate()) def test_media_content_type(self): self.assertEqual(self.media.get_content_type(), 'application/zip') def test_media_type(self): self.assertEqual(self.media.get_type(), 'media') def test_media_pretty_type(self): self.assertEqual(self.media.get_pretty_type(), 'Boot animation') def test_media_sub_type(self): self.assertEqual(self.media.get_sub_type(), 'bootanimation') def test_media_name(self): self.assertEqual(self.media.get_name(), 'test-boot') def test_media_version(self): self.assertEqual(self.media.get_version(), '1') def test_media_meta_data(self): meta_data = { 'media': { 'type': self.media.get_sub_type(), }, } self.assertEqual(self.media.get_registry_meta_data(), meta_data)
class MediaSplashTest(unittest.TestCase): def setUp(self): media_file = os.path.join(__tests_root__, 'res/splash.png') self.media = Media(MagicMock(), 'test-splash', 'splash', 1, media_file) def test_media_is_valid(self): self.assertIsNone(self.media.validate()) def test_media_content_type(self): self.assertEqual(self.media.get_content_type(), 'image/png') def test_media_type(self): self.assertEqual(self.media.get_type(), 'media') def test_media_sub_type(self): self.assertEqual(self.media.get_sub_type(), 'splash') def test_media_name(self): self.assertEqual(self.media.get_name(), 'test-splash') def test_media_version(self): self.assertEqual(self.media.get_version(), '1') def test_media_meta_data(self): meta_data = { 'media': { 'type': self.media.get_sub_type(), }, } self.assertEqual(self.media.get_registry_meta_data(), meta_data)
def prepare(self): self._maybe_inject_version() media = Media.parse(self.config, self.name, self.type, self.version, self.media_file) media.already_registered = self.already_registered return [media], media
def test_media_registers_successfully(self): media_file = os.path.join(__tests_root__, 'res', 'bootanimation.zip') command = RegisterMediaCommand(self.config, 'Boot Anim', 'bootanimation', '1', media_file) command.run() self.config.api.upload_artifact.assert_called_with( media_file, Media.parse(self.config, 'Boot anim', 'bootanimation', '1', media_file))
def test_latest_non_existant_media_registers_successfully(self): self.config.api.get_highest_artifact = MagicMock(return_value=None) media_file = os.path.join(__tests_root__, 'res', 'bootanimation.zip') command = RegisterMediaCommand( self.config, 'Boot Anim', 'bootanimation', 'latest', media_file) command.run() self.config.api.upload_artifact.assert_called_with( media_file, Media.parse(self.config, 'Boot anim', 'bootanimation', '1', media_file))
def test__upload_artifact__media_requests_are_correct(self): media_file = os.path.join(__tests_root__, 'res', 'bootanimation.zip') artifact = Media.parse(MagicMock(), 'Boot Anim', 'bootanimation', '1', media_file) self.handler.get = MagicMock(return_value={ 'signed_request': 'signed_request', 'url': 'signed_url' }) self.api.upload_artifact(media_file, artifact) self.handler.get.assert_called_with( 'url_root/mason-test/Boot Anim/1?type=media&noContentType=true', headers={ 'Content-Type': 'application/json', 'Content-MD5': 'HzF5jT1tn8nOtt33IcFWaQ==', 'Authorization': 'Bearer Foobar' }) self.handler.put.assert_called_with( 'signed_request', media_file, headers={'Content-MD5': 'HzF5jT1tn8nOtt33IcFWaQ=='}) self.handler.post.assert_called_with( 'url_root/mason-test', headers={ 'Content-Type': 'application/json', 'Authorization': 'Bearer Foobar' }, json={ 'name': 'Boot Anim', 'version': '1', 'customer': 'mason-test', 'url': 'signed_url', 'type': 'media', 'checksum': { 'sha1': 'e7788dca3a3797fd152825e600047e7cef870d98' }, 'media': { 'type': 'bootanimation' } })
def setUp(self): media_file = os.path.join(__tests_root__, 'res', 'bootanimation.zip') self.media = Media(MagicMock(), 'test-boot', 'bootanimation', 1, media_file)
def setUp(self): media_file = os.path.join(__tests_root__, 'res/splash.png') self.media = Media(MagicMock(), 'test-splash', 'splash', 1, media_file)