Пример #1
0
def main():
    # Set up the tester.
    test = asst3.start_test('orm get command test', TOTAL_MARK)

    # Import student's code.
    import orm

    mark = 0
    case_number = 1

    # Start the server.
    server = asst3.Server()
    server.start("preload.txt")

    # Set up student's database object and connect to the database.
    db = orm.setup("easydb", asst3_schema)
    asst3.try_connect(db, server)

    # ===== CASE 1: Get id which does not exist. =====

    print("CASE {}: Get id which does not exist.".format(case_number).format(
        case_number))
    (mark, result) = asst3.run_test_case(
        asst3_schema.User.get, (db, 777), case_number, 1, mark, True,
        orm.exceptions.ObjectDoesNotExist
    )  # This should raise an ObjectDoesNotExist error.
    case_number = case_number + 1

    # ===== CASE 2: Get a row object with no error. =====

    id_number = random.randint(1, 3)

    if id_number == 1:
        age = 38
    elif id_number == 2:
        age = 48
    else:
        age = 21

    print("CASE {}: Get a row object with no error.".format(case_number))

    # This should not raise any error.
    try:
        user1 = asst3_schema.User.get(db, id_number)

        if user1.age == age:
            print("CASE {} PASS".format(case_number))
            mark = mark + 1
        else:
            print(
                "CASE {} FAIL: the field value of the row object is not correct"
                .format(case_number))
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))

    case_number = case_number + 1

    # ===== CASE 3: Get a row object which has foreign key field with no error. =====

    id_number = random.randint(1, 4)

    if id_number == 1:
        firstName = "James"
    else:
        firstName = "Alice"

    print(
        "CASE {}: Get a row object which has foreign key field with no error.".
        format(case_number))

    # This should not raise any error.
    try:
        account1 = asst3_schema.Account.get(db, id_number)

        if (account1.type == "Normal") and (account1.user.firstName
                                            == firstName):
            print("CASE {} PASS".format(case_number))
            mark = mark + 1
        else:
            print(
                "CASE {} FAIL: the field value of the row object is not correct"
                .format(case_number))
    except Exception as e:
        print("CASE 2 FAIL: {}".format(case_number, str(e)))

    db.close()

    server.end()

    test.add_mark(mark)
Пример #2
0
def main():
    # Set up the tester.
    test = asst3.start_test('easydb scan command test', TOTAL_MARK)

    # Import student's code.
    from orm import easydb, exceptions

    mark = 0
    case_number = 1

    # Start the server.
    server = asst3.Server()
    server.start(datafile="preload.txt")

    # database tables
    tb = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", int),
            )),
        (
            "Account",
            (
                ("user", "User"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    # Set up student's database object and connect to the database.
    db = easydb.Database(tb)
    asst3.try_connect(db, server)

    # ===== CASE 1: Table name does not exist. =====

    print("CASE {}: Table name does not exist.".format(case_number))
    (mark, result) = asst3.run_test_case(
        db.scan, ("Bob", ("firstName", easydb.OP_EQ, "James")), case_number, 1,
        mark, True, ValueError)  # This should raise an ValueError error.
    case_number = case_number + 1

    # ===== CASE 2: Query is not a tuple. =====

    print("CASE {}: Query is not a tuple.".format(case_number))
    (mark,
     result) = asst3.run_test_case(db.scan, ("User", 3), case_number, 1, mark,
                                   True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 3: Query has more than 3 elements. =====

    print("CASE {}: Query has more than 3 elements.".format(case_number))
    (mark,
     result) = asst3.run_test_case(db.scan,
                                   ("User", ("age", easydb.OP_EQ, 27, 90)),
                                   case_number, 1, mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 4: Query has less than 3 elements. =====

    print("CASE {}: Query has less than 3 elements.".format(case_number))
    (mark,
     result) = asst3.run_test_case(db.scan, ("User", ("age", easydb.OP_EQ)),
                                   case_number, 1, mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 5: Column name is not a string. =====

    print("CASE {}: Column name is not a string.".format(case_number))
    (mark,
     result) = asst3.run_test_case(db.scan, ("User", (3, easydb.OP_EQ, 27)),
                                   case_number, 1, mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 6: Column name does not exist. =====

    print("CASE {}: Column name does not exist.".format(case_number))
    (mark, result) = asst3.run_test_case(
        db.scan, ("User", ("bob", easydb.OP_EQ, 27)), case_number, 1, mark,
        True, ValueError)  # This should raise an ValueError error.
    case_number = case_number + 1

    # ===== CASE 7: Operator is not supported. =====

    print("CASE {}: Operator is not supported.")
    (mark, result) = asst3.run_test_case(
        db.scan, ("User", ("age", 10, 27)), case_number, 1, mark, True,
        ValueError)  # This should raise an ValueError error.
    case_number = case_number + 1

    # ===== CASE 8: Type of operand does not match. =====

    print("CASE {}: Type of operand does not match.".format(case_number))
    (mark, result) = asst3.run_test_case(
        db.scan, ("User", ("age", easydb.OP_EQ, "27")), case_number, 1, mark,
        True, ValueError)  # This should raise an ValueError error.
    case_number = case_number + 1

    # ===== CASE 9: Operator of a foreign key operand is not OP_EQ or OP_NE. =====

    print("CASE {}: Operator of a foreign key column is not OP_EQ or OP_NE.".
          format(case_number))
    (mark, result) = asst3.run_test_case(
        db.scan, ("Account", ("user", easydb.OP_GT, 10)), case_number, 1, mark,
        True, ValueError)  # This should raise an ValueError error.
    case_number = case_number + 1

    # ===== CASE 10: Operand of a foreign key column is not an integer. =====

    print("CASE {}: Operand of a foreign key column is not an integer.".format(
        case_number))
    (mark, result) = asst3.run_test_case(
        db.scan, ("Account", ("user", easydb.OP_EQ, "Bob")), case_number, 1,
        mark, True, ValueError)  # This should raise an ValueError error.
    case_number = case_number + 1

    # ===== CASE 11: Everything is ok with equal operator. =====

    print("CASE {}: Everything is ok with equal operator.".format(case_number))

    # This should not raise any error.
    try:
        IDs = db.scan("User", ("firstName", easydb.OP_EQ, "James"))
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        if [1] == IDs:
            print("CASE {} PASS".format(case_number))
            mark = mark + 1
        else:
            print("CASE {} FAIL: the scan result is not correct".format(
                case_number))

    case_number = case_number + 1

    # ===== CASE 12: Everything is ok with not equal operator. =====

    print("CASE {}: Everything is ok with not equal operator.".format(
        case_number))

    # This should not raise any error.
    try:
        IDs = db.scan("User", ("firstName", easydb.OP_NE, "James"))
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        if IDs is not None and all(ID in IDs
                                   for ID in [2, 3]) and len(IDs) == 2:
            print("CASE {} PASS".format(case_number))
            mark = mark + 1
        else:
            print("CASE {} FAIL: the scan result is not correct".format(
                case_number))

    case_number = case_number + 1

    # ===== CASE 13: Everything is ok with less than operator. =====

    print("CASE {}: Everything is ok with less than operator.".format(
        case_number))

    # This should not raise any error.
    try:
        IDs = db.scan("User", ("age", easydb.OP_LT, 100))
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        if IDs is not None and all(ID in IDs
                                   for ID in [1, 2, 3]) and len(IDs) == 3:
            print("CASE {} PASS".format(case_number))
            mark = mark + 1
        else:
            print("CASE {} FAIL: the scan result is not correct".format(
                case_number))

    case_number = case_number + 1

    # ===== CASE 14: Everything is ok with greater than operator. =====

    print("CASE {}: Everything is ok with greater than operator.".format(
        case_number))

    # This should not raise any error.
    try:
        IDs = db.scan("User", ("height", easydb.OP_GT, 190.0))
    except Exception as e:
        db.close()
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        db.close()
        if IDs is not None and len(IDs) == 0:
            line = 'Request { table_id: 1, command: Query(3, 4, Float(190.0)) }'
            if server.expect(line) is not None:
                print("CASE {} PASS".format(case_number))
                mark = mark + 1
            else:
                print("CASE {} FAIL: server did not receive the Scan command".
                      format(case_number))
        else:
            print("CASE {} FAIL: the scan result is not correct".format(
                case_number))

    server.end()

    test.add_mark(mark)
def main():
    # Set up the tester.
    test = asst3.start_test('easydb drop command test', TOTAL_MARK)

    # Import student's code.
    from orm import easydb, exceptions

    mark = 0
    case_number = 1

    # Start the server.
    server = asst3.Server()
    server.start(datafile="preload.txt")

    # database tables
    tb = (
        ("User", ( # table_name
            ("firstName", str), # (column_name, type)
            ("lastName", str),
            ("height", float),
            ("age", int),
        )),
    
        ("Account", (
            ("user", "User"), # (column_name, table_reference)
            ("type", str),
            ("balance", float),
        ))
    )

    # Set up student's database object and connect to the database.
    db = easydb.Database(tb)
    asst3.try_connect(db, server)

    # ===== CASE 1: Drop non-existing row. =====

    print("CASE {}: Drop non-existing row.".format(case_number))
    (mark, result) = asst3.run_test_case(db.drop, ("User", 300), case_number, 1, mark, True, exceptions.ObjectDoesNotExist) # This should raise an ObjectDoesNotExist error.
    case_number = case_number + 1

    # ===== CASE 2: Table name does not exist. =====

    print("CASE {}: Table name does not exist.".format(case_number))
    (mark, result) = asst3.run_test_case(db.drop, ("Hahaha", 1), case_number, 1, mark, True, ValueError) # This should raise an ValueError error.
    case_number = case_number + 1

    # ===== CASE 3: Everything is ok. =====

    print("CASE {}: Everything is ok.".format(case_number))

    # This should not raise any error.
    try:
        db.drop("User", 2)
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))
        db.close()    
    else:
        db.close()
        
        # Dump database rows.
        rows = asst3.dump(server, 1)
    
        not_deleted = False
        for row in rows:
            if row[0] == "2":
                not_deleted = True
                break

        if not_deleted:
            print("CASE {} FAIL: the dropped row is still on the server".format(case_number))
        else:
            print("CASE {} PASS".format(case_number))
            mark = mark + 1

    server.end()

    test.add_mark(mark)
Пример #4
0
def main():
    # Set up the tester.
    test = asst3.start_test('orm delete command test', TOTAL_MARK)

    # Import student's code.
    import orm

    mark = 0
    case_number = 1

    # Start the server.
    server = asst3.Server()
    server.start("preload.txt")

    # Set up student's database object and connect to the database.
    db = orm.setup("easydb", asst3_schema)
    asst3.try_connect(db, server)

    # Create a row object for testing.
    james = asst3_schema.User(db,
                              firstName="James",
                              lastName="Hartley",
                              height=180.3,
                              age=38)
    james.pk = 1
    james.version = 1

    # ===== CASE 1: Delete a row object with no error. =====

    print("CASE {}: Delete a row object with no error.".format(case_number))

    # This should not raise any error.
    try:
        james.delete()
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        db.close()

        # Dump database rows.
        rows = asst3.dump(server, 1)

        not_deleted = False

        for row in rows:
            if row[0] == "1":
                not_deleted = True
                break

        if not_deleted:
            print(
                "CASE {} FAIL: the deleted row is still on the server".format(
                    case_number))
        else:
            print("CASE {} PASS".format(case_number))
            mark = mark + 1

        db.connect(server.host, server.port)

    case_number = case_number + 1

    # ===== CASE 2: Delete a row object whose pk is None. =====

    print("CASE {}: Delete a row object whose pk is None.".format(case_number))
    (mark, result) = asst3.run_test_case(
        james.delete, (), case_number, 1, mark, True,
        orm.exceptions.PacketError,
        True)  # This should raise an error other than PacketError.

    db.close()

    server.end()

    test.add_mark(mark)
Пример #5
0
def main():
    # Set up the tester.
    test = asst3.start_test('easydb insert command test', TOTAL_MARK)
    
    # Import student's code.
    from orm import easydb, exceptions

    mark = 0
    case_number = 1

    # Start the server.
    server = asst3.Server()
    server.start()

    # database tables
    tb = (
        ("User", ( # table_name
            ("firstName", str), # (column_name, type)
            ("lastName", str),
            ("height", float),
            ("age", int),
        )),
    
        ("Account", (
            ("user", "User"), # (column_name, table_reference)
            ("type", str),
            ("balance", float),
        ))
    )

    # Set up student's database object and connect to the database.
    db = easydb.Database(tb)
    asst3.try_connect(db, server)

    # ===== CASE 1: There is an extra element in the inserted row. =====

    print("CASE {}: There is an extra element in the inserted row.".format(case_number))
    (mark, result) = asst3.run_test_case(db.insert, ("User", ["Jay", "Sung", 5.5, 31, 33]), case_number, 1, mark, True, ValueError) # This should raise a ValueError error.
    case_number = case_number + 1

    # ===== CASE 2: There is missing an element in the inserted row. =====

    print("CASE {}: There is missing an element in the inserted row.".format(case_number))
    (mark, result) = asst3.run_test_case(db.insert, ("User", ["Jay", "Sung", 5.5]), case_number, 1, mark, True, ValueError) # This should raise a ValueError error.
    case_number = case_number + 1

    # ===== CASE 3: Type of the column in the inserted row does not match. =====

    print("CASE {}: Type of the column in the inserted row does not match.".format(case_number))
    (mark, result) = asst3.run_test_case(db.insert, ("User", ["Jay", "Sung", "Dog", 31]), case_number, 1, mark, True, ValueError) # This should raise a ValueError error.
    case_number = case_number + 1

    # ===== CASE 4: Table name is not a string. =====

    print("CASE {}: Table name is not a string.".format(case_number))
    (mark, result) = asst3.run_test_case(db.insert, (123, ["Jay", "Sung", 5.5, 31]), case_number, 1, mark, True, ValueError) # This should raise a ValueError error.
    case_number = case_number + 1

    # ===== CASE 5: Table name does not exist in the database. =====

    print("CASE 5: Table name does not exist in the database.".format(case_number))
    (mark, result) = asst3.run_test_case(db.insert, ("Test", ["Jay", "Sung", 5.5, 31]), case_number, 1, mark, True, ValueError) # This should raise a ValueError error.
    case_number = case_number + 1

    # ===== CASE 6: Everything is ok. =====

    print("CASE {}: Everything is ok.".format(case_number))

    # Randomly generate attribute information.
    first_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6)).capitalize()
    last_name = ''.join(random.choice(string.ascii_lowercase) for i in range(6)).capitalize()
    height = random.randint(1200, 2000) / 10
    age = random.randint(1, 100) 

    # This should not raise any error.
    try:
        pk, version = db.insert("User", [first_name, last_name, height, age])
    except Exception as e:
        db.close()
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        db.close()
    
        # Dump database rows.
        rows = asst3.dump(server, 1)

        if [str(pk), str(version), first_name, last_name, str(height), str(age)] in rows or [str(pk), str(version), first_name, last_name, str(int(height)), str(age)] in rows:
            print("CASE {} PASS".format(case_number))
            mark = mark + 1
        else:
            print("CASE {} FAIL: the inserted row cannot be found on the server".format(case_number))

    server.end()

    test.add_mark(mark)
def main():
    # Set up the tester.
    test = asst3.start_test('easydb get command test', TOTAL_MARK)

    # Import student's code.
    from orm import easydb, exceptions

    mark = 0
    case_number = 1

    # Start the server.
    server = asst3.Server()
    server.start(datafile="preload.txt")

    # database tables
    tb = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", int),
            )),
        (
            "Account",
            (
                ("user", "User"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    # Set up student's database object and connect to the database.
    db = easydb.Database(tb)
    asst3.try_connect(db, server)

    # ===== CASE 1: Get non-existing row. =====

    print("CASE {}: Get non-existing row.".format(case_number))
    (mark, result) = asst3.run_test_case(
        db.get, ("User", 300), case_number, 1, mark, True, exceptions.
        ObjectDoesNotExist)  # This should raise an ObjectDoesNotExist error.
    case_number = case_number + 1

    # ===== CASE 2: Table name does not exist. =====

    print("CASE {}: Table name does not exist.".format(case_number))
    (mark, result) = asst3.run_test_case(
        db.get, ("Hahaha", 1), case_number, 1, mark, True,
        ValueError)  # This should raise an ValueError error.
    case_number = case_number + 1

    # ===== CASE 2: Everything is ok. =====

    print("CASE {}: Everything is ok.".format(case_number))

    # This should not raise any error.
    try:
        values, version = db.get("User", 1)
    except Exception as e:
        db.close()
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        db.close()
        if values == ["James", "Hartley", 180.3, 38]:
            if server.expect(
                    'Request { table_id: 1, command: Get(1) }') is not None:
                print("CASE {} PASS".format(case_number))
                mark = mark + 1
            else:
                print("CASE {} FAIL: server did not receive the Get command".
                      format(case_number))
        else:
            print("CASE {} FAIL: the received row is not correct".format(
                case_number))

    server.end()

    test.add_mark(mark)
def main():
    # Set up the tester.
    test = asst3.start_test('orm save command test', TOTAL_MARK)

    # Import student's code.
    import orm 

    mark = 0
    case_number = 1

    # Start the server.
    server = asst3.Server()
    server.start()

    # Set up student's database object and connect to the database.
    db = orm.setup("easydb", asst3_schema)
    asst3.try_connect(db, server)

    # Create some row objects for testing.
    joe = asst3_schema.User(db, firstName="Joe", lastName="Harris", age=32)
    jeffrey = asst3_schema.User(db, firstName="Jeffrey", lastName="Fang", height=999.9)
    alice = asst3_schema.User(db, firstName="Alice", lastName="Stuart", age=18)
    account1 = asst3_schema.Account(db, user=alice, type="Yes")
    account2 = asst3_schema.Account(db, user=jeffrey, type="Special")

    # ===== CASE 1: Save a row object whose field is not in choices. =====

    print("CASE {}: Save a row object whose field is not in choices.".format(case_number))
    (mark, result) = asst3.run_test_case(account1.save, (), case_number, 1, mark, True, ValueError) # This should raise a ValueError error.
    case_number = case_number + 1

    # ===== CASE 2: Save a new row object to the database with no error (insert). =====

    print("CASE {}: Save a new row object to the database with no error (insert).".format(case_number))

    # This should not raise any error.
    try:
        joe.save()
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        db.close()

        # Dump database rows.
        rows = asst3.dump(server, 1)

        if [str(1), str(1), "Joe", "Harris", "0", "32"] in rows or [str(2), str(1), "Joe", "Harris", "0", "32"] in rows:
            print("CASE {} PASS".format(case_number))
            mark = mark + 1
        else:
            print("CASE {} FAIL: the saved row cannot be found on the server".format(case_number))

        db.connect(server.host, server.port)

    case_number = case_number + 1

    # ===== CASE 3: Cascade save new row objects to the database with no error (insert). =====

    print("CASE {}: Cascade save new row objects to the database with no error (insert).".format(case_number))

    # This should not raise any error.
    try:
        account2.save()
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        db.close()

        # Dump database rows.
        client = asst3.Client(server)
        user_rows = client.dump(1)
        account_rows = client.dump(2)
        client.close()

        if ([str(2), str(1), "Jeffrey", "Fang", "999.9", "0"] in user_rows or [str(3), str(1), "Jeffrey", "Fang", "999.9", "0"] in user_rows) \
        and ([str(1), str(1), "2", "Special", "0"] in account_rows or [str(2), str(1), "2", "Special", "0"] in account_rows \
        or [str(1), str(1), "3", "Special", "0"] in account_rows or [str(2), str(1), "3", "Special", "0"] in account_rows):
            print("CASE {} PASS".format(case_number))
            mark = mark + 1
        else:
            print("CASE {} FAIL: the saved row cannot be found on the server".format(case_number))

        db.connect(server.host, server.port)

    case_number = case_number + 1

    # ===== CASE 4: Save a existing row object to the database (update). =====

    joe.height = 663.1

    print("CASE {}: Save a existing row object to the database (update).".format(case_number))

    # This should not raise any error.
    try:
        joe.save()
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        db.close()

        # Dump database rows.
        rows = asst3.dump(server, 1)

        if [str(1), str(2), "Joe", "Harris", "663.1", "32"] in rows or [str(2), str(2), "Joe", "Harris", "663.1", "32"] in rows:
            print("CASE {} PASS".format(case_number))
            mark = mark + 1
        else:
            print("CASE {} FAIL: the saved row cannot be found on the server".format(case_number))

        db.connect(server.host, server.port)

    case_number = case_number + 1

    # ===== CASE 5: Non-atomic save (non-atomic update) =====

    joe.age = 50

    print("CASE {}: Non-atomic save (non-atomic update)".format(case_number))

    # This may raise a TransactionAbort error.
    try:
        joe.save()
    except orm.TransactionAbort:
        print("CASE {} PASS".format(case_number))
        mark = mark + 1
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        db.close() 

        # Dump database rows.
        rows = asst3.dump(server, 1)

        if [str(1), str(3), "Joe", "Harris", "663.1", "50"] in rows or [str(2), str(3), "Joe", "Harris", "663.1", "50"] in rows:
            print("CASE {} PASS".format(case_number))
            mark = mark + 1
        else:
            print("CASE {} FAIL: the saved row cannot be found on the server".format(case_number))

        db.connect(server.host, server.port)

    case_number = case_number + 1

    # ===== CASE 6: Row object's id does not exist in the database anymore (invalid reference). =====

    jeffrey.pk = 888

    print("CASE {}: Row object's id does not exist in the database anymore (invalid reference).".format(case_number))

    # This should raise an InvalidReference error.
    try:
        account2.save()
    except orm.exceptions.InvalidReference:
        if jeffrey.pk is None:
            mark = mark + 1
            print("CASE {} PASS".format(case_number))
        else:
            print("CASE {} FAIL: pk is not set back to None".format(case_number))
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        print("CASE {} FAIL: {}".format(case_number, "expected InvalidReference"))

    db.close()

    server.end()

    test.add_mark(mark)
Пример #8
0
def main():
    # Set up the tester.
    test = asst3.start_test('easydb table format test', TOTAL_MARK)

    # Load student's code.
    from orm import easydb, exceptions

    mark = 0
    case_number = 1

    # ===== CASE 1: All the table formats are ok. =====

    tb_1 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", int),
            )),
        (
            "Account",
            (
                ("user", "User"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print("CASE {}: All the table formats are ok.".format(case_number))

    # This should not raise any error.
    try:
        db = easydb.Database(tb_1)
    except Exception as e:
        print("CASE {} FAIL: {}".format(case_number, str(e)))
    else:
        contain = False

        for key in db.__dict__:
            # Check if the object saves the inpputed schema by checking if there is a tuple, list, or dict attribute.
            if isinstance(db.__dict__[key], (tuple, list, dict)):
                if len(db.__dict__[key]) > 0:
                    contain = True
                    break

        if contain:
            print("CASE {} PASS".format(case_number))
            mark = mark + 1
        else:
            print(
                "CASE {} FAIL: no tuple, list, or dict is found in the Database object indicating that the inputted schema is saved"
                .format(case_number))

    case_number = case_number + 1

    # ===== CASE 2: Table name is not a string. =====

    tb_2 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", int),
            )),
        (
            33333,
            (
                ("user", "User"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print("CASE {}: Table name is not a string.".format(case_number))
    (mark, result) = asst3.run_test_case(
        easydb.Database, (tb_2, ), case_number, 1, mark, True,
        TypeError)  # This should raise a TypeError error.
    case_number = case_number + 1

    # ===== CASE 3: Column name is not a string. =====

    tb_3 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ([1, 2], float),
                ("age", int),
            )),
        (
            "Account",
            (
                ("user", "User"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print("CASE {}: Column name is not a string.".format(case_number))
    (mark, result) = asst3.run_test_case(
        easydb.Database, (tb_3, ), case_number, 1, mark, True,
        TypeError)  # This should raise a TypeError error.
    case_number = case_number + 1

    # ===== CASE 4: Type is not one of str, float, int. =====

    tb_4 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", tuple),
            )),
        (
            "Account",
            (
                ("user", "User"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print("CASE {}: Type is not one of str, float, int.".format(case_number))
    (mark, result) = asst3.run_test_case(
        easydb.Database, (tb_4, ), case_number, 1, mark, True,
        ValueError)  # This should raise a ValueError error.
    case_number = case_number + 1

    # ===== CASE 5: Type is not a string referencing another table name (nonexistent table). =====

    tb_5 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", int),
            )),
        (
            "Account",
            (
                ("user", "Yes"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print(
        "CASE {}: Type is not a string referencing another table name (nonexistent table)."
        .format(case_number))
    (mark, result) = asst3.run_test_case(
        easydb.Database, (tb_5, ), case_number, 1, mark, True,
        exceptions.IntegrityError)  # This should raise a IntegrityError error.
    case_number = case_number + 1

    # ===== CASE 6: Length of tables are not exactly 2. =====

    tb_6 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", int),
            ),
            3),
        (
            "Account",
            (
                ("user", "User"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print("CASE {}: Length of tables are not exactly 2.".format(case_number))
    (mark,
     result) = asst3.run_test_case(easydb.Database, (tb_6, ), case_number, 1,
                                   mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 7: Length of columns are not exactly 2. =====

    tb_7 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", int),
            )),
        (
            "Account",
            (
                ("user", "User"),  # (column_name, table_reference)
                ("type", str, 123, "nonono"),
                ("balance", float),
            )))

    print("CASE {}: Length of columns are not exactly 2.".format(case_number))
    (mark,
     result) = asst3.run_test_case(easydb.Database, (tb_7, ), case_number, 1,
                                   mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 8: Names of tables are not legal. =====

    tb_8 = (
        (
            "_User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", int),
            )),
        (
            "Account",
            (
                ("user", "User"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print("CASE {}: Names of tables are not legal.".format(case_number))
    (mark,
     result) = asst3.run_test_case(easydb.Database, (tb_8, ), case_number, 1,
                                   mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 9: Names of columns are not legal. =====

    tb_9 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("3height", float),
                ("age", int),
            )),
        (
            "Account",
            (
                ("user", "User"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print("CASE {}: Names of columns are not legal.".format(case_number))
    (mark,
     result) = asst3.run_test_case(easydb.Database, (tb_9, ), case_number, 1,
                                   mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 10: Table names are duplicated. =====

    tb_10 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", int),
            )),
        (
            "User",
            (
                ("user", str),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print("CASE {}: Table names are duplicated.".format(case_number))
    (mark,
     result) = asst3.run_test_case(easydb.Database, (tb_10, ), case_number, 1,
                                   mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 11: Column names are duplicated. =====

    tb_11 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("weight", float),
                ("firstName", int),
            )),
        (
            "Account",
            (
                ("user", str),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print("CASE {}: Column names are duplicated.".format(case_number))
    (mark,
     result) = asst3.run_test_case(easydb.Database, (tb_11, ), case_number, 1,
                                   mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 12: Column name is 'pk'. =====

    tb_12 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("weight", float),
                ("pk", int),
            )),
        (
            "Account",
            (
                ("user", str),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print("CASE {}: Column name is 'pk'.".format(case_number))
    (mark,
     result) = asst3.run_test_case(easydb.Database, (tb_12, ), case_number, 1,
                                   mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 13: Column name is 'id'. =====

    tb_13 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("weight", float),
                ("age", int),
            )),
        (
            "Account",
            (
                ("user", str),  # (column_name, table_reference)
                ("id", str),
                ("balance", float),
            )))

    print("CASE {}: Column name is 'id'.".format(case_number))
    (mark,
     result) = asst3.run_test_case(easydb.Database, (tb_13, ), case_number, 1,
                                   mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 14: Column name is 'save'. =====

    tb_14 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("weight", float),
                ("age", int),
            )),
        (
            "Account",
            (
                ("user", str),  # (column_name, table_reference)
                ("save", str),
                ("balance", float),
            )))

    print("CASE {}: Column name is 'save'.".format(case_number))
    (mark,
     result) = asst3.run_test_case(easydb.Database, (tb_14, ), case_number, 1,
                                   mark, True,
                                   Exception)  # This should raise an error.
    case_number = case_number + 1

    # ===== CASE 15: Foreign keys are causing a cycle. =====

    tb_15 = (
        (
            "User",
            (  # table_name
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", int),
            )),
        (
            "Account",
            (
                ("user", "Account"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )),
        (
            "Test1",
            (
                ("user", "Account"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )),
        (
            "Test2",
            (
                ("user", "Test1"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )))

    print("CASE {}: Foreign keys are causing a cycle.".format(case_number))
    (mark, result) = asst3.run_test_case(
        easydb.Database, (tb_15, ), case_number, 1, mark, True, exceptions.
        IntegrityError)  # This should raise an IntegrityError error.
    case_number = case_number + 1

    # ===== CASE 16: Table reference is out of order. =====

    tb_16 = (
        (
            "Account",
            (  # table_name
                ("user", "User"),  # (column_name, table_reference)
                ("type", str),
                ("balance", float),
            )),
        (
            "User",
            (
                ("firstName", str),  # (column_name, type)
                ("lastName", str),
                ("height", float),
                ("age", int),
            )))

    print("CASE {}: Table reference is out of order.".format(case_number))
    (mark, result) = asst3.run_test_case(
        easydb.Database, (tb_16, ), case_number, 1, mark, True, exceptions.
        IntegrityError)  # This should raise an IntegrityError error.

    test.add_mark(mark)