Exemplo n.º 1
0
    def __init__(self, user_id, user_pw, session_file_path: str = None, no_directly_login: bool = False):
        # Set Properties
        self.__set_theqoo_id(user_id)
        self.__set_theqoo_pw(user_pw)
        # When Parameter Not Passed
        if session_file_path is None:
            self.__session_file_path = ini.SESSION_FILE_NAME
        else:
            self.__session_file_path = session_file_path
        # Get Former Session
        former_session = theqoo_api.get_former_session(self.__session_file_path)
        # Check Former Session Alive
        if former_session is not None:
            # When Can Be Used
            self.session = former_session
            self.__logged_in = True

        if no_directly_login:
            pass
        elif not self.__logged_in:
            # When Unable To Use Former Session
            try:
                self.__logged_in = theqoo_api.do_login(
                    session=self.session,
                    login_id=self.__theqoo_id,
                    login_pw=self.__theqoo_pw,
                    session_file_name=self.__session_file_path)
            except ConnectionError as e:
                util.print_message(message_type=MessageTypes.ERROR,
                                   message=f'다음과 같은 이유로 로그인에 실패하였습니다. {e.strerror}')
        # Set Headers To Session
        self.session.headers = {
            'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko',
            'Host': 'theqoo.net'
        }
Exemplo n.º 2
0
 def test_get_user_documents_ok(self):
     with api.get_former_session(test_setting.FILE_WITH_SESSION) as s:
         res = api.get_user_documents(s)
         self.assertIsInstance(res, list)
         self.assertGreater(len(res), 0)
         for doc in res:
             self.assertIsInstance(doc, api.Document)
             self.assertTrue(doc.category_nm is not None, doc.category_nm)
             self.assertTrue(doc.title is not None, doc.title)
             self.assertTrue(doc.srl is not None, doc.srl)
Exemplo n.º 3
0
 def test_delete_document_success_instrumented(self):
     with api.get_former_session(session_file_name=test_setting.FILE_WITH_SESSION) as s:
         self.delete_document_success(s, self.document_srl)
Exemplo n.º 4
0
 def test_get_former_session_no_session(self):
     res = api.get_former_session(session_file_name=test_setting.FILE_NO_SESSION)
     self.assertIsNone(res)
Exemplo n.º 5
0
 def test_get_former_session_no_session_file(self):
     # When There's No File
     res = api.get_former_session('File Nothing')
     self.assertIsNone(res, "None should be returned when there's no file")
Exemplo n.º 6
0
 def test_get_former_session_got_session(self):
     res = api.get_former_session(session_file_name=test_setting.FILE_WITH_SESSION)
     self.assertIsNotNone(res)
     self.assertIsInstance(res, requests.Session)
Exemplo n.º 7
0
 def test_get_user_comments_success_instrumented(self):
     with api.get_former_session(session_file_name=test_setting.FILE_WITH_SESSION) as s:
         self.get_user_comments_success(s)