示例#1
0
    def test_build_index_as_cql(self):
        column_meta = Mock()
        column_meta.name = 'column_name_here'
        column_meta.table.name = 'table_name_here'
        column_meta.table.keyspace_name = 'keyspace_name_here'
        column_meta.table.columns = {column_meta.name: column_meta}
        parser = get_schema_parser(Mock(), '2.1.0', 0.1)

        row = {
            'index_name': 'index_name_here',
            'index_type': 'index_type_here'
        }
        index_meta = parser._build_index_metadata(column_meta, row)
        self.assertEqual(
            index_meta.as_cql_query(),
            'CREATE INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here)'
        )

        row['index_options'] = '{ "class_name": "class_name_here" }'
        row['index_type'] = 'CUSTOM'
        index_meta = parser._build_index_metadata(column_meta, row)
        self.assertEqual(
            index_meta.as_cql_query(),
            "CREATE CUSTOM INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here) USING 'class_name_here'"
        )
示例#2
0
    def test_build_index_as_cql(self):
        column_meta = Mock()
        column_meta.name = 'column_name_here'
        column_meta.table.name = 'table_name_here'
        column_meta.table.keyspace_name = 'keyspace_name_here'
        column_meta.table.columns = {column_meta.name: column_meta}
        parser = get_schema_parser(Mock(), '2.1.0', 0.1)

        row = {'index_name': 'index_name_here', 'index_type': 'index_type_here'}
        index_meta = parser._build_index_metadata(column_meta, row)
        self.assertEqual(index_meta.as_cql_query(),
                'CREATE INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here)')

        row['index_options'] = '{ "class_name": "class_name_here" }'
        row['index_type'] = 'CUSTOM'
        index_meta = parser._build_index_metadata(column_meta, row)
        self.assertEqual(index_meta.as_cql_query(),
                "CREATE CUSTOM INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here) USING 'class_name_here'")
示例#3
0
    def test_build_index_as_cql(self):
        column_meta = Mock()
        column_meta.name = "column_name_here"
        column_meta.table.name = "table_name_here"
        column_meta.table.keyspace_name = "keyspace_name_here"
        column_meta.table.columns = {column_meta.name: column_meta}
        connection = Mock()
        connection.server_version = "2.1.0"
        parser = get_schema_parser(connection, 0.1)

        row = {"index_name": "index_name_here", "index_type": "index_type_here"}
        index_meta = parser._build_index_metadata(column_meta, row)
        self.assertEqual(
            index_meta.as_cql_query(),
            "CREATE INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here)",
        )

        row["index_options"] = '{ "class_name": "class_name_here" }'
        row["index_type"] = "CUSTOM"
        index_meta = parser._build_index_metadata(column_meta, row)
        self.assertEqual(
            index_meta.as_cql_query(),
            "CREATE CUSTOM INDEX index_name_here ON keyspace_name_here.table_name_here (column_name_here) USING 'class_name_here'",
        )