Пример #1
0
 def test_schema_with_property_type_array(self, get, from_response):
     s = schema.Schema(
         title="title",
         type="object",
         url="url.com",
         properties={
             u'items': {
                 u'type': u'array',
                 u'items': {
                     'title':
                     'Foo',
                     'type':
                     'object',
                     'properties': {
                         'id': {
                             'type': 'integer'
                         }
                     },
                     'links': [{
                         "href": "http://localhost/foos/{id}/",
                         "method": "GET",
                         "rel": "item",
                     }]
                 }
             },
         },
     )
     data = {'items': [{'id': 1}, {'id': 2}]}
     app = resource.Resource(url="appurl.com", data=data, schema=s)
     app.data['items'][0].item()
     url = 'http://localhost/foos/1/'
     get.assert_called_with(url=url,
                            headers={'content-type': 'application/json'},
                            timeout=30)
Пример #2
0
    def test_extra_parameters_uri(self, get, resource_from_response):
        data = {
            u'name': u'repos',
            u'platform': u'repos',
        }
        self.schema.links[0]['href'] = '/apps/{name}/log/{lines}'
        app = resource.Resource(url="appurl.com",
                                data=data,
                                schema=self.schema)

        app.log(lines=10, source="app")
        url = '/apps/repos/log/10?source=app'
        get.assert_called_with(url=url,
                               headers={'content-type': 'application/json'},
                               timeout=30)
Пример #3
0
 def test_resource_with_an_array_without_schema(self):
     data = {
         u'units': [{
             u'name': u'someunit'
         }],
         u'name': u'registry',
     }
     s = schema.Schema(url='url',
                       title='app schema',
                       type='object',
                       required=['name'],
                       properties={'name': {
                           'type': 'string'
                       }})
     response = resource.Resource("url", data, s)
     self.assertDictEqual(data, response.data)
Пример #4
0
    def test_extra_parameters_uri_name_bug(self, get, resource_from_response):
        # regression for #12.
        data = {'platform': 'xpto'}
        link = {
            "href": "http://example.org/{context_name}",
            "method": "GET",
            "rel": "example"
        }
        self.schema.links.append(link)
        app = resource.Resource(url="appurl.com",
                                data=data,
                                schema=self.schema)

        app.example(context_name='context', name='value1')
        url = 'http://example.org/context?name=value1'
        get.assert_called_with(url=url,
                               headers={'content-type': 'application/json'},
                               timeout=30)
Пример #5
0
    def test_extra_parameters_querystring(self, get, resource_from_response):
        data = {
            u'name': u'repos',
            u'platform': u'repos',
        }
        app = resource.Resource(url="appurl.com",
                                data=data,
                                schema=self.schema)

        app.log(lines=10)
        url = '/apps/repos/log?lines=10'
        get.assert_called_with(url=url,
                               headers={'content-type': 'application/json'},
                               timeout=30)

        app.log(lines=10, source="app")
        qs = parse_qs(urlparse(get.call_args[1]['url']).query)
        expected = {'source': ['app'], 'lines': ['10']}
        self.assertEqual(qs, expected)