Fix the defects the suite pinned; turn xfail/known_bug into regressions
The suite documented every defect with two `xfail` and four `test_known_bug_*` tests. With the tests as the specification, all of them are fixed and those tests are now regression tests that fail against the previous code: - findby_director() returned None on the success path (it printed the matches and fell off the end); it returns the rows now. - findby_actor() raised UnboundLocalError when no actor matched, and returned only the last article of an actor with several; it returns the list, or None. - findby_name() and findby_type() returned the integer 0 on no match, which main.py indexed into; they return an empty list and the menus skip it. - purchase() debited USERID (the account of the last log_in) instead of the userid argument, while the rent went to the argument. - the message list looked the author up with row[4] (the recipient) instead of row[5] (the sender), in the unread and in the read list. - remove_article() checked only the open rents, so the foreign keys on the older rents and on pricehistory turned the refusal into a traceback; it now explains which records keep the article and rolls back as a backstop. - show_unread_messages() returned None when there was nothing; it returns an empty list like the read side, and the messages menu skips an empty list. - database.USERID did not exist before a login, so leaving the menu with 0 raised AttributeError; it starts as None and the menu code handles 0. - every connection is opened and closed by one context manager: findby_director(), findby_actor() and findby_type() returned before conn.close() and statistics() never closed, leaving sessions `idle in transaction`. make test: 40 passed, 0 xfailed (was 30 passed, 2 xfailed). No xfail and no test_known_bug_* is left. The README's previous "what is broken" paragraph and its test output are updated, and a "Known limitations" section lists what was deliberately not touched: SQL built by string concatenation, menu selections past the end of the list, and input() inside the data layer.
This commit is contained in:
@@ -67,6 +67,9 @@ def client():
|
||||
if client_search == '1':
|
||||
client_search_typo=input("\tInsert movie name: ")
|
||||
article=database.findby_name(client_search_typo)
|
||||
if not article:
|
||||
print("\n\tNo article matches that search")
|
||||
continue
|
||||
while (x := int(input("\tYour Selection: "))) != 0:
|
||||
print("\n\t" + article[x - 1][1])
|
||||
while (client_in := input(article_interface)) != '0':
|
||||
@@ -83,6 +86,9 @@ def client():
|
||||
if client_search == '2':
|
||||
client_search_typo=input("\tInsert movie director: ")
|
||||
article=database.findby_director(client_search_typo)
|
||||
if not article:
|
||||
print("\n\tNo article matches that search")
|
||||
continue
|
||||
while (x := int(input("\tYour Selection: "))) != 0:
|
||||
print("\n\t" + article[x - 1][1])
|
||||
while (client_in := input(article_interface)) != '0':
|
||||
@@ -99,6 +105,9 @@ def client():
|
||||
if client_search == '3':
|
||||
client_search_typo=input("\tInsert movie type: ")
|
||||
article=database.findby_type(client_search_typo)
|
||||
if not article:
|
||||
print("\n\tNo article matches that search")
|
||||
continue
|
||||
while (x := int(input("\tYour Selection: "))) != 0:
|
||||
print("\n\t" + article[x - 1][1])
|
||||
while (client_in := input(article_interface)) != '0':
|
||||
@@ -114,6 +123,9 @@ def client():
|
||||
if client_search == '4':
|
||||
client_search_typo=input("\tInsert movie actor: ")
|
||||
article=database.findby_actor(client_search_typo)
|
||||
if not article:
|
||||
print("\n\tNo article matches that search")
|
||||
continue
|
||||
while (x := int(input("\tYour Selection: "))) != 0:
|
||||
print("\n\t" + article[x - 1][1])
|
||||
while (client_in := input(article_interface)) != '0':
|
||||
@@ -268,6 +280,8 @@ def client():
|
||||
while (client_input := input(message_interface)) != '0':
|
||||
if client_input == '1':
|
||||
y = database.show_unread_messages(USERID)
|
||||
if not y:
|
||||
continue
|
||||
while (x := int(input("\tYour Selection: "))) != 0:
|
||||
database.read_message(y[x - 1][0])
|
||||
print("\n\t" + y[x - 1][1])
|
||||
@@ -357,9 +371,17 @@ def admin():
|
||||
database.statistics()
|
||||
|
||||
|
||||
if menu() != -1:
|
||||
# menu() returns 1 for a client, -1 for an administrator and None when the
|
||||
# user leaves with 0. That last case used to be tested with `!= -1`, so it
|
||||
# went into the client branch and read database.USERID, which did not exist
|
||||
# until somebody logged in (AttributeError). Nobody is logged in there, so
|
||||
# neither menu is opened.
|
||||
role = menu()
|
||||
if role == -1:
|
||||
USERID = database.USERID
|
||||
admin()
|
||||
elif role == 1:
|
||||
USERID = database.USERID
|
||||
client()
|
||||
else:
|
||||
USERID = database.USERID
|
||||
admin()
|
||||
print("\n\tGoodbye")
|
||||
Reference in New Issue
Block a user