~jonas-drange/ubuntu-system-settings/hotspots-change-test-backend

« back to all changes in this revision

Viewing changes to tests/autopilot/ubuntu_system_settings/tests/__init__.py

  • Committer: jonas-drange
  • Date: 2015-07-22 14:16:13 UTC
  • mfrom: (1312.3.74 tmp)
  • Revision ID: jonas.drange@canonical.com-20150722141613-4hz7rolyt8eei8ht
  Pete Woods 2015-07-16 Manage hotspots via connectity API

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from gi.repository import UPowerGlib
35
35
from testtools.matchers import Equals, NotEquals, GreaterThan
36
36
 
37
 
 
38
37
ACCOUNTS_IFACE = 'org.freedesktop.Accounts'
39
38
ACCOUNTS_USER_IFACE = 'org.freedesktop.Accounts.User'
40
39
ACCOUNTS_OBJ = '/org/freedesktop/Accounts'
392
391
        self.cellular_page = self.main_view.go_to_cellular_page()
393
392
 
394
393
 
 
394
class HotspotBaseTestCase(CellularBaseTestCase):
 
395
 
 
396
    @classmethod
 
397
    def setUpClass(cls):
 
398
        super(HotspotBaseTestCase, cls).setUpClass()
 
399
        nm_tmpl = os.path.join(os.path.dirname(__file__), 'networkmanager.py')
 
400
        (cls.n_mock, cls.obj_nm) = cls.spawn_server_template(
 
401
            nm_tmpl, stdout=subprocess.PIPE)
 
402
        (cls.u_mock, cls.obj_urf) = cls.spawn_server_template(
 
403
            'urfkill', stdout=subprocess.PIPE)
 
404
 
 
405
    @classmethod
 
406
    def tearDownClass(cls):
 
407
        cls.n_mock.terminate()
 
408
        cls.n_mock.wait()
 
409
        cls.u_mock.terminate()
 
410
        cls.u_mock.wait()
 
411
        super(HotspotBaseTestCase, cls).tearDownClass()
 
412
 
 
413
    def tearDown(self):
 
414
        self.obj_nm.Reset()
 
415
        self.urfkill_mock.ClearCalls()
 
416
        super(HotspotBaseTestCase, self).tearDown()
 
417
 
 
418
    def setUp(self):
 
419
        self.patch_environment("USS_SHOW_ALL_UI", "1")
 
420
        self.nm_mock = dbus.Interface(self.obj_nm, dbusmock.MOCK_IFACE)
 
421
        self.device_path = self.obj_nm.AddWiFiDevice('test0', 'Barbaz', 1)
 
422
        self.device_mock = dbus.Interface(self.dbus_con.get_object(
 
423
            NM_SERVICE, self.device_path),
 
424
            'org.freedesktop.DBus.Properties')
 
425
        self.urfkill_mock = dbus.Interface(self.obj_urf, dbusmock.MOCK_IFACE)
 
426
        super(HotspotBaseTestCase, self).setUp()
 
427
 
 
428
    def add_hotspot(self, name, password, secured=True, enabled=False):
 
429
        settings = {
 
430
            'connection': {
 
431
                'id': dbus.String('Test AP', variant_level=1),
 
432
                'type': dbus.String('802-11-wireless', variant_level=1), },
 
433
            '802-11-wireless': {
 
434
                'mode': dbus.String('ap', variant_level=1),
 
435
                'ssid': dbus.String(name, variant_level=1),
 
436
            }
 
437
        }
 
438
 
 
439
        if secured:
 
440
            settings['802-11-wireless']['security'] = dbus.String(
 
441
                '802-11-wireless-security', variant_level=1)
 
442
            settings['802-11-wireless-security'] = {
 
443
                'auth-alg': dbus.String('shared', variant_level=1),
 
444
                'key-mgmt': dbus.String('wpa-psk', variant_level=1),
 
445
                'psk': dbus.String(password, variant_level=1),
 
446
            }
 
447
 
 
448
        if enabled:
 
449
            settings['connection']['autoconnect'] = True
 
450
 
 
451
        connection_path = self.obj_nm.SettingsAddConnection(settings)
 
452
 
 
453
        return connection_path
 
454
 
 
455
 
395
456
class BluetoothBaseTestCase(UbuntuSystemSettingsTestCase):
396
457
 
397
458
    def setUp(self):