Ejemplo n.º 1
0
    def test_wiki_dump_retry(self):
        responses.add(
            responses.Response(
                responses.GET,
                'http://localhost:8000/v2/registrations/fxehm/wikis/',
                status=429,
                headers={'Retry-After': '1'},
            )
        )
        responses.add(
            responses.Response(
                responses.GET,
                'http://localhost:8000/v2/registrations/fxehm/wikis/',
                json=wiki_metadata(),
            )
        )
        responses.add(
            responses.Response(
                responses.GET,
                'https://localhost:8000/v2/wikis/dtns3/content/',
                body=b'dtns3 data',
            ),
        )
        responses.add(
            responses.Response(
                responses.GET,
                'https://localhost:8000/v2/wikis/md549/content/',
                body=b'md549 data',
            ),
        )
        responses.add(
            responses.Response(
                responses.GET,
                'https://localhost:8000/v2/wikis/p8kxa/content/',
                body=b'p8kxa data',
            ),
        )

        with mock.patch('builtins.open', mock.mock_open()) as m:
            asyncio.run(main('fxehm'))
            assert m.call_args_list == [
                call('/home.md', 'wb'),
                call('/test1Ω≈ç√∫˜µ≤≥≥÷åß∂ƒ©˙∆∆˚¬…æ.md', 'wb'),
                call('/test2.md', 'wb')
            ]
            handle = m()

            assert handle.write.call_args_list == [
                call(b'dtns3 data'),
                call(b'md549 data'),
                call(b'p8kxa data')
            ]
Ejemplo n.º 2
0
    def test_wiki_dump_multiple_pages(self):
        page1, page2 = wiki_metadata_two_pages()
        responses.add(
            responses.Response(
                responses.GET,
                'http://localhost:8000/v2/registrations/fxehm/wikis/',
                json=page1,
                match_querystring=True,
            ))
        responses.add(
            responses.Response(
                responses.GET,
                'http://localhost:8000/v2/registrations/fxehm/wikis/?page=2',
                json=page2,
                match_querystring=True,
            ))

        data = page1['data'] + page2['data']
        for wiki in data:
            responses.add(
                responses.Response(
                    responses.GET,
                    f'https://localhost:8000/v2/wikis{wiki["attributes"]["path"]}/content/',
                    body=f'{wiki["attributes"]["path"]} data',
                ), )

        with mock.patch('builtins.open', mock.mock_open()) as m:
            asyncio.run(main('fxehm', ''))
            mock_path = os.path.abspath(os.path.join(HERE, '..', 'fxehm'))
            assert_equal(m.call_args_list, [
                call(
                    os.path.join(mock_path,
                                 f'{wiki["attributes"]["name"]}.md'), 'wb')
                for wiki in data
            ])

            handle = m()
            assert_equal(handle.write.call_args_list, [
                call(
                    os.path.join(
                        mock_path,
                        f'{wiki["attributes"]["path"]} data').encode())
                for wiki in data
            ])
Ejemplo n.º 3
0
    def test_wiki_dump(self):
        responses.add(
            responses.Response(
                responses.GET,
                'http://localhost:8000/v2/registrations/fxehm/wikis/',
                json=wiki_metadata(),
            ))
        responses.add(
            responses.Response(
                responses.GET,
                'https://localhost:8000/v2/wikis/dtns3/content/',
                body=b'dtns3 data',
            ), )
        responses.add(
            responses.Response(
                responses.GET,
                'https://localhost:8000/v2/wikis/md549/content/',
                body=b'md549 data',
            ), )
        responses.add(
            responses.Response(
                responses.GET,
                'https://localhost:8000/v2/wikis/p8kxa/content/',
                body=b'p8kxa data',
            ), )

        with mock.patch('builtins.open', mock.mock_open()) as m:
            asyncio.run(main('fxehm', ''))
            mock_path = os.path.abspath(os.path.join(HERE, '..', 'fxehm'))
            assert m.call_args_list == [
                call(os.path.join(mock_path, 'home.md'), 'wb'),
                call(
                    os.path.join(mock_path, 'test1Ω≈ç√∫˜µ≤≥≥÷åß∂ƒ©˙∆∆˚¬…æ.md'),
                    'wb'),
                call(os.path.join(mock_path, 'test2.md'), 'wb')
            ]
            handle = m()

            assert handle.write.call_args_list == [
                call(b'dtns3 data'),
                call(b'md549 data'),
                call(b'p8kxa data')
            ]