예제 #1
0
def test_delim_sequence(sdk: mtds.LookerSDK, email_domain: str,
                        users: List[Dict[str, str]]):
    search_results = sdk.search_users_names(pattern=f"%{email_domain}")
    assert len(search_results) == len(users)
    delim_ids = ml.DelimSequence([cast(int, u.id) for u in search_results])
    all_users = sdk.all_users(ids=delim_ids)
    assert len(all_users) == len(users)
예제 #2
0
def test_connection(
    connection: models.DBConnection,
) -> Sequence[models.DBConnectionTestResult]:
    """Run supported tests against a given connection."""
    assert connection.name
    assert connection.dialect and connection.dialect.connection_tests
    supported_tests: MutableSequence[str] = list(
        connection.dialect.connection_tests)
    test_results = sdk.test_connection(connection.name,
                                       models.DelimSequence(supported_tests))
    return test_results
예제 #3
0
    def check_db_connections(self):
        """Gets all db connections and runs all supported tests against them.
        """
        print("\bTest 1/6: Checking connections")

        reserved_names = [
            "looker__internal__analytics", "looker", "looker__ilooker"
        ]
        db_connections: Sequence[models.DBConnection] = list(
            filter(lambda c: c.name not in reserved_names,
                   self.sdk.all_connections()))

        if not db_connections:
            raise exceptions.NotFoundError("No connections found.")

        formatted_results = []
        for connection in db_connections:
            assert connection.dialect
            assert isinstance(connection.name, str)
            resp = self.sdk.test_connection(
                connection.name,
                models.DelimSequence(connection.dialect.connection_tests),
            )
            results = list(filter(lambda r: r.status == "error", resp))
            errors = [
                f"- {fill(cast(str, e.message), width=100)}" for e in results
            ]

            resp = self.sdk.run_inline_query(
                "json",
                models.WriteQuery(
                    model="i__looker",
                    view="history",
                    fields=["history.query_run_count"],
                    filters={"history.connection_name": connection.name},
                    limit="1",
                ),
            )
            query_run_count = json.loads(resp)[0]["history.query_run_count"]

            formatted_results.append({
                "Connection":
                connection.name,
                "Status":
                "OK" if not errors else "\n".join(errors),
                "Query Count":
                query_run_count,
            })
        self._tabularize_and_print(formatted_results)
예제 #4
0
def test_register_user(
    looker_test_users: List[sheets.User], sdk: methods.LookerSDK, register_twice: bool
):

    test_hackathon = "Some Hackathon"

    test_user = looker_test_users[0]
    looker.register_user(
        hackathon=test_hackathon,
        first_name=test_user.first_name,
        last_name=test_user.last_name,
        email=test_user.email,
    )
    if register_twice:
        looker.register_user(
            hackathon=test_hackathon,
            first_name=test_user.first_name,
            last_name=test_user.last_name,
            email=test_user.email,
        )

    users = sdk.search_users(email=test_user.email)
    assert len(users) > 0
    actual_user = users[0]

    assert actual_user.first_name == test_user.first_name
    assert actual_user.last_name == test_user.last_name
    assert actual_user.credentials_email
    assert actual_user.credentials_api3
    assert len(actual_user.credentials_api3) == 1
    assert actual_user.group_ids
    assert len(actual_user.group_ids) == 2
    assert actual_user.is_disabled

    groups = sdk.all_groups(ids=models.DelimSequence(actual_user.group_ids))
    for group in groups:
        if group.name == f"Looker_Hack: {test_hackathon}":
            break
    else:
        pytest.fail(f"Failed to find or create 'Looker_Hack: {test_hackathon}'")
    for role in sdk.all_roles(fields="name,id"):
        if role.name == "Hackathon":
            break
    else:
        pytest.fail("Bad test setup, failed to find 'Hackathon' role")
    assert role.id
    role_groups = sdk.role_groups(role_id=role.id, fields="id")
    for role_group in role_groups:
        if role_group.id == group.id:
            break
    else:
        pytest.fail(
            f"Failed to assign group 'Looker_Hack: {test_hackathon}' to role 'Hackathon'"
        )

    assert actual_user.id
    actual_attributes = sdk.user_attribute_user_values(user_id=actual_user.id)
    assert actual_attributes
    for actual_attribute in actual_attributes:
        if actual_attribute.name == "hackathon":
            assert actual_attribute.value == test_hackathon
            break
    else:
        assert False, "Not assigned hackathon role"