def test_login(mock_db): database = sqlite3.connect(mock_db) shell = MiniProjectShell(database) assert not shell.login_session shell.login("*****@*****.**", "foo") assert shell.login_session assert shell.login_session.get_email() == "*****@*****.**" assert shell.login_session._email == "*****@*****.**" assert shell.login_session._password == "foo"
def test_offer_ride(mock_db): database = sqlite3.connect(mock_db) shell = MiniProjectShell(database) user = LoginSession("*****@*****.**", "") shell.login("*****@*****.**", "") assert not database.cursor().execute( "SELECT DISTINCT * FROM rides " "WHERE rno > 43 AND driver LIKE '*****@*****.**'").fetchone() offer_ride(database, user, "2018-12-31", 3, 3000, "I love em", 'west1', 'ab1', 1, {'cntr1', 'cntr2', 'cntr3'}) assert database.cursor().execute( "SELECT DISTINCT * FROM rides " "WHERE rno > 43 AND driver LIKE '*****@*****.**'").fetchone()
def test_book_member(mock_db): database = sqlite3.connect(mock_db) shell = MiniProjectShell(database) shell.login("*****@*****.**", "foo") assert not database.cursor().execute( "SELECT DISTINCT * FROM bookings " "WHERE email like '*****@*****.**'").fetchone() book_member(database, 44, '*****@*****.**', 12000, 1, 'west1', 'yyc1') assert database.cursor().execute( "SELECT DISTINCT * FROM bookings " "WHERE email like '*****@*****.**'").fetchone()
def test_send_message(mock_db): database = sqlite3.connect(mock_db) shell = MiniProjectShell(database) assert not database.cursor().execute( "SELECT * FROM inbox " "WHERE email LIKE '*****@*****.**'").fetchall() send_message(database, '*****@*****.**', '*****@*****.**', 'I love you', 42) assert database.cursor().execute( "SELECT * FROM inbox " "WHERE email LIKE '*****@*****.**'").fetchall()
def test_logout(mock_db): database = sqlite3.connect(mock_db) shell = MiniProjectShell(database) assert not shell.login_session shell.login("*****@*****.**", "foo") assert shell.login_session shell.logout() assert not shell.login_session
def test_delete_request(mock_db): """Tests delete request""" database = sqlite3.connect(mock_db) shell = MiniProjectShell(database) shell.login("*****@*****.**", "foo") assert database.cursor().execute( "SELECT DISTINCT * FROM requests WHERE rid = 15").fetchone() shell.do_delete_request('15') assert not database.cursor().execute( "SELECT DISTINCT * FROM requests WHERE rid = 15").fetchone() assert database.cursor().execute( "SELECT DISTINCT * FROM requests WHERE rid = 16").fetchone() shell.do_delete_request('16') assert not database.cursor().execute( "SELECT DISTINCT * FROM requests WHERE rid = 16").fetchone()
def test_cancel_booking(mock_db): database = sqlite3.connect(mock_db) shell = MiniProjectShell(database) shell.login("*****@*****.**", "foo") assert database.cursor().execute("SELECT DISTINCT * FROM bookings " "WHERE bno = 13").fetchone() shell.do_cancel_booking("13") assert not database.cursor().execute("SELECT DISTINCT * FROM bookings " "WHERE bno = 13").fetchone()
def test_post_request(mock_db): database = sqlite3.connect(mock_db) shell = MiniProjectShell(database) shell.login("*****@*****.**", "foo") assert not database.cursor().execute( "SELECT DISTINCT * FROM requests " "WHERE email = '*****@*****.**' AND dropoff = 'cntr3'").fetchone() shell.do_post_request("2018-12-31 west1 cntr3 1000") assert database.cursor().execute( "SELECT DISTINCT * FROM requests " "WHERE email = '*****@*****.**' AND dropoff = 'cntr3'").fetchone()
def test_register(mock_db): """""" database = sqlite3.connect(mock_db) dbcursor = database.cursor() shell = MiniProjectShell(database) testcases = list() prev_all_members = dbcursor.execute("Select * from members").fetchall() register_member(database, "*****@*****.**", "Jonny Boi", '213-342-2834', 'pass') register_member(database, "*****@*****.**", "Jonny Boi", '213-342-2834', 'pass') register_member(database, "*****@*****.**", "Jonny Boi", '213-342-2834', 'pass') all_members = dbcursor.execute("Select * from members").fetchall() assert len(prev_all_members) + 3 == len(all_members)
def main(argv=sys.argv[1:]) -> int: """main entry point mini-project-1""" parser = get_parser() args = parser.parse_args(argv) # configure logging handlers_ = [] log_format = Formatter(fmt="[%(asctime)s] [%(levelname)s] - %(message)s") if args.log_dir: os.makedirs(args.log_dir, exist_ok=True) file_handler = TimedRotatingFileHandler( os.path.join(args.log_dir, "mini_project_1.log"), when="d", interval=1, backupCount=7, encoding="UTF-8", ) file_handler.setFormatter(log_format) file_handler.setLevel(args.log_level) handlers_.append(file_handler) if args.verbose: stream_handler = logging.StreamHandler(stream=sys.stderr) stream_handler.setFormatter(log_format) stream_handler.setLevel(args.log_level) handlers_.append(stream_handler) basicConfig(handlers=handlers_, level=args.log_level) # if specified initialize a example database if args.init_database: __log__.info("creating example mini-project-1 " "database at: {}".format(args.init_database)) init_db(args.init_database) # establish a connection to the database __log__.info("connecting to mini-project-1 " "database at: {}".format(args.database or args.init_database)) conn = sqlite3.connect(args.database or args.init_database) __log__.info("starting mini-project-1 shell") MiniProjectShell(conn, register_start=args.register).cmdloop() return 0
def test_show_inbox(mock_db): database = sqlite3.connect(mock_db) shell = MiniProjectShell(database) shell.login("*****@*****.**", "foo") unread_mail = database.cursor().execute( "SELECT DISTINCT * " "FROM inbox " "WHERE inbox.email = '*****@*****.**' AND inbox.seen = 'n'").fetchall() shell.do_show_inbox(None) read_mail = database.cursor().execute( "SELECT DISTINCT * " "FROM inbox " "WHERE inbox.email = '*****@*****.**' AND inbox.seen = 'y'").fetchall() assert len(unread_mail) == len(read_mail) assert not database.cursor().execute( "SELECT DISTINCT * " "FROM inbox " "WHERE inbox.email = '*****@*****.**' AND inbox.seen = 'n'").fetchall()
def test_help_messsages(mock_db): """Test all the shell's ``help_<command>`` methods Ensure that they can be called without raising an exception. """ database = sqlite3.connect(mock_db) shell = MiniProjectShell(database) shell.help_book_member() shell.help_cancel_booking() shell.help_delete_request() shell.help_search_requests_lcode() shell.help_search_requests_city() shell.help_search_rides() shell.help_select_request() shell.help_post_request() shell.help_offer_ride() shell.help_list_bookings() shell.help_list_requests() shell.help_logout()