예제 #1
0
    def test_api_healthcheck_001(capsys, osenviron, healthcheck):
        """Run API healtcheck."""

        osenviron.setenv('SNIPPY_SERVER_HOST', '127.0.0.1:8081')
        snippy = Snippy(['snippy', '--server-healthcheck'])
        cause = snippy.run()
        healthcheck.assert_called_once_with('127.0.0.1:8081', timeout=2)
        out, err = capsys.readouterr()
        assert cause == Cause.ALL_OK
        assert out == ''
        assert not err
예제 #2
0
def _create_snippy(mocker, request, params, database):
    """Create snippy with mocks.

    Args:
        params (list): Command line arguments to start the Snippy.
        database (str): Database used with the tests.

    Returns:
        obj: Snippy object.
    """

    if request.config.getoption("--snippy-logs"):
        params.append('--debug')

    # Mock only objects from the Snippy package. If system calls like os.open
    # are mocked from here, it will mock all the third party packages that are
    # imported when the Snippy object is created. System calls must be mocked
    # after the Snippy object is in a such state that it can accept test case
    # input.
    mocker.patch.object(Config,
                        '_storage_file',
                        return_value=Database.get_storage())
    if database == Database.DB_POSTGRESQL:
        params = params + Database.get_cli_params()

    snippy = Snippy(params)

    return snippy
예제 #3
0
    def test_api_hello_api_008():
        """Test server hello response.

        Send GET /api/snippy/rest/' to get server hello response. In this case
        the server base path is incorrect because it contains two slashes. This
        configuration error results the default base path configuration.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '246'
        }
        expect_body = {'meta': Content.get_api_meta()}
        server = Snippy([
            'snippy', 'server', '--server-host', 'localhost:8080',
            '--server-base-path-rest', '/api//snippy'
        ])
        server.run()
        result = testing.TestClient(
            server.server.api).simulate_get('/api/snippy/rest')
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
        server.release()
        Content.delete()
예제 #4
0
    def test_api_hello_api_007():
        """Test server hello response.

        Send GET /api/snippy/ to get server hello response. In this case the
        server base path configuration is incorrect. The server base path must
        contain leading and trailing slashes which are missing from this test.
        In this case the configuration must be updated automatically and the
        API call must work.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '246'
        }
        expect_body = {'meta': Content.get_api_meta()}
        server = Snippy([
            'snippy', 'server', '--server-host', 'localhost:8080',
            '--server-base-path-rest', 'api/snippy'
        ])
        server.run()
        result = testing.TestClient(
            server.server.api).simulate_get('/api/snippy')
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
        server.release()
        Content.delete()