Exemplo n.º 1
0
 def test_set_transmitter_exactly_once(self):
     tt = Transmitter()
     url = 'whee.com'
     username = '******'
     account = Account(url, username, None)
     tt.set_account(account)
     aa = ElyxerEntry()
     aa.set_transmitter(tt)
     self.assertRaises(TransmitterAlreadyExistsError, lambda: aa.set_transmitter(tt))
Exemplo n.º 2
0
 def test_upload_entry(self):
     tt = Transmitter()
     tt.set_account(self.account_with_good_password)
     filename = 'test_files/entry_test'
     entry = ElyxerEntry()
     entry.set_transmitter(tt)
     entry.load(filename)
     entry.set_title('WoooYAH!')
     tt.publish_entry(entry)
Exemplo n.º 3
0
 def test_set_transmitter_exactly_once(self):
     tt = Transmitter()
     url = 'whee.com'
     username = '******'
     account = Account(url, username, None)
     tt.set_account(account)
     aa = ElyxerEntry()
     aa.set_transmitter(tt)
     self.assertRaises(TransmitterAlreadyExistsError,
                       lambda: aa.set_transmitter(tt))
Exemplo n.º 4
0
class LyXBlogger:

    VERSION = '0.43'
    def __init__(self, input_file, display = None):
        self.__display = display or Display()
        self.__state = 0
        self.__entry = None
        self.__manager = AccountManager()
        self.__input_file = input_file

    def start(self):
        self.__welcome()
        self.__entry = ElyxerEntry()
        self.__entry.load(self.__input_file)
        self.__ensure_title()
        self.__display_summary()
        account = self.__verify_which_account()
        self.__ensure_password(account)
        transmitter = self.__manager.pass_transmitter()
        self.__entry.set_transmitter(transmitter)
        self.__verify_create_new_or_overwrite()
        self.__publishing_message(account)
        self.__entry.publish()
        self.__closing_remarks()

    def __verify_which_account(self):
        dd = self.__display
        mm = self.__manager
        recent_id = mm.get_recent_id()
        while(1):
            accounts = mm.get_accounts()
            response_with_case = dd.ask_which_account(accounts, recent_id)
            response = response_with_case.lower()
            if response == 'd':
                account_id = dd.ask_which_account(accounts, True)
                mm.delete_account_by_id(int(account_id))
            elif response == 'n':
                username = dd.ask_for_new_username()
                url = dd.ask_for_new_url()
                password = dd.ask_for_new_password()
                new_account = Account(url, username, password)
                mm.add_new_account(new_account)
            elif response == '':
                return mm.get_recent_account()
            elif re.compile('^\d+$').match(response):
                account_id = int(response)
                return mm.get_account_by_id(account_id)
            else:
                dd.print_unrecognized_response(response_with_case)


    def __ensure_title(self):
        if not self.__entry.get_title():
            title = self.__display.ask_for_title()
            self.__entry.set_title(title)
        
    def __ensure_password(self, account):
        if not account.get_password():
            temp = self.__display.ask_for_temp_password(account)
            account.set_temp_password(temp)

    def __verify_create_new_or_overwrite(self):
        pass

    def __welcome(self):
        self.__display.welcome(LyXBlogger.VERSION)

    def __closing_remarks(self):
        self.__display.print_done()

    def __display_summary(self):
        self.__display.print_entry_summary(self.__entry)

    def __publishing_message(self, account):
        self.__display.print_uploading(account)
Exemplo n.º 5
0
class LyXBlogger:

    VERSION = '0.43'

    def __init__(self, input_file, display=None):
        self.__display = display or Display()
        self.__state = 0
        self.__entry = None
        self.__manager = AccountManager()
        self.__input_file = input_file

    def start(self):
        self.__welcome()
        self.__entry = ElyxerEntry()
        self.__entry.load(self.__input_file)
        self.__ensure_title()
        self.__display_summary()
        account = self.__verify_which_account()
        self.__ensure_password(account)
        transmitter = self.__manager.pass_transmitter()
        self.__entry.set_transmitter(transmitter)
        self.__verify_create_new_or_overwrite()
        self.__publishing_message(account)
        self.__entry.publish()
        self.__closing_remarks()

    def __verify_which_account(self):
        dd = self.__display
        mm = self.__manager
        recent_id = mm.get_recent_id()
        while (1):
            accounts = mm.get_accounts()
            response_with_case = dd.ask_which_account(accounts, recent_id)
            response = response_with_case.lower()
            if response == 'd':
                account_id = dd.ask_which_account(accounts, True)
                mm.delete_account_by_id(int(account_id))
            elif response == 'n':
                username = dd.ask_for_new_username()
                url = dd.ask_for_new_url()
                password = dd.ask_for_new_password()
                new_account = Account(url, username, password)
                mm.add_new_account(new_account)
            elif response == '':
                return mm.get_recent_account()
            elif re.compile('^\d+$').match(response):
                account_id = int(response)
                return mm.get_account_by_id(account_id)
            else:
                dd.print_unrecognized_response(response_with_case)

    def __ensure_title(self):
        if not self.__entry.get_title():
            title = self.__display.ask_for_title()
            self.__entry.set_title(title)

    def __ensure_password(self, account):
        if not account.get_password():
            temp = self.__display.ask_for_temp_password(account)
            account.set_temp_password(temp)

    def __verify_create_new_or_overwrite(self):
        pass

    def __welcome(self):
        self.__display.welcome(LyXBlogger.VERSION)

    def __closing_remarks(self):
        self.__display.print_done()

    def __display_summary(self):
        self.__display.print_entry_summary(self.__entry)

    def __publishing_message(self, account):
        self.__display.print_uploading(account)