示例#1
0
    def setUp(self):
        current_dir = os.path.abspath(os.path.dirname(__file__))
        self.fixture_dir = os.path.join(current_dir, 'fixtures')
        self.test_url = 'http://127.0.0.1:8080/'
        entry_point = 'http://127.0.0.1:8080/?json_response={}'

        # For various navigation tests
        self.nav_values = {'next': "http://127.0.0.1:8080/docs?tag=npr_api&profile=someGUIDvalue&offset=10",
                           'prev': "http://127.0.0.1:8080/docs?",
                           'first': "http://127.0.0.1:8080/docs?tag=npr_api&profile=someGUIDvalue",
                           'last': "http://127.0.0.1:8080/docs?tag=npr_api&profile=someGUIDvalue&offset=13130",
                           'current': "http://127.0.0.1:8080/docs?tag=npr_api&profile=someGUIDvalue"}

        # Fixture locations
        self.home_doc = os.path.join(self.fixture_dir, 'homedoc.json')
        self.auth_doc = os.path.join(self.fixture_dir, 'authdetails.json')
        self.data_doc = os.path.join(self.fixture_dir, 'datadoc.json')

        # Can also return JSON via these urls and testing server
        self.server_process = Process(target=run_forever)
        self.server_process.start()
        self.test_entry_point = entry_point.format(self.home_doc)
        self.auth_url = entry_point.format(self.auth_doc)
        self.data_url = entry_point.format(self.data_doc)

        with open(self.home_doc, 'r') as jfile:
            home = PelicanJson(json.loads(jfile.read()))
        home.set_nested_value(['links', 'auth', 3, 'href'],
                              self.auth_url)
        self.home_values = home.convert()
示例#2
0
def edit_profile(profile, new_data):
    """EXPERIMENTAL function for cramming data into a profile.
    """
    pelican_profile = PelicanJson(profile)
    pelican_data = PelicanJson(new_data)
    for path, value in pelican_data.enumerate():
        pelican_profile.set_nested_value(path, value, force=True)
    return pelican_profile.convert()
示例#3
0
def strip_guids(json_result):
    guidpat = re.compile(r'\w{8}-\w{4}-\w{4}-\w{4}-\w{12}')
    pelican = PelicanJson(json_result)
    for path, value in pelican.enumerate():
        if type(value) == str and guidpat.search(value):
            pelican.set_nested_value(path,
                                     re.sub(guidpat, 'someGUIDvalue',
                                            value))

    return pelican.convert()
示例#4
0
def clean_urls(json_result):
    urlpat = re.compile(r'https://[api|publish]-sandbox.pmp.io')
    pelican = PelicanJson(json_result)
    for path, value in pelican.enumerate():
        if type(value) == str and urlpat.search(value):
            pelican.set_nested_value(path,
                                     re.sub(urlpat, 'http://127.0.0.1:8080',
                                            value))

    return pelican.convert()
 def test_convert(self):
     test_pelican = PelicanJson(self.data)
     self.assertEqual(test_pelican.convert(), self.data)
     self.assertTrue(isinstance(test_pelican.convert(),
                                dict))