def setUp(self):
     resource_type, _ = OfficialResourceType.objects.get_or_create(
         short_name="ta",
         long_name="translationAcademy"
     )
     language, _ = Language.objects.get_or_create(
         code="en",
         name="English"
     )
     source_language, _ = Language.objects.get_or_create(
         code="arc",
         name="Aramaic"
     )
     self.user, _ = User.objects.get_or_create(
         first_name="Test",
         last_name="RequestorUser",
         username="******"
     )
     self.publish_request, _ = PublishRequest.objects.get_or_create(
         requestor="Test tA publish request",
         resource_type=resource_type,
         language=language,
         checking_level=1,
         source_text=source_language
     )
     self.resource = TranslationAcademy("en", self.publish_request)
 def setUp(self):
     resource_type, _ = OfficialResourceType.objects.get_or_create(
         short_name="ta", long_name="translationAcademy")
     language, _ = Language.objects.get_or_create(code="en", name="English")
     source_language, _ = Language.objects.get_or_create(code="arc",
                                                         name="Aramaic")
     self.user, _ = User.objects.get_or_create(
         first_name="Test",
         last_name="RequestorUser",
         username="******")
     self.publish_request, _ = PublishRequest.objects.get_or_create(
         requestor="Test tA publish request",
         resource_type=resource_type,
         language=language,
         checking_level=1,
         source_text=source_language)
     self.resource = TranslationAcademy("en", self.publish_request)
 def setUp(self):
     self.resource = TranslationAcademy("en")
class TranslationAcademyTestCase(TestCase):

    def setUp(self):
        self.resource = TranslationAcademy("en")

    @requests_mock.mock()
    def test_fetch_chapters(self, mock_requests):
        contents = (
            '<h2 id="volume-1-table-of-contents">Volume 1 Table of Contents</h2>'
            '<div id="plugin_include__en__ta__vol1__intro__toc_intro">'
            '<h3 class="sectionedit4" id="table-of-contents-introduction">'
            'Table of Contents - Introduction</h3><div class="level3">'
            '<p>This module answers the question: What is in the Introduction?<br>'
            '</p></div><h4 id="introduction">Introduction</h4><div class="level4">'
            '<ol><li class="level1"><div class="li"> <a href="/en/ta/vol1/intro/ta_'
            'intro" class="wikilink1" title="en:ta:vol1:intro:ta_intro">Introduction'
            ' to translationAcademy</a></div></li></ol></div></div>'
        )
        expected = {
            'chapters': [
                {
                    'frames': [{
                        'id': u'introduction-to-translationacademy',
                        'ref': u'/en/ta/vol1/intro/ta_intro',
                        'title': u'Introduction to translationAcademy',
                        'text': (
                            u'<h2 id="introduction-to-translationacademy">\n '
                            u'Introduction to translationAcademy\n</h2>'
                        )
                    }],
                    'title': u'Introduction'
                }
            ],
            'id': u'volume-1-table-of-contents',
            'title': u'Volume 1 Table of Contents'
        }
        mock_requests.get(
            "https://door43.org/en/ta/vol1/toc?do=export_xhtmlbody",
            text=contents
        )
        mock_requests.get(
            "https://door43.org/en/ta/vol1/intro/ta_intro?do=export_xhtmlbody",
            text=(
                '<h2 id="introduction-to-translationacademy">Introduction to '
                'translationAcademy</h2>'
            )
        )
        toc = self.resource.fetch_chapters()
        self.assertEquals(toc, expected)

    @requests_mock.mock()
    def test_fetch_frame(self, mock_requests):
        expected = {
            "text": (
                u'<h3 id="/foo/bar">\n Foobar\n</h3>\n<div>\n <a href'
                u'="/foo/bar">\n  foobar\n </a>\n</div>'
            ),
            "id": u"/foo/bar",
            "ref": "/en/ta/vol1/toc",
            "title": u"Foobar"
        }
        contents = (
            '<h3 id="/foo/bar">Foobar</h3><!--comment--><div><a href="/foo/bar'
            '">foobar</a></div>'
        )
        mock_requests.get(
            "https://door43.org/en/ta/vol1/toc?do=export_xhtmlbody",
            text=contents
        )

        chapter = self.resource.fetch_frame("/en/ta/vol1/toc")
        self.assertEquals(chapter, expected)
 def setUp(self):
     self.resource = TranslationAcademy("en")
class TranslationAcademyTestCase(TestCase):
    def setUp(self):
        self.resource = TranslationAcademy("en")

    @requests_mock.mock()
    def test_fetch_chapters(self, mock_requests):
        contents = (
            '<h2 id="volume-1-table-of-contents">Volume 1 Table of Contents</h2>'
            '<div id="plugin_include__en__ta__vol1__intro__toc_intro">'
            '<h3 class="sectionedit4" id="table-of-contents-introduction">'
            'Table of Contents - Introduction</h3><div class="level3">'
            '<p>This module answers the question: What is in the Introduction?<br>'
            '</p></div><h4 id="introduction">Introduction</h4><div class="level4">'
            '<ol><li class="level1"><div class="li"> <a href="/en/ta/vol1/intro/ta_'
            'intro" class="wikilink1" title="en:ta:vol1:intro:ta_intro">Introduction'
            ' to translationAcademy</a></div></li></ol></div></div>')
        expected = {
            'chapters': [{
                'frames': [{
                    'id':
                    u'introduction-to-translationacademy',
                    'ref':
                    u'/en/ta/vol1/intro/ta_intro',
                    'title':
                    u'Introduction to translationAcademy',
                    'text': (u'<h2 id="introduction-to-translationacademy">\n '
                             u'Introduction to translationAcademy\n</h2>')
                }],
                'title':
                u'Introduction'
            }],
            'id':
            u'volume-1-table-of-contents',
            'title':
            u'Volume 1 Table of Contents'
        }
        mock_requests.get(
            "https://door43.org/en/ta/vol1/toc?do=export_xhtmlbody",
            text=contents)
        mock_requests.get(
            "https://door43.org/en/ta/vol1/intro/ta_intro?do=export_xhtmlbody",
            text=(
                '<h2 id="introduction-to-translationacademy">Introduction to '
                'translationAcademy</h2>'))
        toc = self.resource.fetch_chapters()
        self.assertEquals(toc, expected)

    @requests_mock.mock()
    def test_fetch_frame(self, mock_requests):
        expected = {
            "text": (u'<h3 id="/foo/bar">\n Foobar\n</h3>\n<div>\n <a href'
                     u'="/foo/bar">\n  foobar\n </a>\n</div>'),
            "id":
            u"/foo/bar",
            "ref":
            "/en/ta/vol1/toc",
            "title":
            u"Foobar"
        }
        contents = (
            '<h3 id="/foo/bar">Foobar</h3><!--comment--><div><a href="/foo/bar'
            '">foobar</a></div>')
        mock_requests.get(
            "https://door43.org/en/ta/vol1/toc?do=export_xhtmlbody",
            text=contents)

        chapter = self.resource.fetch_frame("/en/ta/vol1/toc")
        self.assertEquals(chapter, expected)
class TranslationAcademyTestCase(TestCase):
    def setUp(self):
        resource_type, _ = OfficialResourceType.objects.get_or_create(
            short_name="ta", long_name="translationAcademy")
        language, _ = Language.objects.get_or_create(code="en", name="English")
        source_language, _ = Language.objects.get_or_create(code="arc",
                                                            name="Aramaic")
        self.user, _ = User.objects.get_or_create(
            first_name="Test",
            last_name="RequestorUser",
            username="******")
        self.publish_request, _ = PublishRequest.objects.get_or_create(
            requestor="Test tA publish request",
            resource_type=resource_type,
            language=language,
            checking_level=1,
            source_text=source_language)
        self.resource = TranslationAcademy("en", self.publish_request)

    @requests_mock.mock()
    def test_fetch_table_of_contents(self, mock_requests):

        # so unit tests will show the the whole diff if actual does not equal expected
        self.maxDiff = None

        toc = u'## Volume 1 Table of Contents\n\n### Table of Contents - Introduction\n\n'
        toc += u'This module answers the question: What is in the Introduction?  \n\n#### Introduction\n\n'
        toc += u'  1. [Introduction to translationAcademy](/en/ta/vol1/intro/ta_intro "en:ta:vol1:intro:ta_intro" )\n\n'
        expected = {
            'toc':
            toc,
            'meta': {
                'status': {
                    'source_text': 'arc',
                    'version': '',
                    'publish_date': time.strftime("%Y-%m-%d"),
                    'license': 'CC BY-SA 4.0',
                    'contributors': u'',
                    'checking_level': 1,
                    'checking_entity': '',
                    'source_text_version': u''
                },
                'direction': 'ltr',
                'lc': 'en',
                'anglicized_name': u'',
                'mod': 1457440696,
                'name': 'English'
            },
            'chapters': [{
                'frames': [{
                    'id':
                    u'vol1_intro_ta_intro',
                    'ref':
                    u'/en/ta/vol1/intro/ta_intro',
                    'title':
                    u'Introduction to translationAcademy',
                    'text':
                    u'<h3>Introduction to translationAcademy</h3>'
                }],
                'title':
                u'Introduction'
            }]
        }
        contents = (
            '<h2 id="volume-1-table-of-contents">Volume 1 Table of Contents</h2>'
            '<div id="plugin_include__en__ta__vol1__intro__toc_intro" class="plugin_include_content">'
            '<h3 class="sectionedit4" id="table-of-contents-introduction">'
            'Table of Contents - Introduction</h3><div class="level3">'
            '<p>This module answers the question: What is in the Introduction?<br>'
            '</p></div><h4 id="introduction">Introduction</h4><div class="level4">'
            '<ol><li class="level1"><div class="li"> <a href="/en/ta/vol1/intro/ta_'
            'intro" class="wikilink1" title="en:ta:vol1:intro:ta_intro">Introduction'
            ' to translationAcademy</a></div></li></ol></div></div>')
        mock_requests.get("https://door43.org/en/ta/toc?do=export_xhtmlbody",
                          text=contents)
        mock_requests.get(
            "https://door43.org/en/ta/vol1/intro/ta_intro?do=export_xhtmlbody",
            text=u'<h3>Introduction to translationAcademy</h3>')
        actual = self.resource.fetch_chapters()

        # synchronize the timestamps so they are the same for the test
        expected['meta']['mod'] = actual['meta']['mod']

        self.assertEquals(actual, expected)

    @requests_mock.mock()
    def test_fetch_frame(self, mock_requests):
        expected = {
            "text": (u'<h3>Foobar</h3><div><a href'
                     u'="/foo/bar">foobar</a></div>'),
            "id":
            u"vol1_toc",
            "ref":
            "/en/ta/vol1/toc",
            "title":
            u"Foobar"
        }
        contents = (
            '<h3 id="/foo/bar">Foobar</h3><!--comment--><div><a href="/foo/bar'
            '">foobar</a></div>')
        mock_requests.get(
            "https://door43.org/en/ta/vol1/toc?do=export_xhtmlbody",
            text=contents)

        chapter = self.resource.fetch_frame("/en/ta/vol1/toc")
        self.assertEquals(chapter, expected)
class TranslationAcademyTestCase(TestCase):
    def setUp(self):
        resource_type, _ = OfficialResourceType.objects.get_or_create(
            short_name="ta",
            long_name="translationAcademy"
        )
        language, _ = Language.objects.get_or_create(
            code="en",
            name="English"
        )
        source_language, _ = Language.objects.get_or_create(
            code="arc",
            name="Aramaic"
        )
        self.user, _ = User.objects.get_or_create(
            first_name="Test",
            last_name="RequestorUser",
            username="******"
        )
        self.publish_request, _ = PublishRequest.objects.get_or_create(
            requestor="Test tA publish request",
            resource_type=resource_type,
            language=language,
            checking_level=1,
            source_text=source_language
        )
        self.resource = TranslationAcademy("en", self.publish_request)

    @requests_mock.mock()
    def test_fetch_table_of_contents(self, mock_requests):

        # so unit tests will show the the whole diff if actual does not equal expected
        self.maxDiff = None

        toc = u'## Volume 1 Table of Contents\n\n### Table of Contents - Introduction\n\n'
        toc += u'This module answers the question: What is in the Introduction?  \n\n#### Introduction\n\n'
        toc += u'  1. [Introduction to translationAcademy](/en/ta/vol1/intro/ta_intro "en:ta:vol1:intro:ta_intro" )\n\n'
        expected = {
            'toc': toc,
            'meta': {
                'status': {
                    'source_text': 'arc',
                    'version': '',
                    'publish_date': time.strftime("%Y-%m-%d"),
                    'license': 'CC BY-SA 4.0',
                    'contributors': u'',
                    'checking_level': 1,
                    'checking_entity': '',
                    'source_text_version': u''
                },
                'direction': 'ltr',
                'lc': 'en',
                'anglicized_name': u'',
                'mod': 1457440696,
                'name': 'English'},
            'chapters': [
                {
                    'frames': [
                        {
                            'id': u'vol1_intro_ta_intro',
                            'ref': u'/en/ta/vol1/intro/ta_intro',
                            'title': u'Introduction to translationAcademy',
                            'text': u'<h3>Introduction to translationAcademy</h3>'
                        }
                    ],
                    'title': u'Introduction'
                }
            ]
        }
        contents = (
            '<h2 id="volume-1-table-of-contents">Volume 1 Table of Contents</h2>'
            '<div id="plugin_include__en__ta__vol1__intro__toc_intro" class="plugin_include_content">'
            '<h3 class="sectionedit4" id="table-of-contents-introduction">'
            'Table of Contents - Introduction</h3><div class="level3">'
            '<p>This module answers the question: What is in the Introduction?<br>'
            '</p></div><h4 id="introduction">Introduction</h4><div class="level4">'
            '<ol><li class="level1"><div class="li"> <a href="/en/ta/vol1/intro/ta_'
            'intro" class="wikilink1" title="en:ta:vol1:intro:ta_intro">Introduction'
            ' to translationAcademy</a></div></li></ol></div></div>'
        )
        mock_requests.get(
            "https://door43.org/en/ta/toc?do=export_xhtmlbody",
            text=contents
        )
        mock_requests.get(
            "https://door43.org/en/ta/vol1/intro/ta_intro?do=export_xhtmlbody",
            text=u'<h3>Introduction to translationAcademy</h3>'
        )
        actual = self.resource.fetch_chapters()

        # synchronize the timestamps so they are the same for the test
        expected['meta']['mod'] = actual['meta']['mod']

        self.assertEquals(actual, expected)

    @requests_mock.mock()
    def test_fetch_frame(self, mock_requests):
        expected = {
            "text": (
                u'<h3>Foobar</h3><div><a href'
                u'="/foo/bar">foobar</a></div>'
            ),
            "id": u"vol1_toc",
            "ref": "/en/ta/vol1/toc",
            "title": u"Foobar"
        }
        contents = (
            '<h3 id="/foo/bar">Foobar</h3><!--comment--><div><a href="/foo/bar'
            '">foobar</a></div>'
        )
        mock_requests.get(
            "https://door43.org/en/ta/vol1/toc?do=export_xhtmlbody",
            text=contents
        )

        chapter = self.resource.fetch_frame("/en/ta/vol1/toc")
        self.assertEquals(chapter, expected)