def test_cli_create_solution_003(snippy): """Try to create solution from CLI. Try to create new solution without any changes to template. """ cause = snippy.run(['snippy', 'create', '--scat', 'solution', '--format', 'text']) assert cause == 'NOK: content was not stored because it was matching to an empty template' Content.assert_storage(None)
def test_api_update_reference_002(server): """Update one reference with PUT request. Send PUT /references/{id} to update existing resource. The PUT request contains only the mandatory links attribute. All other attributes must be set to their default values in the HTTP response. """ storage = { 'data': [{ 'category': 'reference', 'data': (), 'brief': '', 'description': '', 'name': '', 'groups': ('default',), 'tags': (), 'links': Reference.PYTEST['links'], 'source': '', 'versions': (), 'filename': '', 'created': Content.GITLOG_TIME, 'updated': Content.PYTEST_TIME, 'uuid': Reference.GITLOG_UUID, 'digest': '4a868cc74e3d32a4340e1a2fd17d0df815777c67f827aeedbb35869b740dd720' }] } request_body = { 'data': { 'type': 'snippet', 'attributes': { 'links': storage['data'][0]['links'], } } } expect_headers = { 'content-type': 'application/vnd.api+json; charset=UTF-8', 'content-length': '650' } 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_put( 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)
def test_api_create_reference_005(server): """Update Reference resource with POST that maps to PATCH. Send POST /references/{id} to update existing resource with the ``X-HTTP-Method-Override`` header that overrides the POST method as PATCH. Only the attributes sent in the PATCH method must be changed. In this case the resource ``created`` attribute must remain in the initial value and the ``updated`` attribute must be set to reflect the update time. The ``uuid`` attribute must not be changed from it's initial value. """ storage = {'data': [Storage.gitlog]} storage['data'][0]['brief'] = Reference.REGEXP['brief'] storage['data'][0]['links'] = Reference.REGEXP['links'] storage['data'][0]['updated'] = Content.REGEXP_TIME storage['data'][0][ 'digest'] = 'ee4a072a5a7a661a8c5d8e8f2aac88267c47fbf0b26db19b97d0b72bae3d74f0' request_body = { 'data': { 'type': 'reference', 'attributes': { 'brief': Reference.REGEXP['brief'], 'links': Reference.REGEXP['links'] } } } expect_headers = { 'content-type': 'application/vnd.api+json; charset=UTF-8', 'content-length': '760' } expect_body = { 'links': { 'self': 'http://falconframework.org/api/snippy/rest/references/' + Reference.GITLOG_UUID }, 'data': { 'type': 'reference', 'id': Reference.GITLOG_UUID, 'attributes': storage['data'][0] } } result = testing.TestClient(server.server.api).simulate_post( path='/api/snippy/rest/references/5c2071094dbfaa33', headers={ 'accept': 'application/vnd.api+json; charset=UTF-8', 'X-HTTP-Method-Override': 'PATCH' }, 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)
def test_cli_create_snippet_004(snippy): """Try to create snippet from CLI. Try to create new snippet without any changes to snippet template. """ cause = snippy.run( ['snippy', 'create', '--editor', '--format', 'text']) assert cause == 'NOK: content was not stored because it was matching to an empty template' Content.assert_storage(None)
def test_cli_create_solution_004(snippy): """Try to create solution from CLI. Try to create new solution with empty data. In this case the whole template is deleted and the edited solution is an empty string. """ cause = snippy.run(['snippy', 'create', '--scat', 'solution', '--format', 'text']) assert cause == 'NOK: could not identify content category - please keep template tags in place' Content.assert_storage(None)
def test_cli_delete_reference_006(snippy): """Delete reference with uuid. Try to delete content with uuid that does not match to any content. """ content = {'data': [Reference.GITLOG, Reference.REGEXP]} cause = snippy.run(['snippy', 'delete', '-u', '1234567']) assert cause == 'NOK: cannot find content with content uuid: 1234567' Content.assert_storage(content)
def test_cli_delete_reference_005(snippy): """Delete reference with uuid. Try to delete content with empty uuid string. """ content = {'data': [Reference.GITLOG, Reference.REGEXP]} cause = snippy.run(['snippy', 'delete', '-u', '']) assert cause == 'NOK: cannot use empty content uuid for delete operation' Content.assert_storage(content)
def test_cli_delete_reference_003(snippy): """Delete reference with digest. Try to delete reference with message digest that cannot be found. """ content = {'data': [Reference.GITLOG, Reference.REGEXP]} cause = snippy.run(['snippy', 'delete', '-d', '123456789abcdef0']) assert cause == 'NOK: cannot find content with message digest: 123456789abcdef0' Content.assert_storage(content)
def test_cli_delete_snippet_005(snippy): """Delete snippet with digest. Try to delete snippet with message digest that cannot be found. """ content = {'data': [Snippet.REMOVE, Snippet.FORCED]} cause = snippy.run(['snippy', 'delete', '-d', '123456789abcdef0']) assert cause == 'NOK: cannot find content with message digest: 123456789abcdef0' Content.assert_storage(content)
def test_cli_update_snippet_010(snippy): """Update snippet with ``--content`` option. Try to update snippet based on content data that is not found. """ content = {'data': [Snippet.REMOVE, Snippet.FORCED]} cause = snippy.run(['snippy', 'update', '-c', 'snippet not existing']) assert cause == 'NOK: cannot find content with content data: snippet not existing' Content.assert_storage(content)
def test_cli_create_solution_009(snippy): """Try to create solution from CLI. Try to create new solution by from command line with --no-editor option when the mandatory data is not defined. """ cause = snippy.run(['snippy', 'create', '--scat', 'solution', '--brief', 'Short brief', '--no-editor']) assert cause == 'NOK: content was not stored because mandatory content field data is empty' Content.assert_storage(None)
def test_api_create_snippet_004(server): """Create one Snippet with POST. Send POST /snippets to create a new resource. In this case snippet content data, tags and links attributes are defined in string context where each line is separated with a newline. The string format is not supported for these attributes and this must generate a HTTP error. """ request_body = { 'data': [{ 'type': 'snippet', 'attributes': { 'data': Const.DELIMITER_DATA.join(Snippet.EXITED['data']), 'brief': Snippet.EXITED['brief'], 'groups': Snippet.EXITED['groups'], 'tags': Const.DELIMITER_TAGS.join(Snippet.EXITED['tags']), 'links': Const.DELIMITER_LINKS.join(Snippet.EXITED['links']) } }] } expect_headers_p3 = { 'content-type': 'application/vnd.api+json; charset=UTF-8', 'content-length': '1838' } expect_headers_p34 = { 'content-type': 'application/vnd.api+json; charset=UTF-8', 'content-length': '1841' } expect_headers_p2 = { 'content-type': 'application/vnd.api+json; charset=UTF-8', 'content-length': '1871' } 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/snippets', 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, expect_headers_p34) Content.assert_restapi(result.json, expect_body) Content.assert_storage(None)
def test_api_create_snippet_014(server): """Update snippet with POST that maps to PATCH. Send POST /snippets with the ``X-HTTP-Method-Override`` header to update a resource. In this case the resource exists and the content is updated. In this case the resource ``created`` attribute must remain in the initial value and the ``updated`` attribute must be set to reflect the update time. The ``uuid`` attribute must not be changed from it's initial value. """ storage = {'data': [Storage.forced]} storage['data'][0]['data'] = Snippet.REMOVE['data'] storage['data'][0]['updated'] = Content.FORCED_TIME storage['data'][0]['uuid'] = Snippet.FORCED_UUID storage['data'][0][ 'digest'] = 'a9e137c08aee09852797a974ef91b871c48915fecf25b2e89c5bdba4885b2bd2' request_body = { 'data': { 'type': 'snippet', 'attributes': { 'data': Snippet.REMOVE['data'] } } } expect_headers = { 'content-type': 'application/vnd.api+json; charset=UTF-8', 'content-length': '886' } expect_body = { 'links': { 'self': 'http://falconframework.org/api/snippy/rest/snippets/' + Snippet.FORCED_UUID }, 'data': { 'type': 'snippet', 'id': Snippet.FORCED_UUID, 'attributes': storage['data'][0] } } result = testing.TestClient(server.server.api).simulate_post( path='/api/snippy/rest/snippets/53908d68425c61dc', headers={ 'accept': 'application/vnd.api+json', 'X-HTTP-Method-Override': 'PATCH' }, 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)
def test_cli_update_snippet_011(snippy): """Update snippet with ``--content`` option. Try to update snippet with empty content data. Nothing must be updated in this case because there is more than one content stored. """ content = {'data': [Snippet.REMOVE, Snippet.FORCED]} cause = snippy.run(['snippy', 'update', '-c', '']) assert cause == 'NOK: cannot use empty content data for update operation' Content.assert_storage(content)
def test_cli_delete_reference_011(snippy): """Delete reference with data. Try to delete reference with empty content data. Nothing should be deleted in this case because there is more than one content left. """ content = {'data': [Reference.GITLOG, Reference.REGEXP]} cause = snippy.run(['snippy', 'delete', '--content', '']) assert cause == 'NOK: cannot use empty content data for delete operation' Content.assert_storage(content)
def test_cli_delete_reference_001(snippy): """Delete reference with digest. Delete reference with short 16 byte version of message digest. """ content = {'data': [Reference.GITLOG]} Content.assert_storage_size(2) cause = snippy.run(['snippy', 'delete', '-d', 'cb9225a81eab8ced']) assert cause == Cause.ALL_OK Content.assert_storage(content)
def test_cli_delete_solution_002(snippy): """Delete solution with digest. Delete solution with without explicitly specifying solution category. """ content = {'data': [Solution.BEATS]} Content.assert_storage_size(2) cause = snippy.run(['snippy', 'delete', '-d', '6cfe47a8880a8f81']) assert cause == Cause.ALL_OK Content.assert_storage(content)
def test_cli_delete_solution_004(snippy): """Delete solution with digest. Delete solution with long 16 byte version of message digest. """ content = {'data': [Solution.BEATS]} Content.assert_storage_size(2) cause = snippy.run(['snippy', 'delete', '--scat', 'solution', '-d', '6cfe47a8880a8f81b66ff6bd71e795069ed1dfdd259c9fd181133f683c7697eb']) # pylint: disable=line-too-long assert cause == Cause.ALL_OK Content.assert_storage(content)
def test_cli_create_solution_005(snippy): """Try to create solution from CLI. Try to create new solution with a template that cannot be identified. In this case the user has changed the input template completely and it has lost tags that identify it as a solution content. """ cause = snippy.run(['snippy', 'create', '--scat', 'solution', '--format', 'text']) assert cause == 'NOK: could not identify content category - please keep template tags in place' Content.assert_storage(None)
def test_cli_update_reference_008(snippy): """Update reference with ``uuid`` option. Try to update reference based on uuid that cannot be found. """ content = {'data': [Reference.GITLOG, Reference.REGEXP]} cause = snippy.run( ['snippy', 'update', '--scat', 'reference', '-u', '9999994']) assert cause == 'NOK: cannot find content with content uuid: 9999994' Content.assert_storage(content)
def test_cli_create_solution_002(snippy): """Try to create solution from CLI. Try to create same solution again with exactly the same content data. """ content = {'data': [Solution.BEATS, Solution.NGINX]} cause = snippy.run( ['snippy', 'create', '--scat', 'solution', '--format', 'text']) assert cause == 'NOK: content data already exist with digest 4346ba4c79247430' Content.assert_storage(content)
def test_cli_delete_snippet_001(snippy): """Delete snippet with digest. Delete snippet with short 16 byte version of message digest. """ content = {'data': [Snippet.REMOVE]} Content.assert_storage_size(2) cause = snippy.run(['snippy', 'delete', '-d', '53908d68425c61dc']) assert cause == Cause.ALL_OK Content.assert_storage(content)
def test_cli_delete_snippet_011(snippy): """Delete snippet with data. Try to delete snippet with empty content data. Nothing should be deleted in this case because there is more than one content left. """ content = {'data': [Snippet.REMOVE, Snippet.FORCED]} cause = snippy.run(['snippy', 'delete', '--content', '']) assert cause == 'NOK: cannot use empty content data for delete operation' Content.assert_storage(content)
def test_cli_delete_snippet_007(snippy): """Delete snippet with dgiest. Try to delete snippet with short version of digest that does not match to any existing message digest. """ content = {'data': [Snippet.REMOVE, Snippet.FORCED]} cause = snippy.run(['snippy', 'delete', '-d', '123456']) assert cause == 'NOK: cannot find content with message digest: 123456' Content.assert_storage(content)
def test_cli_update_snippet_007(snippy): """Update snippet with ``--digest`` option. Try to update snippet with empty message digest. Nothing should be updated in this case because the empty digest matches to more than one snippet. Only one content can be updated at the time. """ content = {'data': [Snippet.REMOVE, Snippet.FORCED]} cause = snippy.run(['snippy', 'update', '-d', '', '--format', 'text']) assert cause == 'NOK: cannot use empty message digest for update operation' Content.assert_storage(content)
def test_cli_delete_snippet_004(snippy): """Delete snippet with dgiest. Delete snippet with empty message digest when there is only one content stored. In this case the last content can be deleted with empty digest. """ Content.assert_storage_size(1) cause = snippy.run(['snippy', 'delete', '-d', '']) assert cause == Cause.ALL_OK Content.assert_storage(None)
def test_cli_delete_snippet_002(snippy): """Delete snippet with digest. Delete snippet with very short version of digest that matches to one snippet. """ content = {'data': [Snippet.FORCED]} Content.assert_storage_size(2) cause = snippy.run(['snippy', 'delete', '-d', '54e41']) assert cause == Cause.ALL_OK Content.assert_storage(content)
def test_cli_delete_snippet_012(snippy): """Delete snippet with search. Delete snippet based on search keyword that results one hit. In this case the content is deleted. """ content = {'data': [Snippet.REMOVE]} Content.assert_storage_size(2) cause = snippy.run(['snippy', 'delete', '--sall', 'redis']) assert cause == Cause.ALL_OK Content.assert_storage(content)
def test_cli_delete_snippet_009(snippy): """Delete snippet with data. Try to delete snippet with content data that does not exist. In this case the content data is not truncated. """ content = {'data': [Snippet.REMOVE, Snippet.FORCED]} cause = snippy.run( ['snippy', 'delete', '--content', 'not found content']) assert cause == 'NOK: cannot find content with content data: not found content' Content.assert_storage(content)
def test_cli_update_snippet_012(snippy): """Update snippet with ``--content`` option. Try to update snippet with content data that matches to two different snippets. Nothing must be updated in this case because content can be updated only if it is uniquely identified. """ content = {'data': [Snippet.REMOVE, Snippet.FORCED]} cause = snippy.run(['snippy', 'update', '-c', 'docker']) assert cause == 'NOK: content data docker matched 2 times preventing update operation' Content.assert_storage(content)