def test_export_db_as_json(self): data = json.loads(export.db_as_json()) self.assertEqual(50, data['huts']['meta']['total_count']) self.assertEqual(355, data['agencies']['meta']['total_count']) self.assertEqual(120, data['regions']['meta']['total_count']) self.assertEqual(u'First Creek Cabin', data['huts']['object_index']['1']['name'])
def handle(self, *args, **options): huts_json = export.db_as_json().encode('utf-8') if options['update']: path = os.path.join(settings.STATIC_ROOT, 'hutmap', 'data') try: os.makedirs(path) except OSError: pass json_file = os.path.join(path, 'huts.json') tmp_file = os.path.join(path, 'huts.new.json') out = open(tmp_file, 'w') out.write(huts_json) os.rename(tmp_file, json_file) else: self.stdout.write(huts_json)
def handle(self, *args, **options): print(export.db_as_json().encode("utf-8"))