def assert_betty_json(self, path: str, schema_definition: str) -> str: file_path = join( self.site.configuration.www_directory_path, path.lstrip('/')) self.assertTrue(exists(file_path), '%s does not exist' % file_path) with open(file_path) as f: json.validate(stdjson.load(f), schema_definition, self.site) return file_path
def assert_betty_json(self, app: App, url_path: str, schema_definition: str) -> Path: file_path = app.configuration.www_directory_path / Path( url_path.lstrip('/')) self.assertTrue(file_path.exists(), '%s does not exist' % file_path) with open(file_path) as f: json.validate(stdjson.load(f), schema_definition, app) return file_path
def assert_encodes(self, expected, data, schema_definition: str): with TemporaryDirectory() as output_directory: configuration = Configuration(output_directory, '') encoded_data = stdjson.loads( stdjson.dumps(data, cls=JSONEncoder.get_factory( configuration, configuration.default_locale))) json.validate(encoded_data, schema_definition, configuration) self.assertEquals(expected, encoded_data)
def assert_encodes(self, expected, data, schema_definition: str): with TemporaryDirectory() as output_directory: configuration = Configuration( output_directory, '') configuration.locales.clear() configuration.locales['en-US'] = LocaleConfiguration('en-US', 'en') configuration.locales['nl-NL'] = LocaleConfiguration('nl-NL', 'nl') site = Site(configuration) encoded_data = stdjson.loads(stdjson.dumps(data, cls=JSONEncoder.get_factory( site, configuration.default_locale))) json.validate(encoded_data, schema_definition, site) self.assertEquals(expected, encoded_data)
async def assert_encodes(self, expected, data, schema_definition: str): with TemporaryDirectory() as output_directory: configuration = Configuration(output_directory, 'https://example.com') configuration.locales.replace([ LocaleConfiguration('en-US', 'en'), LocaleConfiguration('nl-NL', 'nl'), ]) async with App(configuration) as app: encoded_data = stdjson.loads( stdjson.dumps(data, cls=JSONEncoder.get_factory( app, configuration.locales.default.locale))) json.validate(encoded_data, schema_definition, app) self.assertEquals(expected, encoded_data)