Пример #1
0
 def test_fromcollection(self):
     try:
         openman.from_collection()
     except Exception as e:
         self.assertTrue(isinstance(e, openman.errors.OpenmanException))
     try:
         openman.from_collection('non-existant-file')
     except Exception as e:
         self.assertTrue(isinstance(e, FileNotFoundError))
Пример #2
0
    def test_parsecollection_ctor(self):
        try:
            collection = CollectionParser()
        except Exception as e:
            self.assertTrue(
                isinstance(e, openman.errors.CollectionParserException))

        try:
            collection = CollectionParser.parse()
        except Exception as e:
            self.assertTrue(
                isinstance(e, openman.errors.CollectionParserException))

        try:
            collection = CollectionParser([1, 2])
        except Exception as e:
            self.assertTrue(
                isinstance(e, openman.errors.CollectionParserException))

        # collection should be a valid postman collection
        postmancollection = openman.from_collection(self.collection_file)
        try:
            collection = CollectionParser(postmancollection)
        except Exception as e:
            self.assertTrue(
                isinstance(e, openman.errors.CollectionParserException))
Пример #3
0
 def test_requestbody(self, *args, **kwargs):
     collection = from_collection(self.collection_file)
     samplerequestitem = collection['item'][0]['item'][2]
     assert isinstance(samplerequestitem, dict)
     request_item = RequestItemParser(samplerequestitem)
     requestbody_spec = Operation(request_item).request_body()
     self.assertEqual(
         {
             'content': {
                 '*/*': {
                     'schema': {
                         'type': 'object',
                         'properties': {
                             'foo1': {
                                 'type': 'string'
                             },
                             'foo2': {
                                 'type': 'string'
                             }
                         },
                         'required': ['foo1', 'foo2']
                     },
                     'example': {
                         'value': {
                             'foo1': 'bar1',
                             'foo2': 'bar2'
                         }
                     },
                     'x-link-response': []
                 }
             }
         }, requestbody_spec)
Пример #4
0
    def test_parserequest_ctor(self):
        try:
            requestitem = RequestItemParser()
        except Exception as e:
            self.assertTrue(
                isinstance(e, openman.errors.RequestItemParserException))

        try:
            requestitem = RequestItemParser.parse()
        except Exception as e:
            self.assertTrue(
                isinstance(e, openman.errors.RequestItemParserException))

        try:
            requestitem = RequestItemParser([1, 2])
        except Exception as e:
            self.assertTrue(
                isinstance(e, openman.errors.RequestItemParserException))

        # request should be a single valid postman request, not a collection
        collection = openman.from_collection(self.collection_file)
        try:
            requestitem = RequestItemParser(collection)
        except Exception as e:
            self.assertTrue(
                isinstance(e, openman.errors.RequestItemParserException))
Пример #5
0
 def test_openapi(self): 
     collection = CollectionParser(from_collection(self.collection_file))
     spec = Spec(collection)
     self.assertEqual(
         '3.0.0',
         spec.openapi
     )
Пример #6
0
 def test_get_request(self):
     collection = openman.from_collection(self.collection_file)
     samplerequest = collection['item'][0]['item'][0]
     assert isinstance(samplerequest, dict)
     requestitem = RequestItemParser.parse(samplerequest)
     request = requestitem.get_request()
     self.assertEqual('get', request.method)
Пример #7
0
 def test_get_response(self):
     collection = openman.from_collection(self.collection_file)
     samplerequest = collection['item'][0]['item'][0]
     assert isinstance(samplerequest, dict)
     requestitem = RequestItemParser.parse(samplerequest)
     responses = requestitem.get_responses()
     self.assertIn(200, [response.code for response in responses])
Пример #8
0
 def test_summary(self):
     collection = openman.from_collection(self.collection_file)
     samplerequest = collection['item'][0]['item'][0]
     assert isinstance(samplerequest, dict)
     requestitem = RequestItemParser.parse(samplerequest)
     self.assertEqual('GET Request', requestitem.summary)
     self.assertEqual('GET Request', requestitem.get_summary())
Пример #9
0
 def test_folders(self):
     postmancollection = openman.from_collection(self.collection_file)
     assert isinstance(postmancollection, dict)
     collection = CollectionParser.parse(postmancollection)
     folders = collection.get_folders()
     self.assertIn('Request Methods',
                   [folder.summary for folder in folders])
Пример #10
0
    def test_parsefolder_ctor(self):
        try:
            folder = FolderParser()
        except Exception as e:
            self.assertTrue(isinstance(e,
                                       openman.errors.FolderParserException))

        try:
            folder = FolderParser.parse()
        except Exception as e:
            self.assertTrue(isinstance(e,
                                       openman.errors.FolderParserException))

        try:
            folder = FolderParser([1, 2])
        except Exception as e:
            self.assertTrue(isinstance(e,
                                       openman.errors.FolderParserException))

        # folder should be a valid postman folder and not a collection
        postmancollection = openman.from_collection(self.collection_file)
        try:
            folder = FolderParser(postmancollection)
        except Exception as e:
            self.assertTrue(isinstance(e,
                                       openman.errors.FolderParserException))
Пример #11
0
 def test_parameters(self, *args, **kwargs):
     collection = from_collection(self.collection_file)
     samplerequestitem = collection['item'][0]['item'][0]
     assert isinstance(samplerequestitem, dict)
     request_item = RequestItemParser(samplerequestitem)
     param_spec = Operation(request_item).parameters()
     self.assertEqual(
         [{
             'in': 'query',
             'name': 'foo1',
             'schema': {
                 'type': 'string',
                 'example': 'bar1'
             },
             'x-link-response': [{
                 'value': 'bar1',
                 'x-response-id': 'a'
             }]
         }, {
             'in': 'query',
             'name': 'foo2',
             'schema': {
                 'type': 'string',
                 'example': 'bar2'
             },
             'x-link-response': [{
                 'value': 'bar2',
                 'x-response-id': 'a'
             }]
         }], param_spec)
Пример #12
0
 def test_content_type(self):
     collection = openman.from_collection(self.collection_file)
     sampleresponse = collection['item'][0]['item'][0]['response'][0]
     assert isinstance(sampleresponse, dict)
     response = ResponseParser.parse(sampleresponse)
     self.assertEqual('application/json', response.content_type)
     self.assertEqual('application/json', response.get_content_type())
Пример #13
0
 def test_name(self):
     postmancollection = openman.from_collection(self.collection_file)
     samplefolder = postmancollection['item'][0]
     assert isinstance(samplefolder, dict)
     folder = FolderParser.parse(samplefolder)
     self.assertEqual('Request Methods', folder.summary)
     self.assertEqual('Request Methods', folder.get_summary())
Пример #14
0
 def test_method(self):
     collection = openman.from_collection(self.collection_file)
     samplerequest = collection['item'][0]['item'][0]['request']
     assert isinstance(samplerequest, dict)
     request = RequestParser.parse(samplerequest)
     self.assertEqual('get', request.method)
     self.assertEqual('get', request.get_method())
Пример #15
0
 def test_code(self):
     collection = openman.from_collection(self.collection_file)
     sampleresponse = collection['item'][0]['item'][0]['response'][0]
     assert isinstance(sampleresponse, dict)
     response = ResponseParser.parse(sampleresponse)
     self.assertEqual(200, response.code)
     self.assertEqual(200, response.get_code())
Пример #16
0
 def test_path(self):
     collection = openman.from_collection(self.collection_file)
     samplerequest = collection['item'][0]['item'][0]['request'] # Request Methods
     assert isinstance(samplerequest, dict)
     request = RequestParser.parse(samplerequest)
     self.assertEqual('/get', request.path)
     self.assertEqual('/get', request.get_path(True))
     self.assertEqual(['get'], request.get_path())
Пример #17
0
 def test_requestitems(self):
     postmancollection = openman.from_collection(self.collection_file)
     assert isinstance(postmancollection, dict)
     collection = CollectionParser.parse(postmancollection)
     requestitems = collection.get_requestitems()
     self.assertIsInstance(requestitems[0], RequestItemParser)
     self.assertIn('PUT Request',
                   [requestitem.summary for requestitem in requestitems])
Пример #18
0
    def test_operationid(self):
        collection = from_collection(self.collection_file)
        samplerequestitem = collection['item'][0]['item'][0]
        assert isinstance(samplerequestitem, dict)
        request_item = RequestItemParser(samplerequestitem)

        operation_id = Operation(request_item).id()
        self.assertEqual('GetGet', operation_id)
Пример #19
0
 def test_request(self):
     collection = openman.from_collection(self.collection_file)
     sampleresponse = collection['item'][0]['item'][0]['response'][0]
     assert isinstance(sampleresponse, dict)
     response = ResponseParser.parse(sampleresponse)
     example = response.example
     self.assertIsInstance(example, openman.parser.RequestParser)
     self.assertEqual('/get', example.get_path(True))
     self.assertEqual('get', example.method)
Пример #20
0
 def test_headers(self):
     collection = openman.from_collection(self.collection_file)
     samplerequest = collection['item'][1]['item'][0]['request']
     assert isinstance(samplerequest, dict)
     request = RequestParser.parse(samplerequest)
     self.assertEqual({'my-sample-header': 'Lorem ipsum dolor sit amet'}, request.headers)
     self.assertEqual({'my-sample-header': 'Lorem ipsum dolor sit amet'}, request.get_headers())
     self.assertEqual('Lorem ipsum dolor sit amet', request.get_headers('my-sample-header'))
     self.assertIsNone(request.get_headers('NonExistant'))
Пример #21
0
 def test_description(self):
     postmancollection = openman.from_collection(self.collection_file)
     assert isinstance(postmancollection, dict)
     collection = CollectionParser.parse(postmancollection)
     self.assertEqual(
         'Postman Echo is service you can use to test your REST clients and make sample API calls. It provides endpoints for `GET`, `POST`, `PUT`, various auth mechanisms and other utility endpoints.\n\nThe documentation for the endpoints as well as example responses can be found at [https://postman-echo.com](https://postman-echo.com/?source=echo-collection-app-onboarding)',
         collection.description)
     self.assertEqual(
         'Postman Echo is service you can use to test your REST clients and make sample API calls. It provides endpoints for `GET`, `POST`, `PUT`, various auth mechanisms and other utility endpoints.\n\nThe documentation for the endpoints as well as example responses can be found at [https://postman-echo.com](https://postman-echo.com/?source=echo-collection-app-onboarding)',
         collection.get_description())
Пример #22
0
 def test_headers(self):
     collection = openman.from_collection(self.collection_file)
     sampleresponse = collection['item'][0]['item'][0]['response'][0]
     assert isinstance(sampleresponse, dict)
     response = ResponseParser.parse(sampleresponse)
     self.assertTrue(set({'Connection':'keep-alive'}).issubset(response.headers))
     self.assertEqual('keep-alive', response.get_headers('Connection'))
     self.assertTrue(
         set({'Content-Type': 'application/json; charset=utf-8'}).issubset(
             response.get_headers()
         ))
Пример #23
0
 def test_description(self):
     collection = openman.from_collection(self.collection_file)
     samplerequest = collection['item'][0]['item'][0]
     assert isinstance(samplerequest, dict)
     requestitem = RequestItemParser.parse(samplerequest)
     self.assertEqual(
         'The HTTP `GET` request method is meant to retrieve data from a server. The data\nis identified by a unique URI (Uniform Resource Identifier). \n\nA `GET` request can pass parameters to the server using \"Query String \nParameters\". For example, in the following request,\n\n> http://example.com/hi/there?hand=wave\n\nThe parameter \"hand\" has the value \"wave\".\n\nThis endpoint echoes the HTTP headers, request parameters and the complete\nURI requested.',
         requestitem.description)
     self.assertEqual(
         'The HTTP `GET` request method is meant to retrieve data from a server. The data\nis identified by a unique URI (Uniform Resource Identifier). \n\nA `GET` request can pass parameters to the server using \"Query String \nParameters\". For example, in the following request,\n\n> http://example.com/hi/there?hand=wave\n\nThe parameter \"hand\" has the value \"wave\".\n\nThis endpoint echoes the HTTP headers, request parameters and the complete\nURI requested.',
         requestitem.get_description())
Пример #24
0
 def test_description(self):
     postmancollection = openman.from_collection(self.collection_file)
     samplefolder = postmancollection['item'][0]
     assert isinstance(samplefolder, dict)
     folder = FolderParser.parse(samplefolder)
     self.assertEqual(
         'HTTP has multiple request \"verbs\", such as `GET`, `PUT`, `POST`, `DELETE`,\n`PATCH`, `HEAD`, etc. \n\nAn HTTP Method (verb) defines how a request should be interpreted by a server. \nThe endpoints in this section demonstrate various HTTP Verbs. Postman supports \nall the HTTP Verbs, including some rarely used ones, such as `PROPFIND`, `UNLINK`, \netc.\n\nFor details about HTTP Verbs, refer to [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9)\n',
         folder.description)
     self.assertEqual(
         'HTTP has multiple request \"verbs\", such as `GET`, `PUT`, `POST`, `DELETE`,\n`PATCH`, `HEAD`, etc. \n\nAn HTTP Method (verb) defines how a request should be interpreted by a server. \nThe endpoints in this section demonstrate various HTTP Verbs. Postman supports \nall the HTTP Verbs, including some rarely used ones, such as `PROPFIND`, `UNLINK`, \netc.\n\nFor details about HTTP Verbs, refer to [RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9)\n',
         folder.get_description())
Пример #25
0
 def test_requests(self):
     postmancollection = openman.from_collection(self.collection_file)
     samplefolder = postmancollection['item'][0]
     assert isinstance(samplefolder, dict)
     folder = FolderParser.parse(samplefolder)
     requests = folder.get_requestitems()
     self.assertTrue(
         set(['GET Request', 'POST Raw Text'
              ]).issubset(set([request.summary for request in requests])))
     self.assertEqual(
         set(['get', 'post', 'put', 'delete', 'patch']),
         set([request.get_request().method for request in requests]))
Пример #26
0
    def test_body_contenttype(self):
        collection = openman.from_collection(self.collection_file)
        samplerequest = collection['item'][0]['item'][2]['request']
        assert isinstance(samplerequest, dict)
        request = RequestParser.parse(samplerequest)
        self.assertEqual('application/x-www-form-urlencoded', request.body_contenttype)
        self.assertEqual('application/x-www-form-urlencoded', request.get_body_contenttype())

        samplerequest = collection['item'][0]['item'][1]['request']
        request = RequestParser.parse(samplerequest)
        self.assertEqual('*/*', request.body_contenttype)
        self.assertEqual('*/*', request.get_body_contenttype())
Пример #27
0
    def test_servers(self):
        collection = CollectionParser(from_collection(self.collection_file))
        spec = Spec(collection)
        self.assertEqual(["http://localhost"], spec.servers)
        spec.add_servers(["http://abc", "http://def"])
        self.assertEqual(["http://localhost", "http://abc", "http://def"],
                         spec.servers)

        spec.add_servers("jhk")
        self.assertEqual(
            ["http://localhost", "http://abc", "http://def", "jhk"],
            spec.servers,
        )
Пример #28
0
 def test_body(self):
     collection = openman.from_collection(self.collection_file)
     sampleresponse = collection['item'][0]['item'][0]['response'][0]
     assert isinstance(sampleresponse, dict)
     response = ResponseParser.parse(sampleresponse)
     response_body = response.get_body()
     self.assertEqual(['args', 'headers', 'url'], list(response.body.keys()))
     self.assertEqual(
         'https://postman-echo.com/get?foo1=bar1&foo2=bar2',
         response_body['url'])
     self.assertEqual({
             "foo1": "bar1",
             "foo2": "bar2"
         }, response_body['args'])
Пример #29
0
    def test_body(self):
        collection = openman.from_collection(self.collection_file)
        samplerequest = collection['item'][0]['item'][2]['request']
        assert isinstance(samplerequest, dict)
        request = RequestParser.parse(samplerequest)
        self.assertEqual({'foo1': 'bar1', 'foo2': 'bar2'}, request.body)
        self.assertEqual({'foo1': 'bar1', 'foo2': 'bar2'}, request.get_body())

        samplerequest = collection['item'][0]['item'][1]['request']
        request = RequestParser.parse(samplerequest)
        self.assertEqual(
            'This is expected to be sent back as part of response body.',
            request.body)
        self.assertEqual(
            'This is expected to be sent back as part of response body.',
            request.get_body())
Пример #30
0
 def test_query_string(self):
     collection = openman.from_collection(self.collection_file)
     samplerequest = collection['item'][0]['item'][0]['request']
     assert isinstance(samplerequest, dict)
     request = RequestParser.parse(samplerequest)
     self.assertEqual({'foo1': 'bar1', 'foo2': 'bar2'}, request.query_string)
     self.assertEqual({'foo1': 'bar1', 'foo2': 'bar2'}, request.get_query_string())
     # Disabled query string ignores item
     samplerequest['url']['query'][0]['disabled'] = True
     request = RequestParser.parse(samplerequest)
     self.assertEqual({'foo2': 'bar2'}, request.query_string)
     self.assertEqual({'foo2': 'bar2'}, request.get_query_string())
     # Non disabled query string includes item
     samplerequest['url']['query'][0]['disabled'] = False
     request = RequestParser.parse(samplerequest)
     self.assertEqual({'foo1': 'bar1', 'foo2': 'bar2'}, request.query_string)
     self.assertEqual({'foo1': 'bar1', 'foo2': 'bar2'}, request.get_query_string())