~ubuntuone-control-tower/ubuntu-sso-client/trunk

« back to all changes in this revision

Viewing changes to ubuntu_sso/utils/tests/test_common.py

  • Committer: Tarmac
  • Author(s): Rodney Dawes, Natalia Bidart
  • Date: 2014-08-14 14:20:29 UTC
  • mfrom: (1035.3.5 no-more-ping)
  • Revision ID: tarmac-20140814142029-phtfnx288m2ddxes
Remove the ping URL usage.
Update the Terms and Privacy URLs to point to login.ubuntu.com.
Update timestamp checking URL to point to login.ubuntu.com.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
from ubuntuone.devtools.testing.txwebserver import HTTPWebServer
41
41
 
42
42
from ubuntu_sso import utils
43
 
from ubuntu_sso.tests import TestCase, EMAIL, TOKEN
 
43
from ubuntu_sso.tests import TestCase
44
44
 
45
45
CONSTANTS_MODULE = 'ubuntu_sso.constants'
46
46
NOT_DEFINED = object()
238
238
        # pylint: disable=E1101
239
239
        root = RootResource()
240
240
        super(MockWebServer, self).__init__(root)
241
 
 
242
 
 
243
 
class FakedError(Exception):
244
 
    """A mock, test, sample, and fake exception."""
245
 
 
246
 
 
247
 
class PingUrlTestCase(TestCase):
248
 
    """Test suite for the URL pinging."""
249
 
 
250
 
    @defer.inlineCallbacks
251
 
    def setUp(self):
252
 
        yield super(PingUrlTestCase, self).setUp()
253
 
        self.url = 'http://example.com/'
254
 
        self.wc = FakeWebclient()
255
 
        self.patch(utils.webclient, "webclient_factory",
256
 
                   lambda *args: self.wc)
257
 
 
258
 
    @defer.inlineCallbacks
259
 
    def test_ping_url(self):
260
 
        """The url is opened."""
261
 
        yield utils.ping_url(url=self.url, email=EMAIL, credentials=TOKEN)
262
 
 
263
 
        args, _kwargs = self.wc.called[0]
264
 
        self.assertEqual(args[0], self.url + EMAIL)
265
 
 
266
 
    @defer.inlineCallbacks
267
 
    def test_ping_url_result(self):
268
 
        """The result is returned."""
269
 
        result = yield utils.ping_url(url=self.url, email=EMAIL,
270
 
                                      credentials=TOKEN)
271
 
        self.assertEqual(result.content, 'response')
272
 
 
273
 
    @defer.inlineCallbacks
274
 
    def test_request_is_signed_with_credentials(self):
275
 
        """The http request to url is signed with the credentials."""
276
 
        yield utils.ping_url(url=self.url, email=EMAIL, credentials=TOKEN)
277
 
 
278
 
        _args, kwargs = self.wc.called[0]
279
 
        self.assertEqual(kwargs["oauth_credentials"], TOKEN)
280
 
 
281
 
    @defer.inlineCallbacks
282
 
    def test_ping_url_formatting(self):
283
 
        """The email is added as the first formatting argument."""
284
 
        self.url = 'http://example.com/{email}/something/else'
285
 
        yield utils.ping_url(url=self.url, email=EMAIL, credentials=TOKEN)
286
 
 
287
 
        expected = self.url.format(email=EMAIL)
288
 
        assert len(self.wc.called) > 0
289
 
        args, _kwargs = self.wc.called[0]
290
 
        self.assertEqual(expected, args[0])
291
 
 
292
 
    @defer.inlineCallbacks
293
 
    def test_ping_url_formatting_with_query_params(self):
294
 
        """The email is added as the first formatting argument."""
295
 
        self.url = 'http://example.com/{email}?something=else'
296
 
        yield utils.ping_url(url=self.url, email=EMAIL, credentials=TOKEN)
297
 
 
298
 
        expected = self.url.format(email=EMAIL)
299
 
        assert len(self.wc.called) > 0
300
 
        args, _kwargs = self.wc.called[0]
301
 
        self.assertEqual(expected, args[0])
302
 
 
303
 
    @defer.inlineCallbacks
304
 
    def test_ping_url_formatting_no_email_kwarg(self):
305
 
        """The email is added as the first formatting argument."""
306
 
        self.url = 'http://example.com/{0}/yadda/?something=else'
307
 
        yield utils.ping_url(url=self.url, email=EMAIL, credentials=TOKEN)
308
 
 
309
 
        expected = self.url.format(EMAIL)
310
 
        assert len(self.wc.called) > 0
311
 
        args, _kwargs = self.wc.called[0]
312
 
        self.assertEqual(expected, args[0])
313
 
 
314
 
    @defer.inlineCallbacks
315
 
    def test_ping_url_formatting_no_format(self):
316
 
        """The email is appended if formatting could not be accomplished."""
317
 
        self.url = 'http://example.com/yadda/'
318
 
        yield utils.ping_url(url=self.url, email=EMAIL, credentials=TOKEN)
319
 
 
320
 
        expected = self.url + EMAIL
321
 
        assert len(self.wc.called) > 0
322
 
        args, _kwargs = self.wc.called[0]
323
 
        self.assertEqual(expected, args[0])