Skip to content
Snippets Groups Projects
Commit 906aa38a authored by zshan2's avatar zshan2
Browse files

Merge branch 'assignment-2.2' into 'master'

Implementation of assignment-2.2

See merge request !2
parents a8f8fb15 d8e2853e
No related branches found
No related tags found
1 merge request!2Implementation of assignment-2.2
Showing
with 213 additions and 12 deletions
...@@ -5,6 +5,7 @@ from dotenv import load_dotenv ...@@ -5,6 +5,7 @@ from dotenv import load_dotenv
def safe_url(query): def safe_url(query):
""" convert query to URL-safe style """
load_dotenv() load_dotenv()
host = os.getenv('SERVER_HOST') host = os.getenv('SERVER_HOST')
return host + Parser.url_safe(query) return host + Parser.url_safe(query)
...@@ -24,6 +25,7 @@ def get(query): ...@@ -24,6 +25,7 @@ def get(query):
def put(query, json_file): def put(query, json_file):
""" PUT request """
print("PUT: " + query) print("PUT: " + query)
url = safe_url(query) url = safe_url(query)
req = requests.put(url, json=json_file) req = requests.put(url, json=json_file)
...@@ -32,6 +34,7 @@ def put(query, json_file): ...@@ -32,6 +34,7 @@ def put(query, json_file):
def post(query, json_file): def post(query, json_file):
""" POST request """
print("POST: " + query) print("POST: " + query)
url = safe_url(query) url = safe_url(query)
req = requests.post(url, json=json_file) req = requests.post(url, json=json_file)
...@@ -40,6 +43,7 @@ def post(query, json_file): ...@@ -40,6 +43,7 @@ def post(query, json_file):
def delete(query): def delete(query):
""" DELETE request """
print("DELETE: " + query) print("DELETE: " + query)
url = safe_url(query) url = safe_url(query)
req = requests.delete(url) req = requests.delete(url)
......
...@@ -4,6 +4,7 @@ from DataBase import mongoDB as db ...@@ -4,6 +4,7 @@ from DataBase import mongoDB as db
def scrape_api(url_api, book_num_api, author_num_api): def scrape_api(url_api, book_num_api, author_num_api):
""" Function called by other module to run the scraper """
print('Request received, start scraping') print('Request received, start scraping')
book_dict_api = {} book_dict_api = {}
author_dict_api = {} author_dict_api = {}
......
def parse_book_dict_to_json(dictionary): def parse_book_dict_to_json(dictionary):
""" parse books dictionary to json file """
item_list = list(dictionary.items()) item_list = list(dictionary.items())
return_list = [] return_list = []
for items in item_list: for items in item_list:
......
...@@ -16,9 +16,9 @@ def get_db(): ...@@ -16,9 +16,9 @@ def get_db():
def insert_document(docu, opt): def insert_document(docu, opt):
db = get_db() db = get_db()
if opt == 0: if opt == 0:
records = db.test_books records = db.books
elif opt == 1: elif opt == 1:
records = db.test_authors records = db.authors
else: else:
print("failed to get json file: wrong opt for selecting collection") print("failed to get json file: wrong opt for selecting collection")
return return
...@@ -34,9 +34,9 @@ def insert_dicts(dictionary, opt): ...@@ -34,9 +34,9 @@ def insert_dicts(dictionary, opt):
""" """
db = get_db() db = get_db()
if opt == 0: if opt == 0:
records = db.test_books records = db.books
elif opt == 1: elif opt == 1:
records = db.test_authors records = db.authors
else: else:
print("failed to get json file: wrong opt for selecting collection") print("failed to get json file: wrong opt for selecting collection")
return return
...@@ -58,12 +58,13 @@ def update_dicts(opt, identifier, content): ...@@ -58,12 +58,13 @@ def update_dicts(opt, identifier, content):
""" """
db = get_db() db = get_db()
if opt == 0: if opt == 0:
records = db.test_books records = db.books
elif opt == 1: elif opt == 1:
records = db.test_authors records = db.authors
else: else:
print("failed to get json file: wrong opt for selecting collection") print("failed to get json file: wrong opt for selecting collection")
return return
print(content)
result = records.update_one( result = records.update_one(
identifier, identifier,
{"$set": content}, {"$set": content},
...@@ -82,9 +83,9 @@ def get_documents_json(opt, identifier): ...@@ -82,9 +83,9 @@ def get_documents_json(opt, identifier):
""" """
db = get_db() db = get_db()
if opt == 0: if opt == 0:
records = db.test_books records = db.books
elif opt == 1: elif opt == 1:
records = db.test_authors records = db.authors
else: else:
print("failed to get json file: wrong opt for selecting collection") print("failed to get json file: wrong opt for selecting collection")
return json.dumps({}) return json.dumps({})
...@@ -127,10 +128,10 @@ def clean(opt, identifier): ...@@ -127,10 +128,10 @@ def clean(opt, identifier):
""" """
db = get_db() db = get_db()
if opt == 0: if opt == 0:
records = db.test_books records = db.books
elif opt == 1: elif opt == 1:
records = db.test_authors records = db.authors
else: else:
print("failed to get json file: wrong opt for selecting collection") print("failed to get json file: wrong opt for selecting collection")
return return 0
records.delete_many(identifier) return records.delete_many(identifier).deleted_count
# GoodRead Crawler Manual Test
This is a manual test plan for cs242-sp21 assignment2: GoodRead Crawler
## System Requirements
#### OS:
The following OS are appropriate system for running the GoodRead Crawler application and testing.
- Windows 7 or above
- Mac OS X
- Linux
#### Testing Prerequisites
Softwares/applications are required for running the test.
- Python 3
- Javascript
- React JS
## Scenes for Testing
![1](./ManualTestPictures/1(1).png)
## 1.GET function
#### Test1.1
- test content:
Test GET exist book data
- expect result:
Successfully get book data and showing in table
![2](./ManualTestPictures/1(5).png)
#### Test1.2
- test content:
Test GET exist author data
- expect result:
Successfully get author data and showing in table
![3](./ManualTestPictures/1(4).png)
#### Test1.3
- test content:
Test GET unexist book data
- expect result:
Request failed
![4](./ManualTestPictures/1(2).png)
#### Test1.4
- test content:
Test GET unexist author data
- expect result:
Request failed
![5](./ManualTestPictures/1(3).png)
#### Test1.5
- test content:
Test search exist book data with id
- expect result:
Successfully find the data and print in table
![6](./ManualTestPictures/1(6).png)
#### Test1.6
- test content:
Test search exist book data with flexible search condition
- expect result:
Successfully find the data and showing in table
![7](./ManualTestPictures/1(7).png)
#### Test1.7
- test content:
Test search unexist book data
- expect result:
Request failed
![8](./ManualTestPictures/1(8).png)
#### Test1.8
- test content:
Test using scrape in GET command
- expect result:
Request failed
![9](./ManualTestPictures/1(24).png)
## 2.PUT function
#### Test2.1
- test content:
Test PUT update data for exist book documentation
- expect result:
No new document is created, existing document updated
![10](./ManualTestPictures/1(9).png)
![11](./ManualTestPictures/1(10).png)
![12](./ManualTestPictures/1(12).png)
#### Test2.2
- test content:
Test PUT new book documentation
- expect result:
A new book document is created
![13](./ManualTestPictures/1(13).png)
![14](./ManualTestPictures/1(15).png)
#### Test2.3
- test content:
Test PUT update data for exist author documentation
- expect result:
No new document is created, existing document updated
![15](./ManualTestPictures/1(16).png)
![16](./ManualTestPictures/1(17).png)
![17](./ManualTestPictures/1(19).png)
#### Test2.4
- test content:
Test PUT new author documentation
- expect result:
A new author document is created
![18](./ManualTestPictures/1(20).png)
![19](./ManualTestPictures/1(22).png)
## 3.POST function
#### Test3.1
- test content:
Test POST book data
- expect result:
Successfully post new book documtent
![20](./ManualTestPictures/1(26).png)
![21](./ManualTestPictures/1(28).png)
#### Test3.2
- test content:
Test POST author data
- expect result:
Successfully post new author documtent
![22](./ManualTestPictures/1(29).png)
![23](./ManualTestPictures/1(30).png)
#### Test3.3
- test content:
Test Scrape data
- expect result:
New book and author data is added into collections
![24](./ManualTestPictures/1(23).png)
![25](./ManualTestPictures/1(25).png)
#### Test3.4
- test content:
Test the input form of book-type doc can be closed by click 'back' button and another form of author-type can be opened
- expect result:
Successfully changed the form
![26](./ManualTestPictures/1(29).png)
![27](./ManualTestPictures/1(31).png)
## 4.DELETE function
#### Test4.1
- test content:
Test DELETE book data by id
- expect result:
Successfully delete the book data
![28](./ManualTestPictures/1(34).png)
#### Test4.2
- test content:
Test DELETE author data by name
- expect result:
Successfully delete the author data
![29](./ManualTestPictures/1(37).png)
#### Test4.3
- test content:
Test DELETE unexist data
- expect result:
Request failed
![30](./ManualTestPictures/1(38).png)
## 5.Responsive UI Test
#### Test5.1
- test content:
Test main page can fit mobile device
- expect result:
All elements can be fitted in screen of mobile-device size
![31](./ManualTestPictures/1(40).png)
#### Test5.2
- test content:
Test data table can scroll
- expect result:
Data table can be scroll to right and left when the screen's size is not large enough
![32](./ManualTestPictures/1(41).png)
![33](./ManualTestPictures/1(42).png)
![34](./ManualTestPictures/1(43).png)
ManualTestPictures/1(1).png

85.5 KiB

ManualTestPictures/1(10).png

94.5 KiB

ManualTestPictures/1(11).png

98.5 KiB

ManualTestPictures/1(12).png

169 KiB

ManualTestPictures/1(13).png

94.5 KiB

ManualTestPictures/1(14).png

98.4 KiB

ManualTestPictures/1(15).png

139 KiB

ManualTestPictures/1(16).png

159 KiB

ManualTestPictures/1(17).png

92.7 KiB

ManualTestPictures/1(18).png

98.5 KiB

ManualTestPictures/1(19).png

166 KiB

ManualTestPictures/1(2).png

102 KiB

ManualTestPictures/1(20).png

92.8 KiB

ManualTestPictures/1(21).png

98.5 KiB

ManualTestPictures/1(22).png

133 KiB

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