Ejemplo 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))
Ejemplo n.º 2
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))
Ejemplo n.º 3
0
 def test_print_entry_summary(self):
     entry = ElyxerEntry()
     entry._Entry__images = [Image("<img src='photo.jpg' />")]
     entry._Entry__title = 'my title'
     entry._Entry__body = 'fine, fine day'
     returned = self.display.print_entry_summary(entry)
     expected = "You are about to publish:\n\n    my title\n      3 words\n      1 image\n"
     print '**************************************************************'
     print returned
     print expected
     self.assertEqual(returned, expected)
Ejemplo n.º 4
0
 def test_print_entry_summary(self):
     entry = ElyxerEntry()
     entry._Entry__images = [Image("<img src='photo.jpg' />")]
     entry._Entry__title = 'my title'
     entry._Entry__body = 'fine, fine day'
     returned = self.display.print_entry_summary(entry)
     expected = "You are about to publish:\n\n    my title\n      3 words\n      1 image\n"
     print '**************************************************************'
     print returned
     print expected
     self.assertEqual(returned, expected)
Ejemplo n.º 5
0
 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()
Ejemplo n.º 6
0
 def test_replace_special_characters(self):
     aa = ElyxerEntry()
     body = "&lt;code&gt;   SOME CODE   &lt;/code&gt;"
     body += "Footnotes:  [→    →] "
     aa._Entry__body = body
     aa._Entry__replace_special_characters()
     self.assertTrue('<code>' in aa.get_body())
     self.assertTrue('</code>' in aa.get_body())
     self.assertTrue('→' not in aa.get_body())
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 def test_get_title(self):
     aa = ElyxerEntry()
     self.assertEqual(aa.get_title(), None)
     aa.load(self.filename)
     self.assertEqual(aa.get_title(), 'Tutorial de LyX')
     self.assertRaises(TitleAlreadySetError,
                       lambda: aa.set_title('Second Title'))
Ejemplo n.º 9
0
 def test_replace_special_characters(self):
     aa = ElyxerEntry()
     body = "&lt;code&gt;   SOME CODE   &lt;/code&gt;"
     body +="Footnotes:  [→    →] "
     aa._Entry__body = body
     aa._Entry__replace_special_characters()
     self.assertTrue('<code>' in aa.get_body())
     self.assertTrue('</code>' in aa.get_body())
     self.assertTrue('→' not in aa.get_body())
Ejemplo n.º 10
0
 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()
Ejemplo n.º 11
0
 def test_get_wordcount(self):
     aa = ElyxerEntry()
     aa.load(self.filename)
     returned = aa.get_num_words()
     self.assertTrue(isinstance(returned, int))
Ejemplo n.º 12
0
 def test_load(self):
     aa = ElyxerEntry()
     aa.load(self.filename)
     self.assertTrue('Tutorial de LyX' in aa.get_body())
Ejemplo n.º 13
0
 def test_get_num_images(self):
     aa = ElyxerEntry()
     self.assertEqual(aa.get_num_images(), 0)
     aa.load(self.filename)
     self.assertEqual(aa.get_num_images(), 1)
Ejemplo n.º 14
0
 def test_get_num_words(self):
     aa = ElyxerEntry()
     aa._Entry__body = '<b> </b> three more lines'
     self.assertEqual(aa.get_num_words(), 3)
Ejemplo n.º 15
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)
Ejemplo n.º 16
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)
Ejemplo n.º 17
0
 def test_get_num_words(self):
     aa = ElyxerEntry()
     aa._Entry__body = '<b> </b> three more lines'
     self.assertEqual(aa.get_num_words(), 3)
Ejemplo n.º 18
0
 def test_get_num_images(self):
     aa = ElyxerEntry()
     self.assertEqual(aa.get_num_images(), 0)
     aa.load(self.filename)
     self.assertEqual(aa.get_num_images(), 1)
Ejemplo n.º 19
0
 def test_get_wordcount(self):
     aa = ElyxerEntry()
     aa.load(self.filename)
     returned = aa.get_num_words()
     self.assertTrue(isinstance(returned, int))
Ejemplo n.º 20
0
 def test_load(self):
     aa = ElyxerEntry()
     aa.load(self.filename)
     self.assertTrue('Tutorial de LyX' in aa.get_body())
Ejemplo n.º 21
0
 def test_get_title(self):
     aa = ElyxerEntry()
     self.assertEqual(aa.get_title(), None)
     aa.load(self.filename)
     self.assertEqual(aa.get_title(), 'Tutorial de LyX')
     self.assertRaises(TitleAlreadySetError, lambda: aa.set_title('Second Title'))
Ejemplo n.º 22
0
 def test_publish(self):
     aa = ElyxerEntry()
     self.assertRaises(TransmitterNotDefinedError, lambda: aa.publish())
Ejemplo n.º 23
0
 def test_publish(self):
     aa = ElyxerEntry()
     self.assertRaises(TransmitterNotDefinedError, lambda: aa.publish())