Ejemplo n.º 1
0
def test_initialize_user(
    user_count, expected_code, feature_mailing, feature_user_initialize, metadata, client
):
    with patch("endpoints.web.has_users") as mock_user_count:
        with patch("features.MAILING", FeatureNameValue("MAILING", feature_mailing)):
            with patch(
                "features.USER_INITIALIZE",
                FeatureNameValue("USER_INITIALIZE", feature_user_initialize),
            ):
                mock_user_count.return_value = user_count
                user = conduct_call(
                    client,
                    "web.user_initialize",
                    url_for,
                    "POST",
                    {},
                    body=metadata,
                    expected_code=expected_code,
                    headers={"Content-Type": "application/json"},
                )

                if expected_code == 200:
                    assert user.json["username"] == metadata["username"]
                    if feature_mailing:
                        assert user.json["email"] == metadata["email"]
                    else:
                        assert user.json["email"] is None
                    assert user.json.get("encrypted_password", None)
                    if metadata.get("access_token"):
                        assert 40 == len(user.json.get("access_token", ""))
                    else:
                        assert not user.json.get("access_token")
Ejemplo n.º 2
0
def test_user_metadata_update(client):
    with patch("features.USER_METADATA",
               FeatureNameValue("USER_METADATA", True)):
        with client_with_identity("devtable", client) as cl:
            metadata = {
                "given_name": "Quay",
                "family_name": "User",
                "location": "NYC",
                "company": "Red Hat",
            }

            # Update all user metadata fields.
            conduct_api_call(cl, User, "PUT", None, body=metadata)

            # Test that they were successfully updated.
            user = conduct_api_call(cl, User, "GET", None).json
            for field in metadata:
                assert user.get(field) == metadata.get(field)

            # Now nullify one of the fields, and remove another.
            metadata["company"] = None
            location = metadata.pop("location")

            conduct_api_call(cl, User, "PUT", None, body=metadata)

            user = conduct_api_call(cl, User, "GET", None).json
            for field in metadata:
                assert user.get(field) == metadata.get(field)

            # The location field should be unchanged.
            assert user.get("location") == location
Ejemplo n.º 3
0
def test_create_repository(repo_name, extended_repo_names, expected_status,
                           client):
    with patch(
            "features.EXTENDED_REPOSITORY_NAMES",
            FeatureNameValue("EXTENDED_REPOSITORY_NAMES", extended_repo_names),
    ):
        with client_with_identity("devtable", client) as cl:
            body = {
                "namespace": "devtable",
                "repository": repo_name,
                "visibility": "public",
                "description": "foo",
            }

            result = conduct_api_call(client,
                                      RepositoryList,
                                      "post",
                                      None,
                                      body,
                                      expected_code=expected_status).json
            if expected_status == 201:
                assert result["name"] == repo_name
                assert model.repository.get_repository(
                    "devtable", repo_name).name == repo_name
Ejemplo n.º 4
0
def test_signing_disabled(client):
    with patch('features.SIGNING', FeatureNameValue('SIGNING', False)):
        with client_with_identity('devtable', client) as cl:
            params = {'repository': 'devtable/simple'}
            response = conduct_api_call(cl, Repository, 'GET', params).json
            assert not response['trust_enabled']
Ejemplo n.º 5
0
def test_signing_disabled(client):
    with patch("features.SIGNING", FeatureNameValue("SIGNING", False)):
        with client_with_identity("devtable", client) as cl:
            params = {"repository": "devtable/simple"}
            response = conduct_api_call(cl, Repository, "GET", params).json
            assert not response["trust_enabled"]