~super-friends/friends/trunk-next

« back to all changes in this revision

Viewing changes to friends/tests/test_dispatcher.py

  • Committer: Robert Bruce Park
  • Date: 2013-03-29 00:52:39 UTC
  • Revision ID: robert.park@canonical.com-20130329005239-q0wm2szbo8p6gi45
Simplify URL shortening code *even further*.

I was looking at the lookup() method, when I realized that it was
really a constructor in disguise. So I set out to make it a
@classmethod on Shortener. But then I realized that not only was it a
constructor, it was *THE* constructor. Like, the only one that anybody
would ever care about. So I rewrote Shortener.__init__ to do what
lookup() was doing, and in the process I made NullShortener subclass
irrelevant, so I removed that.

Show diffs side-by-side

added added

removed removed

Lines of Context:
208
208
            self.dispatcher.URLShorten('http://tinyurl.com/foo'))
209
209
 
210
210
    @mock.patch('friends.service.dispatcher.logging')
211
 
    @mock.patch('friends.service.dispatcher.lookup')
212
 
    @mock.patch('friends.service.dispatcher.is_shortened')
213
 
    def test_urlshorten(self, short_mock, lookup_mock, logging_mock):
214
 
        short_mock.return_value = False
 
211
    @mock.patch('friends.service.dispatcher.Shortener')
 
212
    def test_urlshorten(self, lookup_mock, logging_mock):
215
213
        lookup_mock().shorten.return_value = 'short url'
216
214
        lookup_mock.reset_mock()
217
215
        self.dispatcher.settings.get_string.return_value = 'is.gd'
219
217
        self.assertEqual(
220
218
            self.dispatcher.URLShorten(long_url),
221
219
            'short url')
222
 
        short_mock.assert_called_once_with(long_url)
223
220
        self.dispatcher.settings.get_boolean.assert_called_once_with(
224
221
            'shorten-urls')
225
222
        lookup_mock.assert_called_once_with('is.gd')