def project(): dimensions = [ Dimension( "test_view.dimension_one", "number", "${TABLE}.dimension_one", ("https://test.looker.com/projects/spectacles/" "files/test_view.view.lkml?line=340"), ), Dimension( "test_view.dimension_two", "number", "${TABLE}.dimension_two", ("https://test.looker.com/projects/spectacles/" "files/test_view.view.lkml?line=360"), ), ] explores_model_one = [Explore("test_explore_one", dimensions)] explores_model_two = [Explore("test_explore_two", dimensions)] models = [ Model("test_model_one", "test_project", explores_model_one), Model("test_model.two", "test_project", explores_model_two), ] project = Project("test_project", models) return project
def build_project( self, selectors: Optional[List[str]] = None, exclusions: Optional[List[str]] = None, ) -> None: """Creates an object representation of the project's LookML. Args: selectors: List of selector strings in 'model_name/explore_name' format. The '*' wildcard selects all models or explores. For instance, 'model_name/*' would select all explores in the 'model_name' model. """ # Assign default values for selectors and exclusions if selectors is None: selectors = ["*/*"] if exclusions is None: exclusions = [] logger.info( f"Building LookML project hierarchy for project {self.project.name}" ) all_models = [ Model.from_json(model) for model in self.client.get_lookml_models() ] project_models = [ model for model in all_models if model.project_name == self.project.name ] if not project_models: raise LookMlNotFound( name="project-models-not-found", title= "No matching models found for the specified project and selectors.", detail=(f"Go to {self.client.base_url}/projects and confirm " "a) at least one model exists for the project and " "b) it has an active configuration."), ) for model in project_models: model.explores = [ explore for explore in model.explores if is_selected(model.name, explore.name, selectors, exclusions) ] for explore in model.explores: dimensions_json = self.client.get_lookml_dimensions( model.name, explore.name) for dimension_json in dimensions_json: dimension = Dimension.from_json(dimension_json, model.name, explore.name) dimension.url = self.client.base_url + dimension.url if not dimension.ignore: explore.add_dimension(dimension) self.project.models = [ model for model in project_models if len(model.explores) > 0 ]
def build_project(self, selectors: List[str]) -> None: """Creates an object representation of the project's LookML. Args: selectors: List of selector strings in 'model_name.explore_name' format. The '*' wildcard selects all models or explores. For instance, 'model_name.*' would select all explores in the 'model_name' model. """ selection = self.parse_selectors(selectors) logger.info( f"Building LookML project hierarchy for project {self.project.name}" ) all_models = [ Model.from_json(model) for model in self.client.get_lookml_models() ] project_models = [ model for model in all_models if model.project == self.project.name ] # Expand wildcard operator to include all specified or discovered models selected_model_names = selection.keys() if "*" in selected_model_names: explore_names = selection.pop("*") for model in project_models: selection[model.name].update(explore_names) selected_models = self._select(choices=tuple(selection.keys()), select_from=project_models) for model in selected_models: # Expand wildcard operator to include all specified or discovered explores selected_explore_names = selection[model.name] if "*" in selected_explore_names: selected_explore_names.remove("*") selected_explore_names.update( set(explore.name for explore in model.explores)) selected_explores = self._select( choices=tuple(selected_explore_names), select_from=model.explores) for explore in selected_explores: dimensions_json = self.client.get_lookml_dimensions( model.name, explore.name) for dimension_json in dimensions_json: dimension = Dimension.from_json(dimension_json) dimension.url = self.client.base_url + dimension.url if not dimension.ignore: explore.add_dimension(dimension) model.explores = selected_explores self.project.models = selected_models
def model(): return Model(name="eye_exam", project_name="eye_exam", explores=[])
def test_model_from_json(): json_dict = load_resource("response_models.json") model = Model.from_json(json_dict[0]) assert model.name == "test_model_one" assert model.project_name == "test_project" assert [e.name for e in model.explores] == ["test_explore_one"]
def model(): return Model(name="model_name", project="string", explores=[])