'test to ensure that materialized view metadata is properly updated with base columns are added
test_create_view_metadata tests that materialized views metadata is properly updated when columns are added to
the base table.
@since 3.0.0
@jira_ticket PYTHON-419
@expected_result Materialized view metadata should be updated correctly
@test_category metadata'

def test_base_table_column_addition_mv(self):

    create_table = 'CREATE    TABLE    {0}.scores(\n                                                                                                user    TEXT,\n                                                                                                game    TEXT,\n                                                                                                year    INT,\n                                                                                                month    INT,\n                                                                                                day    INT,\n                                                                                                score    TEXT,\n                                                                                                PRIMARY    KEY    (user,    game,    year,    month,    day)\n                                                                                                )'.format(self.keyspace_name)
    self.session.execute(create_table)
    create_mv = 'CREATE    MATERIALIZED    VIEW    {0}.monthlyhigh    AS\n                                                                                                SELECT    game,    year,    month,    score,    user,    day    FROM    {0}.scores\n                                                                                                WHERE    game    IS    NOT    NULL    AND    year    IS    NOT    NULL    AND    month    IS    NOT    NULL    AND    score    IS    NOT    NULL    AND    user    IS    NOT    NULL    AND    day    IS    NOT    NULL\n                                                                                                PRIMARY    KEY    ((game,    year,    month),    score,    user,    day)\n                                                                                                WITH    CLUSTERING    ORDER    BY    (score    DESC,    user    ASC,    day    ASC)'.format(self.keyspace_name)
    create_mv_alltime = 'CREATE    MATERIALIZED    VIEW    {0}.alltimehigh    AS\n                                                                                                SELECT    *    FROM    {0}.scores\n                                                                                                WHERE    game    IS    NOT    NULL    AND    score    IS    NOT    NULL    AND    user    IS    NOT    NULL    AND    year    IS    NOT    NULL    AND    month    IS    NOT    NULL    AND    day    IS    NOT    NULL\n                                                                                                PRIMARY    KEY    (game,    score,    user,    year,    month,    day)\n                                                                                                WITH    CLUSTERING    ORDER    BY    (score    DESC)'.format(self.keyspace_name)
    self.session.execute(create_mv)
    self.session.execute(create_mv_alltime)
    score_table = self.cluster.metadata.keyspaces[self.keyspace_name].tables['scores']
    self.assertIsNotNone(score_table.views['monthlyhigh'])
    self.assertIsNotNone(score_table.views['alltimehigh'])
    self.assertEqual(len(self.cluster.metadata.keyspaces[self.keyspace_name].views), 2)
    insert_fouls = 'ALTER    TABLE    {0}.scores    ADD    fouls    INT'.format(self.keyspace_name)
    self.session.execute(insert_fouls)
    self.assertEqual(len(self.cluster.metadata.keyspaces[self.keyspace_name].views), 2)
    score_table = self.cluster.metadata.keyspaces[self.keyspace_name].tables['scores']
    self.assertIn('fouls', score_table.columns)
    for i in range(10):
        mv_alltime = self.cluster.metadata.keyspaces[self.keyspace_name].views['alltimehigh']
        if ('fouls' in mv_alltime.columns):
            break
        time.sleep(0.2)
    self.assertIn('fouls', mv_alltime.columns)
    mv_alltime_fouls_comumn = self.cluster.metadata.keyspaces[self.keyspace_name].views['alltimehigh'].columns['fouls']
    self.assertEqual(mv_alltime_fouls_comumn.cql_type, 'int')
