def test_good_effective_date_request(self, mock_get):
     mock_response = mock.Mock(Response, ok=True)
     mock_response.json.return_value = json.loads(
         '{"results": [{"effective_on": "2018-01-01"}]}')
     mock_get.return_value = mock_response
     PAYLOAD.get_effective_date('1002')
     self.assertEqual(PAYLOAD.effective_date, datetime.date(2018, 1, 1))
Esempio n. 2
0
 def test_bad_effective_date_request_returns_none(self, mock_get):
     mock_response = mock.Mock(
         Response,
         ok=False)
     mock_get.return_value = mock_response
     PAYLOAD.get_effective_date('1002')
     self.assertIs(PAYLOAD.effective_date, None)
 def test_set_table(self):
     PAYLOAD.reset()
     p_soup = bS(self.test_xml, 'lxml-xml')
     appendix = p_soup.find('DIV5').find('DIV9')
     table = appendix.find('TABLE')
     table_id = 'table-A-0'
     ecfr_importer.set_table(table, table_id)
     self.assertIn(table_id, PAYLOAD.tables.keys())
     self.assertTrue(isinstance(PAYLOAD.tables[table_id], RegTable))
Esempio n. 4
0
 def test_set_table(self):
     PAYLOAD.reset()
     p_soup = bS(self.test_xml, 'lxml-xml')
     appendix = p_soup.find('DIV5').find('DIV9')
     table = appendix.find('TABLE')
     table_id = 'table-A-0'
     ecfr_importer.set_table(table, table_id)
     self.assertIn(table_id, PAYLOAD.tables.keys())
     self.assertTrue(isinstance(PAYLOAD.tables[table_id], RegTable))
 def test_parse_appendices_creation(self):
     PAYLOAD.reset()
     self.assertEqual(len(PAYLOAD.appendices), 0)
     test_part = Part.objects.first()
     test_subpart = Subpart.objects.first()
     PAYLOAD.subparts['appendix_subpart'] = test_subpart
     PAYLOAD.interp_refs.update({'A': {'1': 'see(A-1-Interp)'}})
     soup = bS(self.test_xml, 'lxml-xml')
     test_appendices = [soup.find('DIV5').find('DIV9')]
     ecfr_importer.parse_appendices(test_appendices, test_part)
     self.assertEqual(len(PAYLOAD.appendices), 1)
Esempio n. 6
0
 def test_parse_appendices_creation(self):
     PAYLOAD.reset()
     self.assertEqual(len(PAYLOAD.appendices), 0)
     test_part = Part.objects.first()
     test_subpart = Subpart.objects.first()
     PAYLOAD.subparts['appendix_subpart'] = test_subpart
     PAYLOAD.interp_refs.update({'A': {'1': 'see(A-1-Interp)'}})
     soup = bS(self.test_xml, 'lxml-xml')
     test_appendices = [soup.find('DIV5').find('DIV9')]
     ecfr_importer.parse_appendices(test_appendices, test_part)
     self.assertEqual(len(PAYLOAD.appendices), 1)
Esempio n. 7
0
 def test_good_effective_date_request(self, mock_get):
     mock_response = mock.Mock(
         Response,
         ok=True)
     mock_response.json.return_value = json.loads(
         '{"results": [{"effective_on": "2018-01-01"}]}')
     mock_get.return_value = mock_response
     PAYLOAD.get_effective_date('1002')
     self.assertEqual(
         PAYLOAD.effective_date,
         datetime.date(2018, 1, 1))
 def test_interp_inferred_section_graph_parsing(self):
     from regulations3k.scripts.ecfr_importer import PAYLOAD
     PAYLOAD.reset()
     self.assertEqual(PAYLOAD.interp_refs, {})
     soup = bS(self.interp_xml, 'lxml-xml')
     parts = soup.find_all('DIV5')
     part_soup = [div for div in parts if div['N'] == '1030'][0]
     part = parse_part(part_soup, '1030')
     version = parse_version(part_soup, part)
     interp_subpart = Subpart(
         title="Supplement I to Part {}".format(part.part_number),
         label="Official Interpretations",
         version=version)
     interp_subpart.save()
     interp = [div for div
               in part_soup.find_all('DIV9')
               if div.find('HEAD').text.startswith('Supplement I')][0]
     parse_interps(interp, part, interp_subpart)
     self.assertEqual(PAYLOAD.interp_refs['1']['c'], 'see(1-c-Interp)')
Esempio n. 9
0
 def test_interp_graph_parsing(self):
     soup = bS(self.interp_xml, 'lxml-xml')
     part_soup = soup.find('DIV5')
     PAYLOAD.parse_part(part_soup, '1002')
     part = PAYLOAD.part
     PAYLOAD.parse_version(part_soup, part)
     version = PAYLOAD.version
     interp_subpart = Subpart(
         title="Supplement I to Part {}".format(part.part_number),
         label="Official Interpretations",
         version=version)
     interp_subpart.save()
     interp = [div for div
               in part_soup.find_all('DIV9')
               if div.find('HEAD').text.startswith('Supplement I')][0]
     ecfr_importer.parse_interps(interp, part, interp_subpart)
     self.assertEqual(
         Subpart.objects.filter(title__contains='Supplement I').count(),
         1,
     )
Esempio n. 10
0
 def test_interp_inferred_section_graph_parsing(self):
     PAYLOAD.reset()
     self.assertEqual(PAYLOAD.interp_refs, {})
     soup = bS(self.interp_xml, 'lxml-xml')
     parts = soup.find_all('DIV5')
     part_soup = [div for div in parts if div['N'] == '1030'][0]
     PAYLOAD.parse_part(part_soup, '1030')
     part = PAYLOAD.part
     PAYLOAD.parse_version(part_soup, part)
     version = PAYLOAD.version
     interp_subpart = Subpart(
         title="Supplement I to Part {}".format(part.part_number),
         label="Official Interpretations",
         version=version)
     interp_subpart.save()
     interp = [div for div
               in part_soup.find_all('DIV9')
               if div.find('HEAD').text.startswith('Supplement I')][0]
     ecfr_importer.parse_interps(interp, part, interp_subpart)
     self.assertEqual(PAYLOAD.interp_refs['1']['c'], 'see(1-c-Interp)')