Added some test cases and added another error message

This commit is contained in:
Administrator 2022-05-21 11:41:20 +02:00
parent d1c5a4d478
commit e87a071b5d
2 changed files with 32 additions and 1 deletions

View File

@ -565,7 +565,7 @@ def add_product(message):
user_id = message.from_user.id
# Check if user is admin
if not session.query(User).filter(User.telegram_id==user_id).first().admin:
if not session.query(User).filter(User.telegram_id == user_id).first().admin:
bot.reply_to(message, "Error: Admin rights are required to add products")
return
@ -619,6 +619,9 @@ def receive_product_data(message):
except sqlalchemy.exc.IntegrityError:
session.rollback()
bot.send_message(chat_id=user_id, text='Product is in database already')
except pymysql.err.OperationalError:
session.rollback()
bot.send_message(chat_id=user_id, text='Unknown error')
@bot.callback_query_handler(func=lambda call: True)

View File

@ -20,6 +20,11 @@ def fetch_url(url):
Raises:
None: None
Test:
What happens if url returns non 200 status code
What happens if url returns 200 status code
What happens if Firefox, Gecko or important libraries are not installed
"""
display = Display(visible=False, size=(800, 600))
display.start()
@ -57,6 +62,11 @@ def get_title(response):
Raises:
None: None
Test:
Response contains meta tag with title attribute
Response doesn't contain meta tag
Response is invalid html
"""
soup = BeautifulSoup(response, 'html.parser')
@ -79,6 +89,12 @@ def get_image(response):
Raises:
None: None
Test:
Response contains div with "imgTagWrapperId" id and includes json data
Response doesn't contain div
Response is invalid html
JSON is not valid
"""
soup = BeautifulSoup(response, 'html.parser')
@ -111,6 +127,11 @@ def get_description(response):
Raises:
None: None
Test:
Response contains div with "feature-bullets" id
Response doesn't contain div
Response is invalid html
"""
soup = BeautifulSoup(response, 'html.parser')
@ -139,6 +160,13 @@ def get_price(response):
Raises:
None: None
Test:
Response contains div with class "twister-plus-buying-options-price-data"
Response doesn't contain div
No valid JSON
Only price, currency missing
Response is invalid html
"""
soup = BeautifulSoup(response, 'html.parser')