Exemplo n.º 1
0
def test_only_one_active_instance_config_can_exist(config, source_app):
    """
    Checks that attempts to add multiple active InstanceConfig records fail.

    InstanceConfig is supposed to be invalidated by setting
    valid_until to the time the config was no longer in effect. Until
    we added the partial index preventing multiple rows with a null
    valid_until, it was possible for the system to create multiple
    active records, which would cause MultipleResultsFound exceptions
    in InstanceConfig.get_current.
    """
    # create a separate session
    engine = create_engine(source_app.config["SQLALCHEMY_DATABASE_URI"])
    session = sessionmaker(bind=engine)()

    # in the separate session, create an InstanceConfig with default
    # values, but don't commit it
    conflicting_config = InstanceConfig()
    session.add(conflicting_config)

    with source_app.app_context():
        # get_current will create another InstanceConfig with default values
        InstanceConfig.get_current()

    # now the commit of the first instance should fail
    with pytest.raises(IntegrityError):
        session.commit()
Exemplo n.º 2
0
def test_metadata_route(config, source_app):
    with patch("server_os.get_os_release", return_value="20.04"):
        with source_app.test_client() as app:
            resp = app.get(url_for("api.metadata"))
            assert resp.status_code == 200
            assert resp.headers.get("Content-Type") == "application/json"
            assert (resp.json.get("allow_document_uploads") ==
                    InstanceConfig.get_current().allow_document_uploads)
            assert resp.json.get("sd_version") == version.__version__
            assert resp.json.get("server_os") == "20.04"
            assert resp.json.get(
                "supported_languages") == config.SUPPORTED_LOCALES
            assert resp.json.get("v3_source_url") is None
Exemplo n.º 3
0
def test_metadata_route(config, source_app):
    with patch.object(source_app_api.platform, "linux_distribution") as mocked_platform:
        mocked_platform.return_value = ("Ubuntu", "16.04", "xenial")
        with source_app.test_client() as app:
            resp = app.get(url_for('api.metadata'))
            assert resp.status_code == 200
            assert resp.headers.get('Content-Type') == 'application/json'
            assert resp.json.get('allow_document_uploads') ==\
                InstanceConfig.get_current().allow_document_uploads
            assert resp.json.get('sd_version') == version.__version__
            assert resp.json.get('server_os') == '16.04'
            assert resp.json.get('supported_languages') ==\
                config.SUPPORTED_LOCALES
Exemplo n.º 4
0
def test_metadata_route(config, source_app):
    with patch.object(source_app_api, "server_os", new="16.04"):
        with source_app.test_client() as app:
            resp = app.get(url_for('api.metadata'))
            assert resp.status_code == 200
            assert resp.headers.get('Content-Type') == 'application/json'
            assert resp.json.get('allow_document_uploads') ==\
                InstanceConfig.get_current().allow_document_uploads
            assert resp.json.get('sd_version') == version.__version__
            assert resp.json.get('server_os') == '16.04'
            assert resp.json.get('supported_languages') ==\
                config.SUPPORTED_LOCALES
            assert resp.json.get('v2_source_url') is None
            assert resp.json.get('v3_source_url') is None
Exemplo n.º 5
0
 def load_instance_config():
     app.instance_config = InstanceConfig.get_current()