def Get_quotes(author, numPosts): obj = GoodRead() obj.set_base_url("https://www.goodreads.com/") print("---------Top " + str(numPosts) + " Quotes of " + author + "---------") print("-------------------------------------------------") print('') try: #if obj.check_author_type(author): # raise ValueError("Author name should only contain alphabetic characters!") if all(x.isdigit() for x in str(author)): obj.exitcondition = True raise ValueError( "Author name should only contain alphabetic characters!") obj.set_author_query(str(author)) if not all(x.isdigit() for x in str(numPosts)): obj.exitcondition = True raise ValueError("Number of Posts should be an Integer >0") if not obj.exitcondition: obj.set_numQuotes(int(numPosts)) if not obj.exitcondition: obj.set_query_url() if not obj.exitcondition: obj.set_quotesquery_name() if not obj.exitcondition: obj.get_top_quotes(obj.author_query, obj.numQuotes, obj.query_url, obj.filename) return obj.filename except ValueError as e: print(e)
def test_blank_link_get_quotes(self): obj = GoodRead() self.assertRaises( obj.get_top_quotes("Mark XYZ", 0, "", "abc.json"))
def Authenticate(email,password): obj = GoodRead() obj.set_base_url("https://www.goodreads.com/") obj.set_email(email) obj.set_password(password) obj.set_credential()
def test_wrong_link_get_quotes(self): obj = GoodRead() self.assertRaises( obj.get_top_quotes("Mark XYZ", 0, "https://www.xxxxxxxxxxxs.com/quotes/search?&q=mark+twain&commit=Search", "abc.json"))
def test_email(self): obj = GoodRead() self.assertEqual(obj.set_email("*****@*****.**"), "*****@*****.**")
def test_invalid_numpostalpha(self): obj = GoodRead() self.assertRaises(obj.set_numQuotes('a'))
def test_invalid_numpostNegativeInt(self): obj = GoodRead() self.assertRaises(obj.set_numQuotes(-10))
def test_random_author_get_quotes(self): obj = GoodRead() self.assertRaises(obj.get_top_quotes("Mark XYZ", 0,"https://www.goodreads.com/quotes/search?&q=mark+twain&commit=Search","abc.json"))
def test_invalid_authorNegativeInt(self): obj = GoodRead() self.assertRaises(obj.set_author_query(-1))
def test_blank_author_get_quotes(self): obj = GoodRead() obj.query_url = "https://www.goodreads.com/quotes/search?&q=mark+twain&commit=Search" self.assertRaises(obj.get_top_quotes("", 8,obj.query_url,"abc.json"))
def test_wrong_password(self): obj = GoodRead() obj.set_email("*****@*****.**") obj.set_password("abc") obj.set_base_url("https://www.goodreads.com/") self.assertEqual(obj.authenticate(obj.email, obj.password, obj.sign_in_url, obj.redirect_url), False)
def test_empty_email(self): obj = GoodRead() self.assertRaises(obj.set_email(""))
def test_empty_password(self): obj = GoodRead() self.assertRaises(obj.set_password(""))
def test_password(self): obj = GoodRead() self.assertEqual(obj.set_password("rupam.K@19"), "rupam.K@19")