Exemple #1
0
def test_invalid_sql():
    with pytest.raises(ValueError):
        # fmt: off
        invalid_input = ("CREATER TABLE table_name (\n"
                         "    id BIGINT AUTO_INCREMENT PRIMARY KEY\n"
                         ");")
        # fmt: on
        create_md_tables(invalid_input)
Exemple #2
0
def test_different_table_name():
    input = ("CREATE TABLE diff_table_name (\n"
             "    id BIGINT AUTO_INCREMENT PRIMARY KEY\n"
             ");")
    expected = ("**diff_table_name**\n"
                "|Column | Type | Comments|\n"
                "|-|-|-|\n"
                "|id|BIGINT AUTO_INCREMENT PRIMARY KEY||")
    actual = create_md_tables(input)
    assert expected == actual
Exemple #3
0
def test_different_column_name():
    # fmt: off
    input = ("CREATE TABLE table_name (\n"
             "    diff_id BIGINT AUTO_INCREMENT PRIMARY KEY\n"
             ");")
    # fmt: on
    expected = ("**table_name**\n"
                "|Column | Type | Comments|\n"
                "|-|-|-|\n"
                "|diff_id|BIGINT AUTO_INCREMENT PRIMARY KEY||")
    actual = create_md_tables(input)
    assert expected == actual
Exemple #4
0
def test_table_name_extracted(create_table):
    # fmt: off
    input = (f"{create_table}\n"
             "    id BIGINT AUTO_INCREMENT PRIMARY KEY\n"
             ");")
    # fmt: on
    expected = ("**table_name**\n"
                "|Column | Type | Comments|\n"
                "|-|-|-|\n"
                "|id|BIGINT AUTO_INCREMENT PRIMARY KEY||")
    actual = create_md_tables(input)
    assert expected == actual
Exemple #5
0
def test_multiple_columns():
    # fmt: off
    input = ("CREATE TABLE table_name (\n"
             "    id BIGINT AUTO_INCREMENT PRIMARY KEY,\n"
             "    name VARCHAR(255)\n"
             ");")
    # fmt: on
    expected = ("**table_name**\n"
                "|Column | Type | Comments|\n"
                "|-|-|-|\n"
                "|id|BIGINT AUTO_INCREMENT PRIMARY KEY||\n"
                "|name|VARCHAR(255)||")
    actual = create_md_tables(input)
    assert expected == actual
Exemple #6
0
def test_multiple_tables():
    # fmt: off
    input = ("CREATE TABLE table_name (\n"
             "    id BIGINT AUTO_INCREMENT PRIMARY KEY\n"
             ");"
             "CREATE TABLE table_name2 (\n"
             "    id BIGINT AUTO_INCREMENT PRIMARY KEY\n"
             ");")
    # fmt: on
    expected = ("**table_name**\n"
                "|Column | Type | Comments|\n"
                "|-|-|-|\n"
                "|id|BIGINT AUTO_INCREMENT PRIMARY KEY||"
                "\n\n"
                "**table_name2**\n"
                "|Column | Type | Comments|\n"
                "|-|-|-|\n"
                "|id|BIGINT AUTO_INCREMENT PRIMARY KEY||")
    actual = create_md_tables(input)
    assert expected == actual
Exemple #7
0
def test_table_with_unique_key_attribute():
    input = ("CREATE TABLE students(\n"
             "    S_Id int NOT NULL,\n"
             "    LastName varchar (255) NOT NULL,\n"
             "    FirstName varchar (255),\n"
             "    City varchar (255),\n"
             "    CONSTRAINT uc_studentId UNIQUE (S_Id, LastName)\n"
             ")")
    expected = ("**students**\n"
                "Attributes:\n"
                "CONSTRAINT uc_studentId UNIQUE (S_Id, LastName)\n"
                "|Column | Type | Comments|\n"
                "|-|-|-|\n"
                "|S_Id|int NOT NULL||\n"
                "|LastName|varchar (255) NOT NULL||\n"
                "|FirstName|varchar (255)||\n"
                "|City|varchar (255)||")
    actual = create_md_tables(input)
    print(f"{expected}\n\n{actual}")
    assert expected == actual
Exemple #8
0
def test_table_with_attribute():
    # fmt: off
    input = ("CREATE TABLE sales.visits ("
             "    visit_id INT PRIMARY KEY,\n"
             "    first_name VARCHAR (50) NOT NULL,\n"
             "    phone VARCHAR(20),\n"
             "    store_id INT NOT NULL,\n"
             "    FOREIGN KEY (store_id) REFERENCES sales.stores (store_id)"
             ");")
    # fmt: on
    expected = ("**sales.visits**\n"
                "Attributes:\n"
                "FOREIGN KEY (store_id) REFERENCES sales.stores (store_id)\n"
                "|Column | Type | Comments|\n"
                "|-|-|-|\n"
                "|visit_id|INT PRIMARY KEY||\n"
                "|first_name|VARCHAR (50) NOT NULL||\n"
                "|phone|VARCHAR(20)||\n"
                "|store_id|INT NOT NULL||")
    actual = create_md_tables(input)
    assert expected == actual
Exemple #9
0
def test_empty_sql():
    with pytest.raises(ValueError):
        invalid_input = ""
        create_md_tables(invalid_input)