Пример #1
0
    async def test_client_fetch_recent_news(self, mock):
        """Testing fetching recent nows"""
        content = self.load_resource(FILE_NEWS_LIST)
        mock.post(NewsArchive.get_url(), status=200, body=content)
        recent_news = await self.client.fetch_recent_news(30)

        self.assertIsInstance(recent_news.data, NewsArchive)
        self.assertIsInstance(recent_news.data.entries[0], NewsEntry)
Пример #2
0
    def test_access_token을_찾을_수_없을_때(self, mock):
        mock.post('https://www.tistory.com/auth/login', status_code=302)
        mock.get('https://www.tistory.com/oauth/authorize', status_code=302)

        pytistory = PyTistory()
        self.assertRaises(ConfigurationError,
                          pytistory.configure,
                          client_id='example client id',
                          tistory_id='example tistory id',
                          tistory_password='******')
Пример #3
0
    def test_잘못된_CLIENT_ID_와_SECRET_KEY_2(self, mock):
        mock.post('https://www.tistory.com/auth/login', status_code=302)
        mock.get('https://www.tistory.com/oauth/authorize', status_code=400)

        pytistory = PyTistory()
        self.assertRaises(ConfigurationError,
                          pytistory.configure,
                          client_id='example client id',
                          tistory_id='example tistory id',
                          tistory_password='******')
Пример #4
0
    def test_파일을_통한_인증_파일명_넘길_때(self, _1, _2, mock):
        mock.post('https://www.tistory.com/auth/login', status_code=302)
        mock.get('https://www.tistory.com/oauth/authorize', status_code=302, headers={
                 'Location': 'some_callback_url/#access_token=some-access-token&state=some-state'})

        pytistory = PyTistory()
        pytistory.configure(file_name='some-file-name')

        self.assertEqual(pytistory.access_token,
                         'some-access-token', 'Access Token 설정 실패')
Пример #5
0
    def test_access_token을_찾을_수_없을_때_2(self, mock):
        mock.post('https://www.tistory.com/auth/login', status_code=302)
        mock.get('https://www.tistory.com/oauth/authorize', status_code=302, headers={
                 'Location': 'some_callback_url/#state=some-state'})

        pytistory = PyTistory()
        self.assertRaises(ConfigurationError,
                          pytistory.configure,
                          client_id='example client id',
                          tistory_id='example tistory id',
                          tistory_password='******')
Пример #6
0
    def test_access_token_설정(self, mock):
        mock.post('https://www.tistory.com/auth/login', status_code=302)
        mock.get('https://www.tistory.com/oauth/authorize', status_code=302, headers={
                 'Location': 'some_callback_url/#access_token=some-access-token&state=some-state'})

        pytistory = PyTistory()
        pytistory.configure(client_id='example client id', tistory_id='example tistory id',
                            tistory_password='******')

        self.assertEqual(pytistory.access_token,
                         'some-access-token', 'Access Token 설정 실패')
Пример #7
0
    def __mock_github_api(self, mock):
        github_api = 'https://api.github.com'
        user = os.getenv('REPOSITORY_USERNAME')
        repo = os.getenv('REPOSITORY_NAME')
        token = os.getenv('OAUTH_TOKEN')
        pr_id = os.getenv('PULL_REQUEST_ID')

        mock.post(
            f"{github_api}/repos/{user}/{repo}/pulls/{pr_id}/comments",
            request_headers={'authorization': f'token {token}'},
            json='ok'
        )
Пример #8
0
    async def test_client_handle_errors(self, mock):
        """Testing error handling"""
        mock.get(WorldOverview.get_url(), status=403)
        with self.assertRaises(Forbidden):
            await self.client.fetch_world_list()

        mock.get(WorldOverview.get_url(), status=404)
        with self.assertRaises(NetworkError):
            await self.client.fetch_world_list()

        mock.get(NewsEntry.get_list_url(), exception=aiohttp.ClientError())
        with self.assertRaises(NetworkError):
            await self.client.fetch_world_list()

        mock.post(NewsEntry.get_list_url(), exception=aiohttp.ClientOSError())
        with self.assertRaises(NetworkError):
            await self.client.fetch_recent_news(30)
Пример #9
0
    def _setup_login_logout(self, mock):
        login_html = '''
            <input name="__ncforminfo" value="AnyValue">
            <input name="csrf" value="AnyValue">
        '''

        mock.get(re.compile(mock_ee_login_url),
                 text=login_html,
                 status_code=200)
        mock.post(re.compile(mock_ee_login_url),
                  text=login_html,
                  status_code=200)
        mock.get(mock_ee_logout_url, status_code=200)

        mock.post(mock_filters_url,
                  json={
                      'error': [],
                      'data': default_filters
                  },
                  status_code=200,
                  headers={'content-type': 'application/json'})