예제 #1
0
def test_it_updates_session(sdk: mtds.LookerSDK):
    """update_session() should allow us to change the current workspace.
    """
    # Switch workspace to dev mode
    sdk.update_session(ml.WriteApiSession(workspace_id="dev"))
    current_session = sdk.session()

    assert isinstance(current_session, ml.ApiSession)
    assert current_session.workspace_id == "dev"

    # Switch workspace back to production
    current_session = sdk.update_session(
        ml.WriteApiSession(workspace_id="production"))

    assert isinstance(current_session, ml.ApiSession)
    assert current_session.workspace_id == "production"
def main():
    broken_content_prod = sdk.content_validation().content_with_errors
    """Enter dev mode """
    sdk.update_session(models.WriteApiSession(workspace_id='dev'))
    """ Check out this branch """
    branch = sys.argv[1].replace("refs/heads/", "")
    resp = sdk.update_git_branch(project_id=sys.argv[2],
                                 body=models.WriteGitBranch(name=branch))
    broken_content_dev = sdk.content_validation().content_with_errors

    # Assert no new errors introduced in dev branch
    assert len(broken_content_dev) - len(broken_content_prod) <= 0, """
        Uh oh. you just introduced a new content error!"""

    tests = sdk.all_lookml_tests(project_id=sys.argv[2])
    for test in tests:
        resp = sdk.run_lookml_test(project_id=sys.argv[2],
                                   test=test.name,
                                   model=test.model_name)
        if resp[0].errors:
            with fileinput.FileInput(resp[0].errors[0].file_path.replace(
                    sys.argv[2] + "/", ""),
                                     inplace=True) as file:
                for line in file:
                    print(line.replace(
                        "test: " + resp[0].test_name,
                        "# This test failed on " +
                        datetime.now().strftime("%m/%d/%Y %H:%M:%S") +
                        "!\ntest: " + resp[0].test_name),
                          end='')
        assert resp[0].assertions_failed == 0, resp[0].errors
예제 #3
0
def create_project(project_name):

    project = models.WriteProject(name=project_name)
    sdk = looker_sdk.init31(config_file=SCRIPT_PATH.joinpath("looker.ini"))

    # We need to enter dev mode to create a project
    sdk.update_session(models.WriteApiSession(workspace_id="dev"))

    resp = sdk.create_project(project)

    # Now we update the project and set it to a bare repo
    sdk.update_project(resp.id, models.WriteProject(git_service_name="bare"))
    return resp.id
예제 #4
0
def checkout_dev_branch():
    """Enter dev workspace"""
    sdk.update_session(models.WriteApiSession(workspace_id="dev"))
def enter_dev_mode():
    """Enter dev workspace"""
    sdk.update_session(models.WriteApiSession(workspace_id="dev"))