Exemplo n.º 1
0
def test_as_type_with_validator(client, capsys):
    from unittest.mock import patch, Mock

    test_urls = {
        f"{client.base_url}/structures": "structures",
        f"{client.base_url}/structures/mpf_1": "structure",
        f"{client.base_url}/references": "references",
        f"{client.base_url}/references/dijkstra1968": "reference",
        f"{client.base_url}/info": "info",
        f"{client.base_url}/links": "links",
    }
    with patch("requests.get", Mock(side_effect=client.get)):
        for url, as_type in test_urls.items():
            validator = ImplementationValidator(
                base_url=url, as_type=as_type, respond_json=True
            )
            validator.validate_implementation()
            assert validator.valid

            captured = capsys.readouterr()
            json_response = json.loads(captured.out)

            assert json_response["failure_count"] == 0
            assert json_response["internal_failure_count"] == 0
            assert json_response["optional_failure_count"] == 0
            assert validator.results.failure_count == 0
            assert validator.results.internal_failure_count == 0
            assert validator.results.optional_failure_count == 0
            assert dataclasses.asdict(validator.results) == json_response
Exemplo n.º 2
0
def test_with_validator(remote_client):
    """Validate server"""
    from optimade.validator import ImplementationValidator

    validator = ImplementationValidator(client=remote_client, verbosity=5)

    validator.validate_implementation()
    assert validator.valid
Exemplo n.º 3
0
def test_with_validator(both_fake_remote_clients):
    from optimade.server.main_index import app

    validator = ImplementationValidator(
        client=both_fake_remote_clients,
        index=both_fake_remote_clients.app == app,
    )

    validator.validate_implementation()
    assert validator.valid
Exemplo n.º 4
0
def test_with_validator_json_response(both_fake_remote_clients, capsys):
    """Test that the validator writes compliant JSON when requested."""
    from optimade.server.main_index import app

    validator = ImplementationValidator(
        client=both_fake_remote_clients,
        index=both_fake_remote_clients.app == app,
        respond_json=True,
    )
    validator.validate_implementation()

    captured = capsys.readouterr()
    json_response = json.loads(captured.out)
    assert json_response["failure_count"] == 0, json_response
    assert json_response["internal_failure_count"] == 0, json_response
    assert json_response["optional_failure_count"] == 0, json_response
    assert validator.results.failure_count == 0, json_response
    assert validator.results.internal_failure_count == 0, json_response
    assert validator.results.optional_failure_count == 0, json_response
    assert dataclasses.asdict(validator.results) == json_response, json_response
    assert validator.valid
Exemplo n.º 5
0
def test_as_type_with_validator(client):
    import unittest

    test_urls = {
        f"{client.base_url}/structures": "structures",
        f"{client.base_url}/structures/mpf_1": "structure",
        f"{client.base_url}/references": "references",
        f"{client.base_url}/references/dijkstra1968": "reference",
        f"{client.base_url}/info": "info",
        f"{client.base_url}/links": "links",
    }
    with unittest.mock.patch("requests.get",
                             unittest.mock.Mock(side_effect=client.get)):
        for url, as_type in test_urls.items():
            validator = ImplementationValidator(base_url=url,
                                                as_type=as_type,
                                                verbosity=5)
            try:
                validator.validate_implementation()
            except Exception:
                print_exc()
            assert validator.valid
def validate_childdb(url: str) -> dict:
    """ Run the optimade-python-tools validator on the child database.

    Parameters:
        url: the URL of the child database.

    Returns:
        dictionary representation of the validation results.

    """
    import dataclasses
    from traceback import print_exc
    validator = ImplementationValidator(base_url=url,
                                        run_optional_tests=False,
                                        verbosity=0,
                                        fail_fast=False)

    try:
        validator.validate_implementation()
    except Exception:
        print_exc()

    return dataclasses.asdict(validator.results)