def test_option_single_value(self): # Support multiple values for option in [OPTION_SAVE, OPTION_IP, OPTION_PORT]: option = option.strip('-') options = fetchtv.Options([f'--{option}="wibble"']) self.assertEqual(options.__getattribute__(option), 'wibble') options = fetchtv.Options([f'--{option}="wibble, wobble, rabble"']) self.assertEqual(options.__getattribute__(option), 'wibble, wobble, rabble')
def test_option_multi_value(self): # Support multiple values for option in [OPTION_FOLDER, OPTION_TITLE, OPTION_EXCLUDE]: option = option.strip('-') options = fetchtv.Options([f'--{option}="wibble"']) self.assertEqual(options.__getattribute__(option), ['wibble']) options = fetchtv.Options([f'--{option}="wibble, wobble, rabble"']) self.assertEqual(options.__getattribute__(option), ['wibble', 'wobble', 'rabble'])
def test_no_recordings_folder(self): fetch_server = Mock() fetch_server.url = URL_NO_RECORDINGS options = fetchtv.Options([CMD_RECORDINGS]) results = fetchtv.get_fetch_recordings(fetch_server, options) fetchtv.print_recordings(results) self.assertEqual(0, len(results))
def test_get_shows(self): fetch_server = Mock() fetch_server.url = URL_DUMMY options = fetchtv.Options([CMD_SHOWS]) results = fetchtv.get_fetch_recordings(fetch_server, options) fetchtv.print_recordings(results) self.assertEqual(8, len(results))
def test_get_all_recordings(self): fetch_server = Mock() fetch_server.url = URL_DUMMY options = fetchtv.Options([CMD_RECORDINGS]) results = fetchtv.get_fetch_recordings(fetch_server, options) fetchtv.print_recordings(results) self.assertEqual(8, len(results)) self.assertEqual(134, len(results[4]['items']))
def test_exclude_one_show(self): fetch_server = Mock() fetch_server.url = URL_DUMMY options = fetchtv.Options( [CMD_RECORDINGS, f'{OPTION_EXCLUDE}="{SHOW_ONE}"']) results = fetchtv.get_fetch_recordings(fetch_server, options) fetchtv.print_recordings(results) self.assertEqual(7, len(results))
def test_get_shows_json(self): fetch_server = Mock() fetch_server.url = URL_DUMMY options = fetchtv.Options([CMD_SHOWS, OPTION_JSON]) results = fetchtv.get_fetch_recordings(fetch_server, options) output = fetchtv.print_recordings(results) output = json.loads(output) self.assertEqual(8, len(output))
def test_get_one_show_recording(self): fetch_server = Mock() fetch_server.url = URL_DUMMY options = fetchtv.Options( [CMD_RECORDINGS, f'{OPTION_FOLDER}="{SHOW_ONE}"']) results = fetchtv.get_fetch_recordings(fetch_server, options) fetchtv.print_recordings(results) self.assertEqual(1, len(results)) self.assertEqual(134, len(results[0]['items']))
def test_get_two_show_recording(self): fetch_server = Mock() fetch_server.url = URL_DUMMY options = fetchtv.Options( [CMD_RECORDINGS, f'{OPTION_FOLDER}="{SHOW_ONE}, {SHOW_TWO}"']) results = fetchtv.get_fetch_recordings(fetch_server, options) fetchtv.print_recordings(results) self.assertEqual(3, len( results)) # Test data returns LEGO Masters and Lego Masters....
def test_get_recordings_items_json(self): fetch_server = Mock() fetch_server.url = URL_DUMMY options = fetchtv.Options([CMD_IS_RECORDING, OPTION_JSON]) results = fetchtv.get_fetch_recordings(fetch_server, options) output = fetchtv.print_recordings(results) output = json.loads(output) self.assertEqual(1, len(output)) self.assertEqual(1, len(output[0]['items']))
def test_exclude_two_shows(self): fetch_server = Mock() fetch_server.url = URL_DUMMY options = fetchtv.Options( [CMD_RECORDINGS, f'{OPTION_EXCLUDE}="{SHOW_ONE}, {SHOW_TWO}"']) results = fetchtv.get_fetch_recordings(fetch_server, options) fetchtv.print_recordings(results) self.assertEqual( 5, len(results) ) # Test data has LEGO Masters and Lego Masters - both are matched
def test_get_two_recording_item(self): fetch_server = Mock() fetch_server.url = URL_DUMMY options = fetchtv.Options([ CMD_RECORDINGS, f'{OPTION_FOLDER}="{SHOW_ONE}"', f'{OPTION_TITLE}="{SHOW_ONE_EP_ONE}, {SHOW_ONE_EP_TWO}"' ]) results = fetchtv.get_fetch_recordings(fetch_server, options) fetchtv.print_recordings(results) self.assertEqual(1, len(results)) self.assertEqual(2, len(results[0]['items']))
def test_command_order(self): # Command precedence is help, info, recordings, shows options = fetchtv.Options( [CMD_INFO, CMD_RECORDINGS, CMD_SHOWS, CMD_HELP]) self.assertTrue(options.help) # Use first valid command self.assertFalse(options.recordings) self.assertFalse(options.shows) self.assertFalse(options.info) options = fetchtv.Options([CMD_SHOWS, CMD_RECORDINGS, CMD_INFO]) self.assertTrue(options.info) # Use first valid command self.assertFalse(options.help) self.assertFalse(options.recordings) self.assertFalse(options.shows) options = fetchtv.Options([CMD_SHOWS, CMD_RECORDINGS]) self.assertTrue(options.shows) # Use first valid command self.assertFalse(options.help) self.assertFalse(options.info) self.assertFalse(options.recordings)
def test_get_episode(self): fetch_server = fetchtv.discover_fetch(FETCHTV_IP, FETCHTV_PORT) with patch('fetchtv_upnp.download_file', Mock()): results = fetchtv.get_fetch_recordings(fetch_server, fetchtv.Options( [VAL_IP, VAL_PORT, f'{OPTION_FOLDER}="{SHOW_ONE}"', f'{OPTION_TITLE}="{SHOW_ONE_EP_TWO}"', CMD_RECORDINGS, OPTION_OVERWRITE, f'{OPTION_SAVE}="{SAVE_FOLDER}"'])) # Contains 1 show self.assertTrue( len(list(result for result in results if result['title'] in [SHOW_ONE])) == 1) # Contains 1 episode items = list(result for result in results if result['title'] == SHOW_ONE)[0]['items'] self.assertTrue(len(items) == 1) self.assertTrue(len(list(item for item in items if item.title.startswith(SHOW_ONE_EP_TWO))) == 1)
def test_get_shows_episodes(self): fetch_server = fetchtv.discover_fetch(FETCHTV_IP, FETCHTV_PORT) results = fetchtv.get_fetch_recordings( fetch_server, fetchtv.Options([VAL_IP, VAL_PORT, f'{OPTION_FOLDER}="{SHOW_ONE}, {SHOW_TWO}"', f'{OPTION_TITLE}="{SHOW_ONE_EP_ONE}, {SHOW_ONE_EP_TWO}"', CMD_RECORDINGS, OPTION_OVERWRITE, f'{OPTION_SAVE}="{SAVE_FOLDER}"'])) # Contains both shows self.assertTrue(len(list(result for result in results if result['title'] in [SHOW_ONE, SHOW_TWO])) == 2) # Contains both episodes items = list(result for result in results if result['title'] == SHOW_ONE)[0]['items'] self.assertTrue(len(items) == 2) self.assertTrue(len(list(item for item in items if item.title.startswith(SHOW_ONE_EP_ONE))) == 1) self.assertTrue(len(list(item for item in items if item.title.startswith(SHOW_ONE_EP_TWO))) == 1)
def test_get_recordings(self): fetch_server = fetchtv.discover_fetch(ip=FETCHTV_IP, port=FETCHTV_PORT) recordings = fetchtv.get_fetch_recordings(fetch_server, fetchtv.Options('')) self.assertTrue(recordings)
def test_command_values(self): options = fetchtv.Options([f'{CMD_HELP}=fred']) self.assertTrue(options.help)
def test_option_strip_quotes(self): options = fetchtv.Options([f'{CMD_INFO}="fred"']) self.assertEqual(True, options.info) options = fetchtv.Options([f'{CMD_INFO}=\'fred\'']) self.assertEqual(True, options.info)
def test_option_strip_save(self): options = fetchtv.Options([f'{OPTION_SAVE}]=fred' + os.path.sep]) self.assertEqual(options.save, 'fred')