Esempio n. 1
0
    def check_reload(self) -> None:
        # Because importing yamole (and in turn, yaml) takes
        # significant time, and we only use python-yaml for our API
        # docs, importing it lazily here is a significant optimization
        # to `manage.py` startup.
        #
        # There is a bit of a race here...we may have two processes
        # accessing this module level object and both trying to
        # populate self.data at the same time.  Hopefully this will
        # only cause some extra processing at startup and not data
        # corruption.
        from yamole import YamoleParser

        mtime = os.path.getmtime(self.openapi_path)
        # Using == rather than >= to cover the corner case of users placing an
        # earlier version than the current one
        if self.mtime == mtime:
            return

        with open(self.openapi_path) as f:
            yamole_parser = YamoleParser(f)
        self._openapi = yamole_parser.data
        spec = create_spec(self._openapi)
        self._request_validator = RequestValidator(spec)
        self.create_endpoints_dict()
        self.mtime = mtime
Esempio n. 2
0
 def reload(self) -> None:
     # Because importing yamole (and in turn, yaml) takes
     # significant time, and we only use python-yaml for our API
     # docs, importing it lazily here is a significant optimization
     # to `manage.py` startup.
     #
     # There is a bit of a race here...we may have two processes
     # accessing this module level object and both trying to
     # populate self.data at the same time.  Hopefully this will
     # only cause some extra processing at startup and not data
     # corruption.
     from yamole import YamoleParser
     with open(self.path) as f:
         yaml_parser = YamoleParser(f)
     self.data = yaml_parser.data
     validator_spec = create_spec(self.data)
     self.core_data = RequestValidator(validator_spec)
     self.create_regex_dict()
     self.last_update = os.path.getmtime(self.path)
     # Form a set of all documented events
     self.documented_events.clear()
     schema = (self.data['paths']['/events']['get']['responses']
               ['200']['content']['application/json']['schema'])
     for events in schema['properties']['events']['items']['oneOf']:
         op_str = ':'
         if 'op' in events['properties']:
             op_str = f':{events["properties"]["op"]["enum"][0]}'
         self.documented_events.add(events['properties']['type']['enum'][0]
                                    + op_str)
Esempio n. 3
0
 def reload(self) -> None:
     # Because importing yamole (and in turn, yaml) takes
     # significant time, and we only use python-yaml for our API
     # docs, importing it lazily here is a significant optimization
     # to `manage.py` startup.
     from yamole import YamoleParser
     self.last_update = os.path.getmtime(self.path)
     with open(self.path) as f:
         yaml_parser = YamoleParser(f)
     self.data = yaml_parser.data
Esempio n. 4
0
    def reload(self) -> None:
        # Because importing yamole (and in turn, yaml) takes
        # significant time, and we only use python-yaml for our API
        # docs, importing it lazily here is a significant optimization
        # to `manage.py` startup.
        #
        # There is a bit of a race here...we may have two processes
        # accessing this module level object and both trying to
        # populate self.data at the same time.  Hopefully this will
        # only cause some extra processing at startup and not data
        # corruption.
        from yamole import YamoleParser
        with open(self.path) as f:
            yaml_parser = YamoleParser(f)

        self.data = yaml_parser.data
        self.last_update = os.path.getmtime(self.path)
Esempio n. 5
0
import os
import sys

import yaml

# Read yamole from the current source
TEST_DIR = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.normpath(os.path.dirname(TEST_DIR)))

from yamole import YamoleParser

with open(os.path.join(TEST_DIR, 'source.yaml')) as file:
    parser = YamoleParser(file)
    actual = parser.data

with open(os.path.join(TEST_DIR, 'expected.yaml')) as file:
    expected = yaml.safe_load(file)

assert (actual == expected)

# We can't test the .dumps() method as there's no guarantee the keys in the
# output will always be sorted the same way.