Skip to content
Snippets Groups Projects
Commit 521cd6c8 authored by jim20's avatar jim20
Browse files

fixed pylint errors

parent 1cdbba9f
No related branches found
No related tags found
1 merge request!1Implementation of Assignment 2.0
......@@ -7,18 +7,27 @@ from scraper import scrape_book_page, scrape_author_page, url_in_robots_file
from command import check_if_author, check_if_book
class Test(unittest.TestCase):
"""
Test class for most functionality aside from database handling
"""
def test_url_in_robots_file(self):
URL = 'https://www.goodreads.com/book/show/52976360-coronavirus-and-christ'
flag = url_in_robots_file(URL)
"""
test
"""
url = 'https://www.goodreads.com/book/show/52976360-coronavirus-and-christ'
flag = url_in_robots_file(url)
self.assertEqual(flag, True)
def test_url_in_robots_file2(self):
URL = 'https://www.goodreads.com/book/show/3735293-clean-code'
flag = url_in_robots_file(URL)
"""
test
"""
url = 'https://www.goodreads.com/book/show/3735293-clean-code'
flag = url_in_robots_file(url)
self.assertEqual(flag, False)
def test_scrape_book_page(self):
"""
test
"""
url = 'https://www.goodreads.com/book/show/3735293-clean-code'
ret_arr = scrape_book_page(url)
self.assertEqual(ret_arr[0], 'https://www.goodreads.com/book/show/3735293-clean-code')
......@@ -29,17 +38,20 @@ class Test(unittest.TestCase):
self.assertEqual(ret_arr[5], 'Robert C. Martin')
self.assertEqual(ret_arr[9], 'https://i.gr-assets.com/images/S/compressed.photo.goodreads.com/books/1436202607l/3735293._SX318_.jpg')
time.sleep(40)
def test_scrape_book_page2(self):
"""
test
"""
url = 'https://www.goodreads.com/author/show/45372.Robert_C_Martin'
try:
ret_arr = scrape_book_page(url)
except:
ret_arr = None
self.assertEqual(ret_arr, None)
def test_scrape_author_page(self):
"""
test
"""
url = 'https://www.goodreads.com/author/show/45372.Robert_C_Martin'
ret_arr = scrape_author_page(url)
self.assertEqual(ret_arr[0], 'Robert C. Martin')
......@@ -50,16 +62,20 @@ class Test(unittest.TestCase):
#self.assertEqual(retArr[5], '2093')
self.assertEqual(ret_arr[6], 'https://images.gr-assets.com/authors/1490470967p5/45372.jpg')
time.sleep(40)
def test_scrape_author_page2(self):
"""
test
"""
url = 'https://www.goodreads.com/book/show/3735293-clean-code'
try:
ret_arr = scrape_author_page(url)
ret_arr = scrape_author_page(url)
except:
ret_arr = None
self.assertEqual(ret_arr, None)
def test_handle_check_author(self):
"""
test
"""
author = {"name": 'bob',
"author_url" : 'bob.com',
"author_id" : '1234',
......@@ -71,8 +87,10 @@ class Test(unittest.TestCase):
"author_books" : ''}
flag = check_if_author(author)
self.assertEqual(flag, True)
def test_handle_check_author2(self):
"""
test
"""
book = {"book_url": 'book.com',
"title" : 'book',
"book_id" : '123',
......@@ -86,8 +104,10 @@ class Test(unittest.TestCase):
"similar_books" : ''}
flag = check_if_author(book)
self.assertEqual(flag, False)
def test_handle_check_book(self):
"""
test
"""
book = {"book_url": 'book.com',
"title" : 'book',
"book_id" : '123',
......@@ -101,8 +121,10 @@ class Test(unittest.TestCase):
"similar_books" : ''}
flag = check_if_book(book)
self.assertEqual(flag, True)
def test_handle_check_book2(self):
"""
test
"""
author = {"name": 'bob',
"author_url" : 'bob.com',
"author_id" : '1234',
......@@ -115,4 +137,5 @@ class Test(unittest.TestCase):
flag = check_if_book(author)
self.assertEqual(flag, False)
if __name__ == "__main__":
unittest.main()
\ No newline at end of file
unittest.main()
\ No newline at end of file
File deleted
File deleted
......@@ -20,7 +20,7 @@ def check_if_author(document):
"""
return bool('author_id' in document.keys())
def read_json(arg):
"""
"""
Function to handle reading a JSON File and updating
or creating new entries in the MongoDB database
"""
......
......@@ -11,17 +11,14 @@ def get_key():
"""
load_dotenv("./key.env")
return os.getenv("SECRET_KEY")
def handle_read_books(json_file):
"""
This function handles when a book is being created or an already existing book is being updated in the MongoDB database.
"""
client = pymongo.MongoClient(get_key())
database = client.GoodReadData
collection = database.Books
collection.update(json_file, json_file, upsert = True)
def handle_read_authors(json_file):
"""
This function handles when an author is being created or an already existing book is being updated in the MongoDB database.
......@@ -30,7 +27,6 @@ def handle_read_authors(json_file):
database = client.GoodReadData
collection = database.Authors
collection.update(json_file, json_file, upsert = True)
def database_book_handler(ret_arr1):
"""
This function handles the web scraped data of a book and transfers it into the MongoDB database.
......@@ -67,7 +63,6 @@ def database_author_handler(ret_arr1):
"related_authors" : ret_arr1[7],
"author_books" : ret_arr1[8],}
collection.update(author, author, upsert = True)
if __name__ == "__main__":
print(get_key())
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment