Пример #1
0
    def setUp(self, get):
        self.data = {
            "title":
            "app schema",
            "properties": {
                "cname": {
                    "type": "string"
                },
                "ip": {
                    "type": "string"
                },
                "name": {
                    "type": "string"
                },
                "platform": {
                    "type": "string"
                }
            },
            "links": [{
                "href": "/apps/{name}/log",
                "method": "GET",
                "rel": "log"
            }, {
                "href": "/apps/{name}/env",
                "method": "GET",
                "rel": "get envs"
            }],
            "required": ["platform", "name"],
        }
        mock = Mock()
        get.return_value = mock
        mock.json.return_value = self.data

        self.url = "http://app.com/myschema"
        self.result = schema.get(url=self.url)
Пример #2
0
    def setUp(self, get):
        self.data = {
            "title": "app schema",
            "properties": {
                "cname": {"type": "string"},
                "ip": {"type": "string"},
                "name": {"type": "string"},
                "platform": {"type": "string"}
            },
            "links": [
                {
                    "href": "/apps/{name}/log",
                    "method": "GET",
                    "rel": "log"
                },
                {
                    "href": "/apps/{name}/env",
                    "method": "GET",
                    "rel": "get envs"
                }
            ],
            "required": ["platform", "name"],
        }
        mock = Mock()
        get.return_value = mock
        mock.json.return_value = self.data

        self.url = "http://app.com/myschema"
        self.result = schema.get(url=self.url)
Пример #3
0
 def parse_data(self):
     if isinstance(self.data, dict):
         for key, value in self.data.items():
             if isinstance(value, list):
                 data_items = []
                 for item in value:
                     try:
                         prop_items = self.schema.properties[key]['items']
                     except KeyError:
                         break
                     if "$ref" in prop_items:
                         s = schema.get(prop_items['$ref'], self.auth)
                     else:
                         s = Schema(self.url, **prop_items)
                     data_items.append(
                         Resource(
                             self.url,
                             data=item,
                             schema=s,
                         ))
                 self.data[key] = data_items
Пример #4
0
 def parse_data(self):
     if isinstance(self.data, dict):
         for key, value in self.data.items():
             if isinstance(value, list):
                 data_items = []
                 for item in value:
                     try:
                         prop_items = self.schema.properties[key]['items']
                     except KeyError:
                         break
                     if "$ref" in prop_items:
                         s = schema.get(prop_items['$ref'], self.auth)
                     else:
                         s = Schema(self.url, **prop_items)
                     data_items.append(
                         Resource(
                             self.url,
                             data=item,
                             schema=s,
                         )
                     )
                 self.data[key] = data_items
Пример #5
0
    def parse_data(self):
        if not isinstance(self.data, dict):
            return

        for key, value in self.data.items():
            if not isinstance(value, list):
                continue

            item_schema = self.schema.properties.get(key, {})
            is_array = item_schema.get('type') == 'array'

            if not is_array:
                continue

            data_items = []
            prop_items = item_schema.get('items', {})

            if "$ref" in prop_items:
                s = schema.get(prop_items['$ref'], self.auth)
            else:
                s = Schema(self.url, prop_items)

            for item in value:
                if not isinstance(item, dict):
                    data_items.append(item)
                    continue

                data_items.append(
                    Resource(
                        self.url,
                        data=item,
                        schema=s,
                    )
                )

            self.data[key] = data_items