def test_should_sort_views_with_materialized_table(self, temp_dir: Path):
     view_list_config = ViewListConfig(
         [ViewConfig('view1'),
          ViewConfig('view2', materialize=True)])
     (temp_dir /
      'view1.sql').write_text('SELECT * FROM `{project}.{dataset}.mview2`')
     (temp_dir / 'view2.sql').write_text('SELECT 1')
     sorted_view_list_config = view_list_config.sort_insert_order(temp_dir)
     assert sorted_view_list_config.view_names == ['view2', 'view1']
 def test_should_filter_view_names(self):
     view_list_config = ViewListConfig(
         [ViewConfig('view1'),
          ViewConfig('view2'),
          ViewConfig('view3')])
     assert [
         view.view_name
         for view in view_list_config.filter_view_names(['view1', 'view3'])
     ] == ['view1', 'view3']
 def test_should_resolve_conditions(self):
     view_list_config = ViewListConfig([
         ViewConfig('view1',
                    conditions=[
                        ViewCondition(
                            if_condition={'dataset': 'dataset1'},
                            materialize_as='output_dataset1.output_table1')
                    ])
     ])
     assert [
         view.materialize_as for view in
         view_list_config.resolve_conditions({'dataset': 'dataset1'})
     ] == ['output_dataset1.output_table1']
 def test_should_convert_to_view_list_dict(self):
     view_list_config = ViewListConfig(
         [ViewConfig('view1'), ViewConfig('view2')])
     views_ordered_dict = view_list_config.to_views_ordered_dict('dataset1')
     assert views_ordered_dict == OrderedDict([('view1', {
         DATASET_NAME_KEY:
         'dataset1',
         VIEW_OR_TABLE_NAME_KEY:
         'view1'
     }),
                                               ('view2', {
                                                   DATASET_NAME_KEY:
                                                   'dataset1',
                                                   VIEW_OR_TABLE_NAME_KEY:
                                                   'view2'
                                               })])
 def test_should_convert_to_materialized_view_ordered_dict(self):
     view_list_config = ViewListConfig([
         ViewConfig('view1',
                    materialize_as='output_dataset1.output_table1'),
         ViewConfig('view2'),
         ViewConfig('view3', materialize=True)
     ])
     materialized_view_ordered_dict = (
         view_list_config.to_materialized_view_ordered_dict('dataset1'))
     assert materialized_view_ordered_dict == OrderedDict([
         ('view1', {
             DATASET_NAME_KEY: 'output_dataset1',
             VIEW_OR_TABLE_NAME_KEY: 'output_table1'
         }),
         ('view3', {
             DATASET_NAME_KEY: 'dataset1',
             VIEW_OR_TABLE_NAME_KEY: 'mview3'
         })
     ])
 def test_should_add_view(self):
     view_list_config = ViewListConfig(
         [ViewConfig('view1'), ViewConfig('view2')])
     assert view_list_config.has_view('view1')
     assert view_list_config.has_view('view2')
     assert not view_list_config.has_view('view3')
     view_list_config = view_list_config.add_view(ViewConfig('view3'))
     assert view_list_config.has_view('view3')