def test_myplex_failed_login(mock_urlopen, mock_isfile): """ Test token generation using the credentials in user.ini. """ mock_isfile.return_value = False with patch("__builtin__.open", mock_open(read_data="ExampleToken")): resp = Mock() resp.read.side_effect = ['', ''] mock_urlopen.return_value = resp myplex.MYPLEXSHARED = 'enable' assert myplex.myplex_signin('aaa', 'bbb') is None
def test_generate_token_without_plexshared(mock_urlopen, mock_isfile): """ Test token generation using the credentials in user.ini. """ mock_isfile.return_value = False with patch("__builtin__.open", mock_open(read_data="ExampleToken")): resp = Mock() resp.read.side_effect = [ '<user><authentication-token>Dummy-Auth-Token</authentication-token></user>', '''<Directory type="movie" accessToken="Dummy-Auth-Token" sourceTitle="test"/> <Directory type="movie" accessToken="Dummy-Auth-Token2" sourceTitle="test2"/>''' ] mock_urlopen.return_value = resp myplex.MYPLEXSHARED = 'enable' assert myplex.myplex_signin('aaa', 'bbb') == 'Dummy-Auth-Token2'
# #Get list of artists # itemlist = xmldoc.getElementsByTagName('Directory') # print str(len(itemlist)) + " Total Artists Found" # for item in itemlist: # musictitle = item.attributes['title'].value # #musictitle = re.sub(r'[^\x00-\x7F]+',' ', musictitle) # musictitle = re.sub(r'\&','and', musictitle) # musickey = item.attributes['key'].value if tvscrapetype == "disable" and moviescrapetype == "disable": print "Plex Scraper: No scrapers enabled in config. Scraper process disabled." else: while True: try: if myplexstatus == "enable": plextoken = myplex_signin(myplexusername, myplexpassword) if myplexstatus == "enable" and plextoken == "": print "Plex Scraper: Failed to login to myPlex. Please disable myPlex or enter your correct login." exit() if tvactive == "enable" and tvscrapetype != "disable": tvShowScraper(tvscrapetype) if movieactive == "enable" and moviescrapetype != "disable": movieScraper(moviescrapetype) #if pictureactive=="enable": # photoScraper('recentlyAdded') #if musicactive=="enable": # musicScraper('recentlyAdded') print "Plex Scraper: completed at " + strftime("%Y-%m-%d %H:%M:%S") print "Plex Scraper: Sleeping " + str(scrapetimer) + " Seconds..." time.sleep(scrapetimer)
def test_reading_cached_token(mock_isfile): """ Test for reading token from token.txt file """ mock_isfile.return_value = True with patch("__builtin__.open", mock_open(read_data="ExampleToken")): assert myplex.myplex_signin('aaa', 'aaa') == 'ExampleToken'
def test_singin_with_no_password(mock_isfile): """ Test for no password being populated in the user.ini. """ mock_isfile.return_value = False assert myplex.myplex_signin('aaa', '') is None
def test_signin_with_no_username(mock_isfile): """ Test for no username being populated in the user.ini. """ mock_isfile.return_value = False assert myplex.myplex_signin('', 'aaa') is None