Exemple #1
0
def test_account_should_keep_configuration():
    account = Account(enabled=True,
                      name='my name',
                      user='******',
                      password='******',
                      oauth2string='who knows',
                      server='example.org',
                      port='1234',
                      ssl=True,
                      imap=True,
                      idle=True,
                      folders=['a', 'b'],
                      mailbox_type='mybox')
    config = account.get_config()
    expected_config = {
        'enabled': True,
        'name': 'my name',
        'user': '******',
        'password': '******',
        'oauth2string': 'who knows',
        'server': 'example.org',
        'port': '1234',
        'ssl': True,
        'imap': True,
        'idle': True,
        'folders': ['a', 'b'],
        'mailbox_type': 'mybox',
    }
    assert expected_config == config
Exemple #2
0
def test_account_should_store_configuration():
    new_config = {
        'user': '******',
        'password': '******',
        'oauth2string': 'who knows',
        'server': 'example.org',
        'port': '1234',
        'ssl': True,
        'imap': True,
        'idle': True,
        'folders': ['a', 'b'],
    }
    account = Account()
    account.set_config(mailbox_type='mybox',
                       name='my name',
                       enabled=True,
                       config=new_config)
    config = account.get_config()
    expected_config = {
        'enabled': True,
        'name': 'my name',
        'user': '******',
        'password': '******',
        'oauth2string': 'who knows',
        'server': 'example.org',
        'port': '1234',
        'ssl': True,
        'imap': True,
        'idle': True,
        'folders': ['a', 'b'],
        'mailbox_type': 'mybox',
    }
    assert expected_config == config
Exemple #3
0
def test_account_should_keep_configuration():
    account = Account(
        enabled=True,
        name="my name",
        user="******",
        password="******",
        oauth2string="who knows",
        server="example.org",
        port="1234",
        ssl=True,
        imap=True,
        idle=True,
        folders=["a", "b"],
        mailbox_type="mybox",
    )
    config = account.get_config()
    expected_config = {
        "enabled": True,
        "name": "my name",
        "user": "******",
        "password": "******",
        "oauth2string": "who knows",
        "server": "example.org",
        "port": "1234",
        "ssl": True,
        "imap": True,
        "idle": True,
        "folders": ["a", "b"],
        "mailbox_type": "mybox",
    }
    assert expected_config == config
Exemple #4
0
def test_account_should_keep_configuration():
	account = Account(enabled=True,
					  name='my name',
					  user='******',
					  password='******',
					  oauth2string='who knows',
					  server='example.org',
					  port='1234',
					  ssl=True,
					  imap=True,
					  idle=True,
					  folders=['a', 'b'],
					  mailbox_type='mybox')
	config = account.get_config()
	expected_config = {
		'enabled': True,
		'name': 'my name',
		'user': '******',
		'password': '******',
		'oauth2string': 'who knows',
		'server': 'example.org',
		'port': '1234',
		'ssl': True,
		'imap': True,
		'idle': True,
		'folders': ['a', 'b'],
		'mailbox_type': 'mybox',
	}
	assert expected_config == config
Exemple #5
0
def test_account_should_store_configuration():
	new_config = {
		'user': '******',
		'password': '******',
		'oauth2string': 'who knows',
		'server': 'example.org',
		'port': '1234',
		'ssl': True,
		'imap': True,
		'idle': True,
		'folders': ['a', 'b'],
	}
	account = Account()
	account.set_config(mailbox_type='mybox', name='my name', enabled=True, config=new_config)
	config = account.get_config()
	expected_config = {
		'enabled': True,
		'name': 'my name',
		'user': '******',
		'password': '******',
		'oauth2string': 'who knows',
		'server': 'example.org',
		'port': '1234',
		'ssl': True,
		'imap': True,
		'idle': True,
		'folders': ['a', 'b'],
		'mailbox_type': 'mybox',
	}
	assert expected_config == config
Exemple #6
0
def test_account_get_id_should_be_consistent():
    account = Account(name='a',
                      mailbox_type='imap',
                      enabled=True,
                      user='******',
                      server='xx')
    expected_id = account.get_id()
    for i in range(20):
        assert account.get_id() == expected_id
Exemple #7
0
        def worker_thread(name):
            folders = []
            exception = None

            try:
                acc = Account()
                self._configure_account(acc)
                folders = acc.request_server_folders()
            except Exception as ex:
                exception = ex

            # Executed on the GTK main thread
            def finished_func():
                spinner.stop()
                spinner.destroy()

                if exception != None:
                    self._error_label = Gtk.Label()
                    self._error_label.set_justify(Gtk.Justification.CENTER)
                    self._error_label.set_halign(Gtk.Align.CENTER)
                    self._error_label.set_valign(Gtk.Align.CENTER)
                    self._error_label.set_markup(
                        '<span foreground="red"><b>%s</b></span>' %
                        _('Connection failed.'))

                    self._overlay.add_overlay(self._error_label)
                    self._overlay.show_all()
                else:
                    for f in folders:
                        enabled = False
                        if f in self._acc.folders:
                            enabled = True
                            self._selected_folder_count += 1
                        row = [enabled, f]
                        self._liststore_folders.append(row)

                    # Enable the push checkbox in case a remote folder wasn't found
                    # and the folder count is now <2.
                    # (e.g. folders have been renamed/removed on the server, the user has entered a
                    # diffent username/password in this dialog, ...)
                    self._chk_account_push.set_sensitive(
                        self._selected_folder_count < 2)
                    self._folders_received = True

            GObject.idle_add(finished_func)
Exemple #8
0
def test_account_get_id_should_be_unique():
    accounts = [
        Account(name='a',
                mailbox_type='imap',
                enabled=True,
                user='******',
                server='xx'),
        Account(name='b',
                mailbox_type='pop3',
                enabled=True,
                user='******',
                server='yy'),
        Account(name='c', mailbox_type='mbox', enabled=True),
        Account(name='d', mailbox_type='maildir', enabled=True),
    ]
    ids = set(acc.get_id() for acc in accounts)

    assert len(ids) == len(accounts)
Exemple #9
0
		def worker_thread(name):
			folders = []
			exception = None
			
			try:
				acc = Account()
				self._configure_account(acc)
				folders = acc.request_server_folders()
			except Exception as ex:
				exception = ex
			
			# Executed on the GTK main thread
			def finished_func():				
				spinner.stop()
				spinner.destroy()
				
				if exception != None:
					self._error_label = Gtk.Label()
					self._error_label.set_justify(Gtk.Justification.CENTER)
					self._error_label.set_halign(Gtk.Align.CENTER)
					self._error_label.set_valign(Gtk.Align.CENTER)
					self._error_label.set_markup('<span foreground="red"><b>%s</b></span>' % _('Connection failed.'))
					
					self._overlay.add_overlay(self._error_label)
					self._overlay.show_all()
				else:
					for f in folders:
						enabled = False
						if f in self._acc.folders:
							enabled = True
							self._selected_folder_count += 1
						row = [enabled, f]
						self._liststore_folders.append(row)
					
					# Enable the push checkbox in case a remote folder wasn't found 
					# and the folder count is now <2.
					# (e.g. folders have been renamed/removed on the server, the user has entered a 
					# diffent username/password in this dialog, ...)
					self._chk_account_push.set_sensitive(self._selected_folder_count < 2)
					self._folders_received = True
			
			GObject.idle_add(finished_func)
Exemple #10
0
    def _on_btn_add_account_clicked(self, widget):
        acc = Account(enabled=True)
        d = AccountDialog(self._window, acc)

        if d.run() == Gtk.ResponseType.OK:
            self._accountman.add(acc)

            row = [acc, acc.enabled, acc.name]
            iter = self._liststore_accounts.append(row)
            model = self._treeview_accounts.get_model()
            path = model.get_path(iter)
            self._treeview_accounts.set_cursor(path, None, False)
            self._treeview_accounts.grab_focus()
Exemple #11
0
	def _on_cmb_account_type_changed(self, widget):
		acctype = widget.get_active()
		
		#
		# Reset everything when the account type changes
		#
		
		if acctype == IDX_POP3:
			self._label_account_name.set_visible(True)
			self._entry_account_name.set_visible(True)
			self._label_account_server.set_visible(True)
			self._entry_account_server.set_visible(True)
			self._label_account_port.set_visible(True)
			self._entry_account_port.set_visible(True)
			self._expander_folders.set_visible(False)
			self._chk_account_push.set_visible(False)
			self._chk_account_ssl.set_visible(True)
		elif acctype == IDX_IMAP:
			self._label_account_name.set_visible(True)
			self._entry_account_name.set_visible(True)
			self._label_account_server.set_visible(True)
			self._entry_account_server.set_visible(True)
			self._label_account_port.set_visible(True)
			self._entry_account_port.set_visible(True)
			self._expander_folders.set_visible(True)
			self._chk_account_push.set_visible(True)
			self._chk_account_ssl.set_visible(True)
		else: # known provider (imap only)
			self._label_account_name.set_visible(False)
			self._entry_account_name.set_visible(False)
			self._label_account_server.set_visible(False)
			self._entry_account_server.set_visible(False)
			self._label_account_port.set_visible(False)
			self._entry_account_port.set_visible(False)
			self._expander_folders.set_visible(True)
			self._chk_account_push.set_visible(False)
			self._chk_account_ssl.set_visible(False)
		
		self._folders_received = False
		self._selected_folder_count = 0
		
		self._expander_folders.set_expanded(False)
		self._liststore_folders.clear()
		
		empty_acc = Account()
		self._load_account(empty_acc)
Exemple #12
0
	def __init__(self, **kw):
		Account.__init__(self, **kw)
		self._backend = FakeBackend()
Exemple #13
0
def test_account_should_configurable_with_any_parameters():
    account = Account(weird='odd', odd='weird')
    config = account.get_config()
    assert config['weird'] == 'odd'
    assert config['odd'] == 'weird'
Exemple #14
0
def test_type_should_be_empty_by_default():
    account = Account()
    config = account.get_config()
    assert account.mailbox_type == ''
    assert config['mailbox_type'] == ''
Exemple #15
0
def test_account_supports_notifications(config, should_support):
	account = Account(**config)
	if should_support:
		assert account.supports_notifications()
	else:
		assert not account.supports_notifications()
Exemple #16
0
def test_account_get_id_should_be_consistent():
	account = Account(name='a', mailbox_type='imap', enabled=True, user='******', server='xx')
	expected_id = account.get_id()
	for i in range(20):
		assert account.get_id() == expected_id
Exemple #17
0
def test_type_should_be_empty_by_default():
	account = Account()
	config = account.get_config()
	assert account.mailbox_type == ''
	assert config['mailbox_type'] == ''
Exemple #18
0
def test_account_should_configurable_with_any_parameters():
	account = Account(weird='odd', odd='weird')
	config = account.get_config()
	assert config['weird'] == 'odd'
	assert config['odd'] == 'weird'
Exemple #19
0
def test_account_should_configurable_with_any_parameters():
    account = Account(weird="odd", odd="weird")
    config = account.get_config()
    assert config["weird"] == "odd"
    assert config["odd"] == "weird"
Exemple #20
0
def test_account_config_should_always_contain_certain_values():
	account = Account()
	config = account.get_config()
	assert 'enabled' in config
	assert 'name' in config
	assert 'mailbox_type' in config
Exemple #21
0
def test_account_config_should_always_contain_certain_values():
    account = Account()
    config = account.get_config()
    assert "enabled" in config
    assert "name" in config
    assert "mailbox_type" in config
Exemple #22
0
def test_account_supports_notifications(config, should_support):
    account = Account(**config)
    if should_support:
        assert account.supports_notifications()
    else:
        assert not account.supports_notifications()
Exemple #23
0
 def __init__(self, **kw):
     Account.__init__(self, **kw)
     self._backend = FakeBackend()
Exemple #24
0
def test_account_config_should_always_contain_certain_values():
    account = Account()
    config = account.get_config()
    assert 'enabled' in config
    assert 'name' in config
    assert 'mailbox_type' in config
Exemple #25
0
    def _on_cmb_account_type_changed(self, widget):
        acctype = widget.get_active()
        self._entry_account_password.set_icon_from_icon_name(
            Gtk.EntryIconPosition.SECONDARY, None)

        #
        # Reset everything when the account type changes
        #

        if acctype == IDX_POP3:
            self._label_account_name.set_visible(True)
            self._entry_account_name.set_visible(True)
            self._label_account_user.set_visible(True)
            self._entry_account_user.set_visible(True)
            self._label_account_password.set_visible(True)
            self._entry_account_password.set_visible(True)
            self._label_account_server.set_visible(True)
            self._entry_account_server.set_visible(True)
            self._label_account_port.set_visible(True)
            self._entry_account_port.set_visible(True)
            self._expander_folders.set_visible(False)
            self._chk_account_push.set_visible(False)
            self._chk_account_ssl.set_visible(True)
            self._label_account_file_path.set_visible(False)
            self._chooser_account_file_path.set_visible(False)
            self._label_account_directory_path.set_visible(False)
            self._chooser_account_directory_path.set_visible(False)
        elif acctype == IDX_IMAP:
            self._label_account_name.set_visible(True)
            self._entry_account_name.set_visible(True)
            self._label_account_user.set_visible(True)
            self._entry_account_user.set_visible(True)
            self._label_account_password.set_visible(True)
            self._entry_account_password.set_visible(True)
            self._label_account_server.set_visible(True)
            self._entry_account_server.set_visible(True)
            self._label_account_port.set_visible(True)
            self._entry_account_port.set_visible(True)
            self._expander_folders.set_visible(True)
            self._chk_account_push.set_visible(True)
            self._chk_account_ssl.set_visible(True)
            self._label_account_file_path.set_visible(False)
            self._chooser_account_file_path.set_visible(False)
            self._label_account_directory_path.set_visible(False)
            self._chooser_account_directory_path.set_visible(False)
        elif acctype == IDX_MBOX:
            self._label_account_name.set_visible(True)
            self._entry_account_name.set_visible(True)
            self._label_account_user.set_visible(False)
            self._entry_account_user.set_visible(False)
            self._label_account_password.set_visible(False)
            self._entry_account_password.set_visible(False)
            self._label_account_server.set_visible(False)
            self._entry_account_server.set_visible(False)
            self._label_account_port.set_visible(False)
            self._entry_account_port.set_visible(False)
            self._expander_folders.set_visible(False)
            self._chk_account_push.set_visible(False)
            self._chk_account_ssl.set_visible(False)
            self._label_account_file_path.set_visible(True)
            self._chooser_account_file_path.set_visible(True)
            self._label_account_directory_path.set_visible(False)
            self._chooser_account_directory_path.set_visible(False)
        elif acctype == IDX_MAILDIR:
            self._label_account_name.set_visible(True)
            self._entry_account_name.set_visible(True)
            self._label_account_user.set_visible(False)
            self._entry_account_user.set_visible(False)
            self._label_account_password.set_visible(False)
            self._entry_account_password.set_visible(False)
            self._label_account_server.set_visible(False)
            self._entry_account_server.set_visible(False)
            self._label_account_port.set_visible(False)
            self._entry_account_port.set_visible(False)
            self._expander_folders.set_visible(True)
            self._chk_account_push.set_visible(False)
            self._chk_account_ssl.set_visible(False)
            self._label_account_file_path.set_visible(False)
            self._chooser_account_file_path.set_visible(False)
            self._label_account_directory_path.set_visible(True)
            self._chooser_account_directory_path.set_visible(True)
        else:  # known provider (imap only)
            self._label_account_name.set_visible(False)
            self._entry_account_name.set_visible(False)
            self._label_account_user.set_visible(True)
            self._entry_account_user.set_visible(True)
            self._label_account_password.set_visible(True)
            self._entry_account_password.set_visible(True)
            self._label_account_server.set_visible(False)
            self._entry_account_server.set_visible(False)
            self._label_account_port.set_visible(False)
            self._entry_account_port.set_visible(False)
            self._expander_folders.set_visible(True)
            self._chk_account_push.set_visible(False)
            self._chk_account_ssl.set_visible(False)
            self._label_account_file_path.set_visible(False)
            self._chooser_account_file_path.set_visible(False)
            self._label_account_directory_path.set_visible(False)
            self._chooser_account_directory_path.set_visible(False)

            if acctype == IDX_GMAIL:
                self._entry_account_password.set_icon_from_icon_name(
                    Gtk.EntryIconPosition.SECONDARY, self._pwd_info_icon)

        self._folders_received = False
        self._selected_folder_count = 0

        self._expander_folders.set_expanded(False)
        self._liststore_folders.clear()

        empty_acc = Account()
        self._load_account(empty_acc)