aboutsummaryrefslogtreecommitdiff
path: root/gn2/tests/unit/wqflask/api/test_markdown_routes.py
blob: ecf64a81ff7a0f914c7e36285ef86702d87021fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Test functions for wqflask/api/markdown.py"""

import unittest
from unittest import mock

from dataclasses import dataclass
from gn2.wqflask.api.markdown import render_markdown


@dataclass
class MockRequests404:
    status_code: int = 404


@dataclass
class MockRequests200:
    status_code: int = 200
    content: str = b"""
# Glossary
This is some content

## Sub-heading
This is another sub-heading"""


class TestMarkdownRoutesFunctions(unittest.TestCase):
    """Test cases for functions in markdown"""

    @mock.patch('gn2.wqflask.api.markdown.requests.get')
    def test_render_markdown_when_fetching_locally(self, requests_mock):
        requests_mock.return_value = MockRequests404()
        markdown_content = render_markdown("general/glossary/glossary.md")
        requests_mock.assert_called_with(
            "https://raw.githubusercontent.com"
            "/genenetwork/gn-docs/"
            "master/general/"
            "glossary/glossary.md")
        self.assertRegex(markdown_content,
                         "Content for general/glossary/glossary.md not available.")

    @mock.patch('gn2.wqflask.api.markdown.requests.get')
    def test_render_markdown_when_fetching_remotely(self, requests_mock):
        requests_mock.return_value = MockRequests200()
        markdown_content = render_markdown("general/glossary/glossary.md")
        requests_mock.assert_called_with(
            "https://raw.githubusercontent.com"
            "/genenetwork/gn-docs/"
            "master/general/"
            "glossary/glossary.md")
        self.assertEqual("""<h1>Glossary</h1>
<p>This is some content</p>
<h2>Sub-heading</h2>
<p>This is another sub-heading</p>""",
                         markdown_content)