def test_private_get_addon(self, mock_get_addon): fake_addon = fakes.FakeAddon() mock_get_addon.return_value = fake_addon h = helper.DRMHelper() result = h._get_addon() mock_get_addon.assert_called_once_with('inputstream.adaptive') self.assertEqual(result, fake_addon)
def test_get_wvcdm(self, is_dir, is_file, dialog, mock_get_addon, mock_json_rpc, temp_file, translate_path, prog_download, cdm_command, unzip_win): fake_addon = fakes.FakeAddon() for s in fakes.SYSTEMS: h = helper.DRMHelper() if not h._is_wv_drm_supported(): continue mock_get_addon.return_value = fake_addon mock_json_rpc.return_value = json.dumps(fakes.IA_ENABLED) responses.add(responses.GET, config.CMD_CURRENT_VERSION_URL, body='9.9.9.9999') translate_path.side_effect = get_trans_path( fakes.TRANS_PATH_ARGS[0], s.get('system')) with mock.patch.object(helper.DRMHelper, '_get_wvcdm_paths', return_value=fakes.TRANSLATED_PATHS.get( s.get('system'))): with mock.patch.object(helper.DRMHelper, '_get_system', return_value=s.get('system')): with mock.patch.object( helper.DRMHelper, '_get_arch', return_value=s.get('expected_arch')): is_dir.return_value = True is_file.return_value = False result = h._get_wvcdm() temp_file.assert_called() dialog.assert_called() prog_download.assert_called() assert cdm_command.called or unzip_win.called self.assertEqual(result, True)
def test_install_addon(self, mock_executebuiltin): fake_addon = fakes.FakeAddon() with mock.patch.object(helper.DRMHelper, '_get_addon', return_value=fake_addon): h = helper.DRMHelper() result = h._install_addon() self.assertEqual(result, fake_addon)
def test_get_wvcdm_paths(self): for system in fakes.SYSTEMS: rv = fakes.TRANSLATED_PATHS.get(system.get('system')) with mock.patch.object(helper.DRMHelper, '_get_wvcdm_paths', return_value=rv): fake_addon = fakes.FakeAddon() h = helper.DRMHelper() cdm_paths = h._get_wvcdm_paths(fake_addon) self.assertEqual(rv[0], cdm_paths[0])
def test_get_wv_cdm_path(self, temp_file): for system in fakes.SYSTEMS: rv = fakes.TRANSLATED_PATHS.get(system.get('system')) with mock.patch.object(helper.DRMHelper, '_get_wvcdm_paths', return_value=rv): fake_addon = fakes.FakeAddon() h = helper.DRMHelper() cdm_paths = h._get_wvcdm_paths(fake_addon) result = h._get_wvcdm_path(fake_addon, cdm_paths) temp_file.assert_called() self.assertEqual(result, cdm_paths[0])
def test_get_addon_install_ok(self, mock_get_addon): rpc_success = {"result": {"addon": {"enabled": True}}} fake_addon = fakes.FakeAddon() mock_get_addon.return_value = fake_addon with mock.patch.object(helper.DRMHelper, '_execute_json_rpc', return_value=rpc_success): with mock.patch.object(helper.DRMHelper, '_install_addon', return_value=fake_addon): h = helper.DRMHelper() result = h.get_addon() self.assertEqual(result, fake_addon)
def test_get_wvcdm(self, is_dir, is_file, dialog, mock_get_addon, mock_json_rpc, temp_file, translate_path, prog_download, cdm_command, rename_win, mock_kodi_arch): fake_addon = fakes.FakeAddon() for s in fakes.SYSTEMS: h = helper.DRMHelper() mock_get_addon.return_value = fake_addon mock_json_rpc.return_value = json.dumps(fakes.IA_ENABLED) responses.add(responses.GET, config.CDM_CURRENT_VERSION_URL, body=self.MODULE_JSON) translate_path.return_value = get_trans_path( fakes.TRANS_PATH_ARGS[0], s.get('system')) with mock.patch.object(helper.DRMHelper, '_get_wvcdm_paths', return_value=fakes.TRANSLATED_PATHS.get( s.get('system'))): with mock.patch.object(helper.DRMHelper, '_get_system', return_value=s.get('expected_system')): with mock.patch.object( helper.DRMHelper, '_get_arch', return_value=s.get('expected_arch')): mock_kodi_arch.return_value = s.get('expected_arch') is_dir.return_value = True is_file.return_value = False observed = h._get_wvcdm() if (not h._is_wv_drm_supported() or s.get('expected_system') == 'Android'): expected = None else: expected = True temp_file.assert_called_once() temp_file.reset_mock() dialog.assert_called_once() dialog.reset_mock() prog_download.assert_called_once() #print(prog_download.call_args) prog_download.reset_mock() assert cdm_command.called or rename_win.called cdm_command.reset_mock() rename_win.reset_mock() self.assertEqual(expected, observed)
from drmhelper import utils import fakes import mock import testtools import xbmc FAKE_ADDON = fakes.FakeAddon() class UtilsTests(testtools.TestCase): @mock.patch('xbmcaddon.Addon', return_value=FAKE_ADDON) @mock.patch('xbmc.log') def test_log(self, mock_log, mock_addon): utils.log('foo') mock_log.assert_called_once_with('[Test Add-on v0.0.1] foo', level=xbmc.LOGNOTICE) def test_get_info_label(self): with mock.patch('xbmc.getInfoLabel', return_value='foo'): utils.get_info_label('test_label') self.assertEqual(utils.get_info_label('test_label'), 'foo') def test_get_info_label_busy(self): with mock.patch('xbmc.getInfoLabel', return_value='Busy'): utils.get_info_label('test_label') self.assertEqual(utils.get_info_label('test_label'), None)