Esempio n. 1
0
 def test_example_article_sy_xml(self):
     filename = 'example-article.md'
     file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                              filename)
     with open(file_path, 'rb') as ea_fp:
         data = {filename: ea_fp}
         with app.test_client() as test_client:
             response = test_client.post('/convert/markdown/sy_xml',
                                         data=data,
                                         content_type="multipart/form-data")
             self.assertEqual(200, response.status_code)
             loaded_xml = str(response.data, encoding='utf-8')
     print(loaded_xml)
     self.assertEqual(
         "<document dbref=\"1234567890123456789\">\n" +
         "<title>Untertitel</title>\n<subtitle>Titel</subtitle>\n<abstract>Vorlauftext</abstract>\n"
         + "<textel>\n" +
         "<paragraph type=\"standard\" id=\"e0\">Text des Artikels.</paragraph>\n"
         +
         "<paragraph type=\"standard\" id=\"e1\">Dies ist ein zweiter Absatz.</paragraph>\n"
         +
         "<shorturlwrapper><label>Dokumentation: </label><shorturl></shorturl></shorturlwrapper>\n"
         + "<bibliography><title>Literatur</title>" +
         "<internal brand=\"ct\" year=\"19\" month=\"17\" page=\"127\">" +
         "Pina Merkert, Djangolino, Webentwicklung mit Django und wenig Code, c't 17/19, S. 127</internal>"
         +
         "<external href=\"https://ct.de\">https://ct.de</external></bibliography>\n"
         + "</textel>\n</document>", loaded_xml)
Esempio n. 2
0
 def md_as_md_article_round_trip(self, md_text):
     article_markdown = "<!---\ntype: article-standard\n" + \
                        "x_id: 1234567890123456789\n" + \
                        "catchphrase: Testartikel\n" + \
                        "column: Wissen\n" + \
                        "working_title: Standard-Testartikel\n" + \
                        "title: MD_BLOCK\n-->\n\n# Titel\n\n<!---\n" + \
                        "subtitle: MD_BLOCK\n-->\n\n## Untertitel\n\n<!---\n" + \
                        "teaser: MD_BLOCK\n-->\n\n**Vorlauftext**\n\n<!---\n" + \
                        "author: MD_BLOCK\n-->\n\nPina Merkert\n\n<!---\n" + \
                        "content: MD_BLOCK\n-->\n\n" + md_text + "\n\n<!---\n" + \
                        "article_link:\n" + \
                        "  type: article-link-container\n" + \
                        "  link_description: Dokumentation\n" + \
                        "  link: <ctlink />\n" + \
                        "bibliography:\n-->"
     data = {
         'article.md':
         (io.BytesIO(article_markdown.encode('utf-8')), "article.md")
     }
     with app.test_client() as test_client:
         response = test_client.post('/convert/markdown/markdown',
                                     data=data,
                                     content_type="multipart/form-data")
         if response.status_code != 200:
             print(response.data)
             print("Input:")
             print(md_text)
             print("---------------")
             print(response.data)
             print("===============")
         self.assertEqual(200, response.status_code)
         self.assertEqual(article_markdown,
                          str(response.data, encoding='utf-8'))
Esempio n. 3
0
 def test_server_by_env(self):
     with app.test_client() as test_client:
         response = test_client.get('/openapi.json')
         self.assertEqual(200, response.status_code)
         self.assertEqual("application/json", response.mimetype)
         api_def = response.get_json()
     self.assertEqual({'url': 'https://test.org/foo/bar/baz'},
                      api_def['servers'][0])
Esempio n. 4
0
 def request_with_error(self, data: dict) -> Response:
     with app.test_client() as test_client:
         response = test_client.post('/convert/markdown/proof_html',
                                     data=data,
                                     content_type="multipart/form-data")
     self.assertEqual(400, response.status_code)
     self.assertEqual("application/json", response.mimetype)
     return response
Esempio n. 5
0
 def test_converter_unreachable(self):
     with app.test_client() as test_client:
         response = test_client.get('/live')
         self.assertEqual(400, response.status_code)
         self.assertEqual(
             {
                 'Error':
                 'The url https://wrong.url/not/existing/live is unreachable.'
             }, response.get_json())
Esempio n. 6
0
 def test_standard_article_with_email_link(self):
     article_markdown = magic_yaml_block({
         "type":
         "article-standard",
         "x_id":
         "1234567890123456789",
         "catchphrase":
         "Testartikel",
         "column":
         "Wissen",
         "working_title":
         "Standard-Testartikel",
         "title":
         MdBlock("# Titel"),
         "subtitle":
         MdBlock("## Untertitel"),
         "teaser":
         MdBlock("**Vorlauftext**"),
         "author":
         MdBlock("Pina Merkert"),
         "content":
         MdBlock(
             "Text des Artikels.\n\nAbsatz mit Mailto: [[email protected]](mailto:[email protected])\n\nAbsatz 3."
         ),
         "article_link": {
             "type": "article-link-container",
             "link_description": "Dokumentation",
             "link": {
                 "type": "span-ct-link"
             }
         },
         "bibliography": []
     })
     data = {
         'article.md':
         (io.BytesIO(article_markdown.encode('utf-8')), "article.md")
     }
     with app.test_client() as test_client:
         response = test_client.post('/convert/markdown/proof_html',
                                     data=data,
                                     content_type="multipart/form-data")
         self.assertEqual(200, response.status_code)
         self.assertEqual(
             "<article-standard>" + "<x_id>1234567890123456789</x_id>" +
             "<catchphrase>Testartikel</catchphrase>" +
             "<magazine-column>Wissen</magazine-column>" +
             "<h1>Titel</h1>" + "<h2 class=\"subtitle\">Untertitel</h2>" +
             "<teaser>Vorlauftext</teaser>" +
             "<author>Von Pina Merkert</author>" +
             "<p>Text des Artikels.</p><p>Absatz mit Mailto: " +
             "<a href=\"mailto:[email protected]\">[email protected]</a></p>" +
             "<p>Absatz 3.</p>" + "<article-link>" +
             "<article-link-description>Dokumentation:</article-link-description> <ctlink />"
             + "</article-link>" +
             "<div class=\"bibliography\"><h3>Literatur</h3><ol></ol></div>"
             + "</article-standard>", str(response.data, encoding='utf-8'))
Esempio n. 7
0
 def test_default_first_server(self):
     with app.test_client() as test_client:
         response = test_client.get('/openapi.json')
         self.assertEqual(200, response.status_code)
         self.assertEqual("application/json", response.mimetype)
         api_def = response.get_json()
     self.assertEqual('3.0.0', api_def['openapi'])
     self.assertEqual('AssetStorm-Dispatcher', api_def['info']['title'])
     self.assertEqual({'url': 'http://dispatcher.assetstorm.pinae.net'},
                      api_def['servers'][0])
Esempio n. 8
0
 def test_example_article_markdown(self):
     filename = 'example-article.md'
     file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                              filename)
     with open(file_path, 'rb') as ea_fp:
         data = {filename: ea_fp}
         with app.test_client() as test_client:
             response = test_client.post('/convert/markdown/markdown',
                                         data=data,
                                         content_type="multipart/form-data")
             self.assertEqual(200, response.status_code)
             loaded_markdown = str(response.data, encoding='utf-8')
     with open(file_path, 'rb') as ea_fp:
         self.assertEqual(str(ea_fp.read(), encoding='utf-8'),
                          loaded_markdown)
Esempio n. 9
0
 def two_file_conversion(self, source_path, target_example_path,
                         source_format, target_format):
     with open(source_path, 'rb') as source_file:
         data = {os.path.split(source_path)[-1]: source_file}
         with app.test_client() as test_client:
             response = test_client.post("/convert/{}/{}".format(
                 source_format, target_format),
                                         data=data,
                                         content_type="multipart/form-data")
             if response.status_code != 200:
                 print(str(response.data, encoding='utf-8'))
             self.assertEqual(200, response.status_code)
             converted = str(response.data, encoding='utf-8')
     print(converted)
     with open(target_example_path, 'rb') as target_example_file:
         self.assertEqual(converted, target_example_file.read())
Esempio n. 10
0
 def as_through_md_round_trip(self, article: dict):
     with app.test_client() as test_client:
         response = test_client.post(
             '/convert/assetstorm/markdown',
             data=json.dumps(article, ensure_ascii=False).encode('utf-8'),
             content_type="application/json")
         if response.status_code != 200:
             print(response.data)
             print("Input:")
             print(json.dumps(article, indent=2))
             print("---------------")
             print(response.data)
             print("===============")
         self.assertEqual(200, response.status_code)
         md_converter_response = requests.post(Settings().md_conv_url + "/",
                                               data=response.data)
         md_converter_response.encoding = 'utf-8'
         converted_tree = md_converter_response.json()
         as_tree = collapse_tree(converted_tree['blocks'][0])
         self.assertEqual(article, as_tree)
Esempio n. 11
0
 def test_standard_live(self):
     with app.test_client() as test_client:
         response = test_client.get('/live')
         self.assertEqual(200, response.status_code)