def test_output(self): parser = hstprop.HSTParser() mock_infile = os.path.join(os.path.dirname(__file__), "data/stubdata/input/hstprop.json") mock_data = json.loads(open(mock_infile).read()) self.get_batch_mock.return_value = mock_data api_url = 'https://proper.stsci.edu/proper/adsProposalSearch/query_test' token = 'foo' test_data = parser.parse(api_url, api_key=token, fromDate='2019-01-01', maxRecords=1, test=True) test_outfile = "test_hst.tag" standard_outfile = os.path.join( os.path.dirname(__file__), "data/stubdata/serialized/hstprop.tag") try: os.remove(test_outfile) except Exception as err: pass for d in test_data: serializer = classic.Tagged() outputfp = open(test_outfile, 'a') serializer.write(d, outputfp) outputfp.close() result = filecmp.cmp(test_outfile, standard_outfile) self.assertEqual(result, True) os.remove(test_outfile)
def test_missing_token(self): parser = hstprop.HSTParser() mock_infile = os.path.join(os.path.dirname(__file__), "data/stubdata/input/hstprop.json") mock_data = json.loads(open(mock_infile).read()) # self.get_batch_mock.return_value = MockResponse(mock_data) self.get_batch_mock.return_value = mock_data api_url = 'https://proper.stsci.edu/proper/adsProposalSearch/query' with self.assertRaises(hstprop.RequestError): test_data = parser.parse(api_url, fromDate='2019-01-01', maxRecords=1, test=True)
def test_misaligned_arrays(self): parser = hstprop.HSTParser() mock_infile = os.path.join(os.path.dirname(__file__), "data/stubdata/input/hstprop_misaligned_arrays.json") mock_data = json.loads(open(mock_infile).read()) self.get_batch_mock.return_value = mock_data api_url = 'https://proper.stsci.edu/proper/adsProposalSearch/query' token = 'foo' test_data = parser.parse(api_url, api_key=token, fromDate='2019-01-01', maxRecords=1, test=True) # Misaligned arrays should be reported self.assertEqual(parser.errors[0], 'Found misaligned affiliation/ORCID arrays: 2019hst..prop15677M')
def test_missing_field(self): parser = hstprop.HSTParser() mock_infile = os.path.join(os.path.dirname(__file__), "data/stubdata/input/hstprop_missing_field.json") mock_data = json.loads(open(mock_infile).read()) # self.get_batch_mock.return_value = MockResponse(mock_data) self.get_batch_mock.return_value = mock_data api_url = 'https://proper.stsci.edu/proper/adsProposalSearch/query' token = 'foo' test_data = parser.parse(api_url, api_key=token, fromDate='2019-01-01', maxRecords=1, test=True) # A missing data error should be reported self.assertEqual(parser.errors[0], 'Found record with missing data: HST Proposal#15677')
def test_output(self): parser = hstprop.HSTParser() mock_infile = os.path.join(os.path.dirname(__file__), "data/stubdata/input/hstprop.json") mock_data = json.loads(open(mock_infile).read()) # self.get_batch_mock.return_value = MockResponse(mock_data) self.get_batch_mock.return_value = mock_data api_url = 'https://proper.stsci.edu/proper/adsProposalSearch/query' token = 'foo' test_data = parser.parse(api_url, api_key=token, fromDate='2019-01-01', maxRecords=1, test=True) test_outfile = "test_hst.tag" standard_outfile = os.path.join(os.path.dirname(__file__), "data/stubdata/serialized/hstprop.tag") try: os.remove(test_outfile) except Exception, err: pass