def handle(self, *args, **options): output_type = options['type'] output_type_map = { 'article-version-history': logic.bulk_article_version_history } for row in output_type_map[output_type](): print utils.json_dumps(row)
def test_article_versions_list_placeholder(self): "invalid article-json causes a placeholder to be served instead" invalid_ajson = json.load( open(join(self.fixture_dir, 'ajson', 'elife-20125-v4.xml.json'), 'r')) invalid_ajson['article']['title'] = '' av = ajson_ingestor.ingest_publish(invalid_ajson, force=True) self.freshen(av) # we now have a published article in lax with invalid article-json resp = self.c.get( reverse('v2:article-version-list', kwargs={'id': self.msid1})) data = utils.json_loads(resp.content) # the invalid-but-published culprit v4 = data['versions'][-1] expected_struct = utils.json_loads( utils.json_dumps({ '-invalid': True, 'id': av.article.manuscript_id, 'status': av.status, 'published': av.article.datetime_published, 'version': 4, 'versionDate': av.datetime_published })) self.assertEqual(expected_struct, v4)
def handle(self, *args, **options): try: msid_list = options['msid-list'] results = dict(zip(msid_list, map(self.report, options['msid-list']))) self.stdout.write(json_dumps(results, indent=4)) self.stdout.flush() exit(0) except Exception as err: LOG.exception("unhandled exception generating article report: %s", err) exit(1)
def test_article_versions_list_placeholder(self): invalid_ajson = json.load(open(join(self.fixture_dir, 'ajson', 'elife-20125-v4.xml.json'), 'r')) invalid_ajson['article']['title'] = '' _, _, av = ajson_ingestor.ingest_publish(invalid_ajson, force=True) self.freshen(av) # we now have a published article in lax with invalid article-json resp = self.c.get(reverse('v2:article-version-list', kwargs={'id': self.msid1})) data = json.loads(resp.content) # the invalid-but-published culprit v4 = data['versions'][-1] expected_struct = json.loads(utils.json_dumps({ '-invalid': True, 'status': av.status, 'published': av.article.datetime_published, 'version': 4, 'versionDate': av.datetime_published })) self.assertEqual(expected_struct, v4)
def write(print_queue, out=None): if not isinstance(out, basestring): out = utils.json_dumps(out) # encodes datetime objects print_queue.put(out)
def test_json_dumps_rfc3339_on_non_utc(self): tz = pytz.timezone('Australia/Adelaide') # +9.5 hours ahead, but pytz thinks it's only +9 dt = datetime(year=2001, month=1, day=1, hour=9, minute=59, second=59, microsecond=123, tzinfo=tz) struct = {'dt': dt} expected = '{"dt": "2001-01-01T00:59:59Z"}' self.assertEqual(utils.json_dumps(struct), expected)
def test_json_dumps_rfc3339(self): dt = datetime(year=2001, month=1, day=1, hour=23, minute=59, second=59, microsecond=123, tzinfo=pytz.utc) struct = {'dt': dt} expected = '{"dt": "2001-01-01T23:59:59Z"}' self.assertEqual(utils.json_dumps(struct), expected)
def write(print_queue, out=None): if not isinstance(out, str): out = utils.json_dumps(out) # encodes datetime objects print_queue.put(out)
def write(self, out=None): if not isinstance(out, basestring): out = utils.json_dumps(out) # encodes datetime objects self.stdout.write(out) self.stdout.flush()