示例#1
0
 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)
示例#2
0
 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)
示例#3
0
 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')
示例#4
0
 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')
示例#5
0
 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