def test_reference_rewrites(self): # Case to test that a document's internal references have # been rewritten to the cnx-archive's read-only API routes. ident = 3 from ..to_html import ( fix_reference_urls, transform_cnxml_to_html) with psycopg2.connect(self.connection_string) as db_connection: content_filepath = os.path.join(TESTING_DATA_DIR, 'm42119-1.3-modified.cnxml') with open(content_filepath, 'r') as fb: content = transform_cnxml_to_html(fb.read()) content = BytesIO(content) content, bad_refs = fix_reference_urls(db_connection, ident, content) # Read the content for the reference changes. expected_img_ref = '<img src="/resources/38b5477eb68417a65d7fcb1bc1d6630e" data-media-type="image/jpg" alt="The spiral galaxy Andromeda is shown."/>' self.assertTrue(content.find(expected_img_ref) >= 0) expected_internal_ref = '<a href="/contents/209deb1f-1a46-4369-9e0d-18674cf58a3e@7">' self.assertTrue(content.find(expected_internal_ref) >= 0) expected_resource_ref = '<a href="/resources/38b5477eb68417a65d7fcb1bc1d6630e">' self.assertTrue(content.find(expected_resource_ref) >= 0)