Ejemplo n.º 1
0
    def test_api_update_reference_010(server):
        """Update reference with PATCH request.

        Send PATCH /references/{id} to update existing reference with digest.
        The PATCH sets all but the mandatory field to empty values.
        """

        storage = {
            'data': [
                Storage.gitlog
            ]
        }
        storage['data'][0]['brief'] = ''
        storage['data'][0]['description'] = ''
        storage['data'][0]['name'] = ''
        storage['data'][0]['groups'] = ()
        storage['data'][0]['tags'] = ()
        storage['data'][0]['source'] = ''
        storage['data'][0]['versions'] = ()
        storage['data'][0]['filename'] = ''
        storage['data'][0]['created'] = Content.GITLOG_TIME
        storage['data'][0]['updated'] = Content.PYTEST_TIME
        storage['data'][0]['digest'] = '54c493ade0f808e3d1b16bb606484a51bb0f7eb9c0592c46aea5196bd891881c'
        request_body = {
            'data': {
                'type': 'reference',
                'attributes': {
                    'brief': None,
                    'description': None,
                    'name': None,
                    'groups': None,
                    'tags': None,
                    'source': None,
                    'versions': None,
                    'filename': None
                }
            }
        }
        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '634'
        }
        expect_body = {
            'links': {
                'self': 'http://falconframework.org/api/snippy/rest/references/' + Reference.GITLOG_UUID
            },
            'data': {
                'type': 'reference',
                'id': storage['data'][0]['uuid'],
                'attributes': storage['data'][0]
            }
        }
        result = testing.TestClient(server.server.api).simulate_patch(
            path='/api/snippy/rest/references/5c2071094dbfaa33',
            headers={'accept': 'application/vnd.api+json; charset=UTF-8'},
            body=json.dumps(request_body))
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
        Content.assert_storage(storage)
Ejemplo n.º 2
0
    def test_api_create_field_002(server):
        """Try to create ``tags`` attribute from API.

        Try to call not supported POST operation for /tags.
        """

        request_body = {
            'data': [{
                'type': 'reference',
                'attributes': Request.gitlog
            }]
        }
        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '368'
        }
        expect_body = {
            'meta': Content.get_api_meta(),
            'errors': [{
                'status': '405',
                'statusString': '405 Method Not Allowed',
                'module': 'snippy.testing.testing:123',
                'title': 'fields api does not support method: POST'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_post(
            path='/api/snippy/rest/tags',
            headers={'accept': 'application/json'},
            body=json.dumps(request_body))
        assert result.status == falcon.HTTP_405
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
        Content.assert_storage(None)
Ejemplo n.º 3
0
    def test_api_delete_reference_002(server):
        """Try to delete reference.

        Try to send DELETE /reference{id} with ``id`` in URI does not exist.
        """

        storage = {'data': [Storage.pytest, Storage.gitlog, Storage.regexp]}
        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '370'
        }
        expect_body = {
            'meta':
            Content.get_api_meta(),
            'errors': [{
                'status':
                '404',
                'statusString':
                '404 Not Found',
                'module':
                'snippy.testing.testing:123',
                'title':
                'cannot find content with content identity: beefbeef'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_delete(
            path='/api/snippy/rest/references/beefbeef',
            headers={'accept': 'application/json'})
        assert result.status == falcon.HTTP_404
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
        Content.assert_storage(storage)
Ejemplo n.º 4
0
    def test_api_search_groups_004(server):
        """Get specific content based on ``groups`` attribute.

        Send GET /groups to get unique groups. In this case the ``sall``
        query parameter is used to limit the search. The search is made
        from all categories by default.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '69'
        }
        expect_body = {
            'data': {
                'type': 'groups',
                'attributes': {
                    'groups': {
                        'python': 1
                    }
                }
            }
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/groups',
            headers={'accept': 'application/vnd.api+json'},
            query_string='sall=pytest')
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 5
0
    def test_api_search_groups_002(server):
        """Get unique content based on ``groups`` attribute.

        Send GET /groups to get unique groups only from solution category.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '69'
        }
        expect_body = {
            'data': {
                'type': 'groups',
                'attributes': {
                    'groups': {
                        'docker': 1
                    }
                }
            }
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/groups',
            headers={'accept': 'application/vnd.api+json'},
            query_string='scat=solution')
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 6
0
    def test_api_hello_api_004():
        """Test server hello response.

        Send GET /api/snippy to get server hello response. In this case the
        server base path is changed from default and it is set in correct
        format.
        """

        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()
Ejemplo n.º 7
0
    def test_api_update_field_002(server):
        """"Try to update ``groups`` from /groups API endpoint.

        Try to send PUT /groups/{id} that is not supported.
        """

        request_body = {
            'data': [{
                'type': 'reference',
                'attributes': Request.gitlog
            }]
        }
        expect_headers = {
            'content-type': 'application/vnd.api+json',
            'content-length': '0'
        }
        expect_body = None
        result = testing.TestClient(server.server.api).simulate_put(
            path='/api/snippy/rest/groups/1',
            headers={'accept': 'application/json'},
            body=json.dumps(request_body))
        assert result.status == falcon.HTTP_404
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
        Content.assert_storage(None)
Ejemplo n.º 8
0
    def test_api_search_solution_field_006(server):
        """Get specific solution field.

        Try to send GET /solutions/{id}/notexist for existing solution. In
        this case the field name does not exist.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '360'
        }
        expect_body = {
            'meta':
            Content.get_api_meta(),
            'errors': [{
                'status': '400',
                'statusString': '400 Bad Request',
                'module': 'snippy.testing.testing:123',
                'title': 'resource field does not exist: notexist'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/solutions/4346ba4c79247430/notexist',
            headers={'accept': 'application/vnd.api+json'})
        assert result.status == falcon.HTTP_400
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 9
0
    def test_api_search_reference_field_016(server):
        """Get resource attribute.

        Try to send GET /references/{id}/notexist for existing reference.
        In this case the attribute does not exist.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '360'
        }
        expect_body = {
            'meta':
            Content.get_api_meta(),
            'errors': [{
                'status': '400',
                'statusString': '400 Bad Request',
                'module': 'snippy.testing.testing:123',
                'title': 'resource field does not exist: notexist'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/references/5c2071094dbfaa33/notexist',
            headers={'accept': 'application/vnd.api+json'})
        assert result.status == falcon.HTTP_400
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 10
0
    def test_api_search_solution_014(server):
        """Search solution without search parameters.

        Send GET /solutions without defining search parameters. In this
        case all content should be returned.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '4847'
        }
        expect_body = {
            'meta': {
                'count': 2,
                'limit': 20,
                'offset': 0,
                'total': 2
            },
            'data': [{
                'type': 'solution',
                'id': Solution.BEATS_UUID,
                'attributes': Storage.ebeats
            }, {
                'type': 'solution',
                'id': Solution.NGINX_UUID,
                'attributes': Storage.dnginx
            }]
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/solutions',
            headers={'accept': 'application/json'},
            query_string='limit=20&sort=brief')
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 11
0
    def test_api_search_solution_field_005(server):
        """Get specific solution field.

        Send GET /solutions/{id}/lnks for existing solution.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '309'
        }
        expect_body = {
            'data': {
                'type': 'solution',
                'id': Solution.BEATS_UUID,
                'attributes': {
                    'links': Storage.ebeats['links']
                }
            },
            'links': {
                'self':
                'http://falconframework.org/api/snippy/rest/solutions/21cd5827-b6ef-4067-b5ac-3ceac07dde9f/links'
            }
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/solutions/4346ba4c79247430/links',
            headers={'accept': 'application/vnd.api+json'})
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 12
0
    def test_api_search_solution_012(server):
        """Search solution with digets.

        Send GET /api/snippy/rest/solutions/{id} to get explicit solution
        based on digest. In this case the solution is found.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '2279'
        }
        expect_body = {
            'meta': {
                'count': 1,
                'limit': 20,
                'offset': 0,
                'total': 1
            },
            'data': {
                'type': 'solution',
                'id': Solution.BEATS_UUID,
                'attributes': Storage.ebeats
            },
            'links': {
                'self':
                'http://falconframework.org/api/snippy/rest/solutions/' +
                Solution.BEATS_UUID
            }
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/solutions/4346ba4c79247430',
            headers={'accept': 'application/json'})
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 13
0
    def test_api_search_solution_007(server):
        """Search solution with GET.

        Try to send GET /solutions with sort parameter set to attribute
        name that is not existing. The sort must fall to default sorting.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '385'
        }
        expect_body = {
            'meta':
            Content.get_api_meta(),
            'errors': [{
                'status':
                '400',
                'statusString':
                '400 Bad Request',
                'module':
                'snippy.testing.testing:123',
                'title':
                'sort option validation failed for non existent field=notexisting'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/solutions',
            headers={'accept': 'application/json'},
            query_string='sall=docker%2Cswarm&limit=20&sort=notexisting')
        assert result.status == falcon.HTTP_400
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 14
0
    def test_api_create_snippet_001(server):
        """Create one Snippet with POST.

        Send POST /snippets to create a new resource. The created snippet
        is sent in the HTTP request ``data`` attribute as a list of objects.
        """

        storage = {'data': [Storage.remove]}
        storage['data'][0]['uuid'] = Content.UUID1
        request_body = {
            'data': [{
                'type': 'snippet',
                'attributes': Request.remove
            }]
        }
        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '685'
        }
        expect_body = {
            'data': [{
                'type': 'snippet',
                'id': Content.UUID1,
                'attributes': storage['data'][0]
            }]
        }
        result = testing.TestClient(server.server.api).simulate_post(
            path='/api/snippy/rest/snippets',
            headers={'accept': 'application/vnd.api+json'},
            body=json.dumps(request_body))
        assert result.status == falcon.HTTP_201
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
        Content.assert_storage(storage)
Ejemplo n.º 15
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()
Ejemplo n.º 16
0
    def test_api_search_reference_007(server):
        """Search reference from tag fields.

        Try to send GET /references with search tag keywords that do not
        result any matches.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '340'
        }
        expect_body = {
            'meta':
            Content.get_api_meta(),
            'errors': [{
                'status': '404',
                'statusString': '404 Not Found',
                'module': 'snippy.testing.testing:123',
                'title': 'cannot find resources'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/references',
            headers={'accept': 'application/json'},
            query_string=
            'stag=notfound&limit=10&sort=-brief&fields=brief,category')
        assert result.status == falcon.HTTP_404
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 17
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()
Ejemplo n.º 18
0
    def test_api_search_reference_008(server):
        """Search reference with digets.

        Send GET /api/snippy/rest/references/{id} to get explicit reference
        based on digest. In this case the reference is found.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '751'
        }
        expect_body = {
            'meta': {
                'count': 1,
                'limit': 20,
                'offset': 0,
                'total': 1
            },
            'data': {
                'type': 'reference',
                'id': Reference.GITLOG_UUID,
                'attributes': Storage.gitlog
            },
            'links': {
                'self':
                'http://falconframework.org/api/snippy/rest/references/' +
                Reference.GITLOG_UUID
            }
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/references/5c20',
            headers={'accept': 'application/json'})
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 19
0
    def test_api_update_field_001(server):
        """Try to update ``groups`` from /groups API endpoint.

        Try to send PUT /groups that is not supported.
        """

        request_body = {
            'data': [{
                'type': 'reference',
                'attributes': Request.gitlog
            }]
        }
        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '367'
        }
        expect_body = {
            'meta':
            Content.get_api_meta(),
            'errors': [{
                'status': '405',
                'statusString': '405 Method Not Allowed',
                'module': 'snippy.testing.testing:123',
                'title': 'fields api does not support method: PUT'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_put(
            path='/api/snippy/rest/groups',
            headers={'accept': 'application/json'},
            body=json.dumps(request_body))
        assert result.status == falcon.HTTP_405
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
        Content.assert_storage(None)
Ejemplo n.º 20
0
    def test_api_search_reference_009(server):
        """Search reference with digets.

        Try to send GET /references/{id} with digest that is not found.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '395'
        }
        expect_body = {
            'meta':
            Content.get_api_meta(),
            'errors': [{
                'status':
                '404',
                'statusString':
                '404 Not Found',
                'module':
                'snippy.testing.testing:123',
                'title':
                'content identity: 101010101010101 was not unique and matched to: 0 resources'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/references/101010101010101',
            headers={'accept': 'application/json'})
        assert result.status == falcon.HTTP_404
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 21
0
    def test_api_create_solution_006(server):
        """Try to create solution with resource id.

        Try to send POST /solutions/{id} to create a new resource with
        resource ID in URL. The POST method is not overriden with custom
        ``X-HTTP-Method-Override`` header.
        """

        request_body = {
            'data': [{
                'type': 'solution',
                'attributes': Request.dnginx
            }]
        }
        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '403'
        }
        expect_body = {
            'meta': Content.get_api_meta(),
            'errors': [{
                'status': '400',
                'statusString': '400 Bad Request',
                'module': 'snippy.testing.testing:123',
                'title': 'cannot create resource with id, use x-http-method-override to override the request'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_post(
            path='/api/snippy/rest/solutions/53908d68425c61dc',
            headers={'accept': 'application/json'},
            body=json.dumps(request_body))
        assert result.status == falcon.HTTP_400
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
        Content.assert_storage(None)
Ejemplo n.º 22
0
    def test_api_search_reference_010(server):
        """Search reference without search parameters.

        Send GET /references without defining search keywords. In this case
        all content should be returned.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '1278'
        }
        expect_body = {
            'meta': {
                'count': 2,
                'limit': 20,
                'offset': 0,
                'total': 2
            },
            'data': [{
                'type': 'reference',
                'id': Reference.GITLOG_UUID,
                'attributes': Storage.gitlog
            }, {
                'type': 'reference',
                'id': Reference.REGEXP_UUID,
                'attributes': Reference.REGEXP
            }]
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/references',
            headers={'accept': 'application/json'},
            query_string='limit=20&sort=brief')
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 23
0
    def test_api_search_tags_002(server):
        """Try to get unique content based on ``tags`` attribute.

        Try to send GET /groups to get unique groups. In this case the ``scat``
        query parameter limits the search to solution category. There are no
        resources stored in the searched category.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '363'
        }
        expect_body = {
            'meta': Content.get_api_meta(),
            'errors': [{
                'status': '404',
                'statusString': '404 Not Found',
                'module': 'snippy.testing.testing:123',
                'title': 'cannot find unique fields for tags attribute'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/tags',
            headers={'accept': 'application/vnd.api+json'},
            query_string='scat=solution')
        assert result.status == falcon.HTTP_404
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 24
0
    def test_api_search_reference_011(server):
        """Search reference without search parameters.

        Send GET /references without defining search parameters.
        In this case only one reference must be returned because the
        limit is set to one. Also the sorting based on brief field
        causes the last reference to be returned.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '707'
        }
        expect_body = {
            'meta': {
                'count': 1,
                'limit': 1,
                'offset': 0,
                'total': 2
            },
            'data': [{
                'type': 'reference',
                'id': Reference.REGEXP_UUID,
                'attributes': Reference.REGEXP
            }]
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/references',
            headers={'accept': 'application/json'},
            query_string='limit=1&sort=-brief')
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 25
0
    def test_api_search_groups_003(server):
        """Get unique content based on ``groups`` attribute.

        Send GET /groups to get unique groups. In this case the ``limit``
        query parameter is set to zero. The limit parameter does not have
        any effect in the groups API endpoint.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '82'
        }
        expect_body = {
            'data': {
                'type': 'groups',
                'attributes': {
                    'groups': {
                        'docker': 3,
                        'python': 1
                    }
                }
            }
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/groups',
            headers={'accept': 'application/vnd.api+json'},
            query_string='limit=0')
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 26
0
    def test_api_search_reference_paginate_001(server):
        """Search reference with GET.

        Send GET /reference so that pagination is applied with limit zero.
        This is a special case that returns the metadata but the data list
        is empty. This query uses sall parameter with regexp . (dot) which
        matches to all references. The non-zero offset does not affect to the
        total count of query result and it is just returned in the meta as it
        was provided.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '71'
        }
        expect_body = {
            'meta': {
                'count': 0,
                'limit': 0,
                'offset': 4,
                'total': 3
            },
            'data': [],
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/references',
            headers={'accept': 'application/json'},
            query_string='sall=.&offset=4&limit=0&sort=brief')
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 27
0
    def test_api_create_solution_007(server):
        """Try to create solution with malformed JSON request.

        Try to send POST /solutions to create new solution with malformed
        JSON request. In this case the top level json object is incorrect
        because it contains only an empty list.
        """

        request_body = {'data': [{}]}
        expect_headers_p3 = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '848'
        }
        expect_headers_p2 = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '873'
        }
        expect_body = {
            'meta':
            Content.get_api_meta(),
            'errors': [{
                'status': '400',
                'statusString': '400 Bad Request',
                'module': 'snippy.testing.testing:123',
                'title': 'json media validation failed'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_post(
            path='/api/snippy/rest/solutions',
            headers={'accept': 'application/json'},
            body=json.dumps(request_body))
        assert result.status == falcon.HTTP_400
        assert result.headers in (expect_headers_p2, expect_headers_p3)
        Content.assert_restapi(result.json, expect_body)
        Content.assert_storage(None)
Ejemplo n.º 28
0
    def test_api_search_reference_field_015(server):
        """Get resource attribute.

        Send GET /references/{id}/digest for existing resource.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '291'
        }
        expect_body = {
            'data': {
                'type': 'reference',
                'id': Reference.GITLOG_UUID,
                'attributes': {
                    'digest': Reference.GITLOG_DIGEST
                }
            },
            'links': {
                'self':
                'http://falconframework.org/api/snippy/rest/references/31cd5827-b6ef-4067-b5ac-3ceac07dde9f/digest'
            }
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/references/5c2071094dbfaa33/digest',
            headers={'accept': 'application/vnd.api+json'})
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
Ejemplo n.º 29
0
    def test_api_delete_snippet_003(server):
        """Try to delete snippet.

        Try to send DELETE /snippets without ``id`` in URI that identifies
        the delete resource.
        """

        content = {'data': [Storage.remove, Storage.forced]}
        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '368'
        }
        expect_body = {
            'meta':
            Content.get_api_meta(),
            'errors': [{
                'status':
                '404',
                'statusString':
                '404 Not Found',
                'module':
                'snippy.testing.testing:123',
                'title':
                'cannot delete content without identified resource'
            }]
        }
        result = testing.TestClient(server.server.api).simulate_delete(
            path='/api/snippy/rest/snippets',
            headers={'accept': 'application/vnd.api+json'})
        assert result.status == falcon.HTTP_404
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)
        Content.assert_storage(content)
Ejemplo n.º 30
0
    def test_api_search_groups_002(server):
        """Get specific content based on ``groups`` attribute.

        Call GET /groups/docker,python to get content from the docker and
        python groups with search all keywords and content limit applied.
        """

        expect_headers = {
            'content-type': 'application/vnd.api+json; charset=UTF-8',
            'content-length': '4948'
        }
        expect_body = {
            'meta': {
                'count': 2,
                'limit': 20,
                'offset': 0,
                'total': 2
            },
            'data': [{
                'type': 'reference',
                'id': Reference.PYTEST_UUID,
                'attributes': Storage.pytest
            }, {
                'type': 'solution',
                'id': Solution.KAFKA_UUID,
                'attributes': Storage.dkafka
            }]
        }
        result = testing.TestClient(server.server.api).simulate_get(
            path='/api/snippy/rest/groups/docker,python',
            headers={'accept': 'application/vnd.api+json'},
            query_string='sall=test&limit=20&sort=brief')
        assert result.status == falcon.HTTP_200
        assert result.headers == expect_headers
        Content.assert_restapi(result.json, expect_body)