Commits

Peter Sanchez committed f62e7ff

Updated models.py to change the way SubscriptionManager.do_action
saved the verification process.

It was redundant because the callback view will update the
Subscription.verified as well as trigger the verified signal
in case of a sync subscription.

Updated tests to reflect that.

  • Participants
  • Parent commits 5dbd7eb

Comments (0)

Files changed (2)

File djpubsubhubbub/models.py

         if debug:
             print 'Info:\n%s\n\n' % str(info)
 
-        if info.status == 204:
-            subscription.verified = True
-        elif info.status == 202: # async verification
-            subscription.verified = False
-        else:
+        if info.status not in [204, 202]:
+            # 204 is sync verification
+            # 202 is async verification
             error = response.read()
             raise urllib2.URLError(
                 'error with mode "%s" to %s on %s:\n%s' % \
                                             (mode, topic, hub, error)
             )
 
-        subscription.save()
-        if subscription.verified:
-            signals.verified.send(sender=subscription)
         return subscription
     
     def subscribe(self, topic, **kwargs):

File djpubsubhubbub/tests.py

 class MockResponse(object):
     def __init__(self, status, data=None):
         self.status = status
+        self.code = status
         self.data = data
 
     def info(self):
         for signal in pre_subscribe, verified:
             signal.disconnect(dispatch_uid=signal)
 
-    def _send_request(self, url, data, headers={}):
+    def _send_request(self, url, data, headers={}, debug=False):
         self.requests.append((url, data, headers))
         return self.responses.pop()
 
         """
         self.responses.append(MockResponse(204))
         sub = Subscription.objects.do_action('topic', 'hub', 'callback', 2000)
-        self.assertEquals(len(self.signals), 2)
+        self.assertEquals(len(self.signals), 1)
         self.assertEquals(self.signals[0], (pre_subscribe, {'sender': sub,
                                                             'created': True}))
-        self.assertEquals(self.signals[1], (verified, {'sender': sub}))
         self.assertEquals(sub.hub, 'hub')
         self.assertEquals(sub.topic, 'topic')
-        self.assertEquals(sub.verified, True)
+        self.assertEquals(sub.verified, False)
+        self.assertEquals(sub.is_subscribed, False)
         rough_expires = datetime.now() + timedelta(seconds=2000)
         self.assert_(abs(sub.lease_expires - rough_expires).seconds < 5,
                      'lease more than 5 seconds off')
         self.assertEquals(request[1]['mode'], 'subscribe')
         self.assertEquals(request[1]['topic'], 'topic')
         self.assertEquals(request[1]['callback'], 'callback')
-        self.assertEquals(request[1]['verify'], ('async', 'sync'))
+        self.assertEquals(request[1]['verify'], 'sync')
         self.assertEquals(request[1]['verify_token'], sub.verify_token)
         self.assertEquals(request[1]['lease_seconds'], 2000)
 
         subscription is verified.
         """
         self.responses.append(MockResponse(202))
-        sub = Subscription.objects.do_action('topic', 'hub', 'callback', 2000)
+        sub = Subscription.objects.do_action(
+            'topic',
+            'hub',
+            'callback',
+            2000,
+            verify='async',
+        )
         self.assertEquals(len(self.signals), 1)
         self.assertEquals(self.signals[0], (pre_subscribe, {'sender': sub,
                                                             'created': True}))
         self.assertEquals(sub.hub, 'hub')
         self.assertEquals(sub.topic, 'topic')
         self.assertEquals(sub.verified, False)
+        self.assertEquals(sub.is_subscribed, False)
         rough_expires = datetime.now() + timedelta(seconds=2000)
         self.assert_(abs(sub.lease_expires - rough_expires).seconds < 5,
                      'lease more than 5 seconds off')
         self.assertEquals(request[1]['mode'], 'subscribe')
         self.assertEquals(request[1]['topic'], 'topic')
         self.assertEquals(request[1]['callback'], 'callback')
-        self.assertEquals(request[1]['verify'], ('async', 'sync'))
+        self.assertEquals(request[1]['verify'], 'async')
         self.assertEquals(request[1]['verify_token'], sub.verify_token)
         self.assertEquals(request[1]['lease_seconds'], 2000)
 
         self.assertEquals(response.content, 'challenge')
         sub = Subscription.objects.get(pk=sub.pk)
         self.assertEquals(sub.verified, True)
+        self.assertEquals(sub.is_subscribed, True)
         self.assertEquals(len(self.signals), 1)
         self.assertEquals(self.signals[0], (verified, {'sender': sub}))