~nataliabidart/ubuntuone-control-panel/raise-and-handle-unauthorized

« back to all changes in this revision

Viewing changes to ubuntuone/controlpanel/tests/test_backend.py

  • Committer: Tarmac
  • Author(s): Natalia B. Bidart
  • Date: 2011-03-31 21:46:31 UTC
  • mfrom: (119.2.5 device-list-type-error)
  • Revision ID: tarmac-20110331214631-lzjmngucl3im9vk2
- Made the backend robust against possible None values (or any non basestring instance) sent from the API server (LP: #745790).

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
from ubuntuone.controlpanel import backend, replication_client
31
31
from ubuntuone.controlpanel.backend import (bool_str,
32
32
    ACCOUNT_API, DEVICES_API, DEVICE_REMOVE_API, QUOTA_API,
 
33
    DEVICE_TYPE_COMPUTER,
33
34
    FILE_SYNC_DISABLED,
34
35
    FILE_SYNC_DISCONNECTED,
35
36
    FILE_SYNC_ERROR,
41
42
    MSG_KEY, STATUS_KEY,
42
43
)
43
44
from ubuntuone.controlpanel.tests import (TestCase,
 
45
    EMPTY_DESCRIPTION_JSON,
44
46
    EXPECTED_ACCOUNT_INFO,
45
47
    EXPECTED_ACCOUNT_INFO_WITH_CURRENT_PLAN,
46
48
    EXPECTED_DEVICES_INFO,
251
253
        self.patch(backend, "WebClient", MockWebClient)
252
254
        self.patch(backend, "dbus_client", MockDBusClient())
253
255
        self.patch(backend, "replication_client", MockReplicationClient())
254
 
        self.local_token = "Computer" + TOKEN["token"]
 
256
        self.local_token = DEVICE_TYPE_COMPUTER + TOKEN["token"]
255
257
        self.be = backend.ControlBackend()
256
258
 
257
259
        self.memento = MementoHandler()
380
382
        self.assertEqual(result, expected)
381
383
 
382
384
    @inlineCallbacks
 
385
    def test_devices_info_when_token_name_is_empty(self):
 
386
        """The devices_info can handle empty token names."""
 
387
        # pylint: disable=E1101
 
388
        self.be.wc.results[DEVICES_API] = EMPTY_DESCRIPTION_JSON
 
389
        result = yield self.be.devices_info()
 
390
        expected = {'configurable': '',
 
391
                    'device_id': 'ComputerABCDEF01234token',
 
392
                    'is_local': '', 'name': 'None',
 
393
                    'type': DEVICE_TYPE_COMPUTER}
 
394
        self.assertEqual(result, [expected])
 
395
        self.assertTrue(self.memento.check_warning('name', 'None'))
 
396
 
 
397
    @inlineCallbacks
 
398
    def test_devices_info_does_not_log_device_id(self):
 
399
        """The devices_info does not log the device_id."""
 
400
        # pylint: disable=E1101
 
401
        self.be.wc.results[DEVICES_API] = SAMPLE_DEVICES_JSON
 
402
        yield self.be.devices_info()
 
403
 
 
404
        dids = (d['device_id'] for d in EXPECTED_DEVICES_INFO)
 
405
        device_id_logged = all(all(did not in r.getMessage()
 
406
                                   for r in self.memento.records)
 
407
                               for did in dids)
 
408
        self.assertTrue(device_id_logged)
 
409
 
 
410
    @inlineCallbacks
383
411
    def test_remove_device(self):
384
412
        """The remove_device method calls the right api."""
385
 
        dtype, did = "Computer", "SAMPLE-TOKEN"
 
413
        dtype, did = DEVICE_TYPE_COMPUTER, "SAMPLE-TOKEN"
386
414
        device_id = dtype + did
387
415
        apiurl = DEVICE_REMOVE_API % (dtype.lower(), did)
388
416
        # pylint: disable=E1101
411
439
                                 WebClientError)
412
440
 
413
441
    @inlineCallbacks
 
442
    def test_remove_device_does_not_log_device_id(self):
 
443
        """The remove_device does not log the device_id."""
 
444
        device_id = DEVICE_TYPE_COMPUTER + TOKEN['token']
 
445
        yield self.be.remove_device(device_id)
 
446
 
 
447
        device_id_logged = all(device_id not in r.getMessage()
 
448
                               for r in self.memento.records)
 
449
        self.assertTrue(device_id_logged)
 
450
 
 
451
    @inlineCallbacks
414
452
    def test_change_show_all_notifications(self):
415
453
        """The device settings are updated."""
416
454
        backend.dbus_client.show_all_notifications = False
465
503
        self.assertEqual(backend.dbus_client.limits["upload"], -1)
466
504
        self.assertEqual(backend.dbus_client.limits["download"], -1)
467
505
 
 
506
    @inlineCallbacks
 
507
    def test_changing_settings_does_not_log_device_id(self):
 
508
        """The change_device_settings does not log the device_id."""
 
509
        device_id = 'yadda-yadda'
 
510
        yield self.be.change_device_settings(device_id, {})
 
511
 
 
512
        device_id_logged = all(device_id not in r.getMessage()
 
513
                               for r in self.memento.records)
 
514
        self.assertTrue(device_id_logged)
 
515
 
468
516
 
469
517
class BackendVolumesTestCase(BackendBasicTestCase):
470
518
    """Volumes tests for the backend."""