=== modified file 'bin/ubuntuone-preferences'
--- bin/ubuntuone-preferences	2010-02-17 02:19:29 +0000
+++ bin/ubuntuone-preferences	2010-02-17 04:05:23 +0000
@@ -26,6 +26,10 @@
 import gtk
 import os
 import gettext
+import gnomekeyring
+import httplib2
+import simplejson
+from oauth import oauth
 from ubuntuone import clientdefs
 
 import dbus.service
@@ -79,6 +83,8 @@
             self.dn_limit = 2097152
 
             self.__bus = dbus.SessionBus()
+            self.keyring = gnomekeyring
+            self.httpclient = httplib2.Http()
 
             try:
                   client = self.__bus.get_object(DBUS_IFACE_NAME, "/config",
@@ -198,7 +204,37 @@
                         'type' : real_type,
                         'percent' : percent })
             self.usage_graph.set_fraction(percent / 100)
-            
+
+      def request_quota_info(self):
+            """Request new quota info from server, and update display."""
+            consumer = oauth.OAuthConsumer("ubuntuone", "hammertime")
+            items = []
+            items = self.keyring.find_items_sync(
+                  gnomekeyring.ITEM_GENERIC_SECRET,
+                  {'ubuntuone-realm': "https://ubuntuone.com",
+                   'oauth-consumer-key': consumer.key})
+            token = oauth.OAuthToken.from_string(items[0].secret)
+            request = oauth.OAuthRequest.from_consumer_and_token(
+                  http_url='https://one.ubuntu.com/api/quota/',
+                  http_method='GET',
+                  oauth_consumer=consumer,
+                  token=token)
+            request.sign_request(oauth.OAuthSignatureMethod_HMAC_SHA1(),
+                                 consumer, token)
+            client = self.httpclient
+            headers = {}
+            headers.update(request.to_header())
+            resp, content = client.request(request.http_url,
+                                           request.http_method,
+                                           headers=headers)
+            if resp['status'] == '200':
+                  quota = simplejson.loads(content)
+                  self.update_quota_display(quota['used'], quota['total'])
+                  # FIXME: Log json parsing failures
+            else:
+                  # FIXME: Log errors
+                  return
+
       def __construct(self):
             """Construct the dialog's layout."""
             area = self.get_content_area()
@@ -324,6 +360,7 @@
             """Show our dialog, since we can do stuff now."""
             self.disconnect_signal_handlers()
             dialog = UbuntuOneDialog()
+            dialog.request_quota_info()
             dialog.show()
 
       def got_oautherror(self, message=None):
@@ -372,7 +409,7 @@
                                                DBUS_IFACE_AUTH_PATH,
                                                follow_name_owner_changes=True)
                   iface = dbus.Interface(client, DBUS_IFACE_AUTH_NAME)
-                  iface.login('https://one.ubuntu.com/', 'ubuntuone',
+                  iface.login('https://ubuntuone.com', 'ubuntuone',
                               reply_handler=dbus_async,
                               error_handler=self.got_dbus_error)
             except DBusException, e:
@@ -384,6 +421,7 @@
       gettext.textdomain(clientdefs.GETTEXT_PACKAGE)
 
       gtk.rc_parse_string(RCSTYLE)
+      gobject.set_application_name("Ubuntu One")
 
       try:
             login = UbuntuoneLoginHandler()

=== modified file 'tests/test_preferences.py'
--- tests/test_preferences.py	2010-02-17 02:19:29 +0000
+++ tests/test_preferences.py	2010-02-17 04:05:23 +0000
@@ -19,7 +19,9 @@
 
 import new
 import os
+import gnomekeyring
 
+from contrib.mocker import MockerTestCase, KWARGS
 from contrib.testing.testcase import DBusTwistedTestCase, FakeLogin
 from twisted.internet import defer
 from twisted.python.failure import Failure
@@ -29,7 +31,7 @@
     """Exception for when we get the wrong signal called."""
     pass
 
-class PreferencesTests(DBusTwistedTestCase):
+class PreferencesTests(MockerTestCase, DBusTwistedTestCase):
     """Basic tests for the ubuntuone-preferences app."""
 
     _path = os.path.join(os.getcwd(), "bin", "ubuntuone-preferences")
@@ -38,11 +40,39 @@
     u1prefs.DBUS_IFACE_AUTH_PATH = '/oauthdesktop'
 
     def setUp(self):
+        MockerTestCase.setUp(self)
         DBusTwistedTestCase.setUp(self)
         self.oauth = FakeLogin(self.bus)
         self._old_path = dbus_interface.DBUS_PATH_AUTH
         dbus_interface.DBUS_PATH_AUTH = '/oauthdesktop'
 
+        # For testing keyring queries
+        self.keyring = self.mocker.mock()
+        self.item = self.mocker.mock(gnomekeyring.Found)
+
+        self.item_id = 999
+
+        ex = self.expect(self.item.item_id)
+        ex.result(self.item_id)
+        ex.count(0, None)
+
+        ex = self.expect(self.item.secret)
+        ex.result('oauth_token=access_key&oauth_token_secret=access_secret')
+        ex.count(0, None)
+
+    def expect_token_query(self):
+        """Expects the keyring to be queried for a token."""
+        return self.expect(
+            self.keyring.find_items_sync(
+                gnomekeyring.ITEM_GENERIC_SECRET,
+                {'ubuntuone-realm': 'https://ubuntuone.com',
+                 'oauth-consumer-key': 'ubuntuone'})
+            )
+
+    def mock_has_token(self):
+        """Mocks a cached token in the keyring."""
+        self.expect_token_query().result([self.item])
+
     def tearDown(self):
         # collect all signal receivers registered during the test
         signal_receivers = set()
@@ -61,23 +91,46 @@
 
     def test_bw_throttling(self):
         """Test that toggling bw throttling works correctly."""
-
+        self.mocker.replay()
         dialog = self.u1prefs.UbuntuOneDialog()
         self.assertTrue(dialog is not None)
+        dialog.notebook.set_current_page(1)
         self.assertFalse(dialog.bw_table.get_property('sensitive'))
         dialog.limit_check.set_active(True)
         self.assertTrue(dialog.bw_table.get_property('sensitive'))
+        dialog.destroy()
 
     def test_quota_display(self):
         """Test that quota display works correctly."""
+        self.mocker.replay()
         dialog = self.u1prefs.UbuntuOneDialog()
         self.assertTrue(dialog is not None)
         self.assertEqual(dialog.usage_graph.get_fraction(), 0.0)
         dialog.update_quota_display(1024, 2048)
         self.assertEqual(dialog.usage_graph.get_fraction(), 0.5)
+        dialog.destroy()
+
+    def test_request_quota_info(self):
+        """Test that we can request the quota info properly."""
+        self.mock_has_token()
+        dialog = self.u1prefs.UbuntuOneDialog()
+        dialog.keyring = self.keyring
+        self.assertEqual(dialog.usage_graph.get_fraction(), 0.0)
+        self.assertTrue(dialog is not None)
+        response = { 'status' : '200' }
+        content = '{"total":2048, "used":1024}'
+        client = self.mocker.mock()
+        dialog.httpclient = client
+        self.expect(client.request('https://one.ubuntu.com/api/quota/',
+                                   'GET', KWARGS)).result((response, content))
+        self.mocker.replay()
+        dialog.request_quota_info()
+        self.assertEqual(dialog.usage_graph.get_fraction(), 0.5)
+        dialog.destroy()
 
     def test_login_check(self):
         """Test that our login check works correctly."""
+        self.mocker.replay()
         def got_new_creds(realm=None, consumer_key=None, sender=None):
             """ Override the callback """
             d.callback(True)

