Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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()
Exemplo n.º 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)
Exemplo n.º 12
0
	def __init__(self, **kw):
		Account.__init__(self, **kw)
		self._backend = FakeBackend()
Exemplo n.º 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'
Exemplo n.º 14
0
def test_type_should_be_empty_by_default():
    account = Account()
    config = account.get_config()
    assert account.mailbox_type == ''
    assert config['mailbox_type'] == ''
Exemplo n.º 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()
Exemplo n.º 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
Exemplo n.º 17
0
def test_type_should_be_empty_by_default():
	account = Account()
	config = account.get_config()
	assert account.mailbox_type == ''
	assert config['mailbox_type'] == ''
Exemplo n.º 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'
Exemplo n.º 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"
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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()
Exemplo n.º 23
0
 def __init__(self, **kw):
     Account.__init__(self, **kw)
     self._backend = FakeBackend()
Exemplo n.º 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
Exemplo n.º 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)