示例#1
0
    def has_isSubscribed_set_to_true_when_current_user_is_subscribed(self):
        from django.contrib.auth.models import User
        from subscriptions.models import Subscriber, Subscription
        from subscriptions.feeds import ContentFeedLibrary
        from main.feeds import NewLegislationFeed

        subscriber = Subscriber(username="******")
        subscriber.set_password("world")
        subscriber.save()

        library = ContentFeedLibrary()
        library.register(NewLegislationFeed, 'blah blah')

        feed = NewLegislationFeed()
        subscription = subscriber.subscribe(feed)
        subscriber.save()

        # Make the request.
        client = Client()
        assert client.login(username="******", password="******")
        response = client.get('/legislation/')

        # Check the context
        assert response.context['is_subscribed']
        assert_equal(response.context['subscription'], subscription)
示例#2
0
文件: handlers.py 项目: rik/basket
 def create(self, request):
     try:
         email = request.POST.get("email", "")
         s = Subscriber.objects.get(email=email)
     except Subscriber.DoesNotExist:
         try:
             s = Subscriber(email=email)
             s.full_clean()
             s.save()
         except ValidationError, e:
             resp = rc.BAD_REQUEST
             resp.write(encoding.smart_unicode(e.message_dict))
             return resp
示例#3
0
    def has_isSubscribed_set_to_true_when_current_user_is_subscribed(self):
        from django.contrib.auth.models import User
        from subscriptions.models import Subscriber, Subscription
        from subscriptions.feeds import ContentFeedLibrary
        from main.feeds import NewLegislationFeed

        subscriber = Subscriber(username="******")
        subscriber.set_password("world")
        subscriber.save()

        library = ContentFeedLibrary()
        library.register(NewLegislationFeed, 'blah blah')

        feed = NewLegislationFeed()
        subscription = subscriber.subscribe(feed)
        subscriber.save()

        # Make the request.
        client = Client()
        assert client.login(username="******", password="******")
        response = client.get('/legislation/')

        # Check the context
        assert response.context['is_subscribed']
        assert_equal(response.context['subscription'], subscription)
示例#4
0
    def setUp(self):
        Subscriber.objects.all().delete()
        ContentFeedRecord.objects.all().delete()
        ContentFeedParameter.objects.all().delete()
        Subscription.objects.all().delete()

        user = self.user = Subscriber(); user.save()
        record = self.record = ContentFeedRecord(); record.save()

        sub = self.sub = Subscription(subscriber=user, feed_record=record); sub.save()
示例#5
0
 def test_subscriber_model_string(self):
     test_user1 = User.objects.create_user(username='******',
                                           password='******')
     test_user1.save()
     subscriber = Subscriber(user=test_user1)
     self.assertEqual(str(subscriber), 'testuser')
示例#6
0
 class MyUser (Mock):
     def is_authenticated(self):
         return True
     def subscription(self, feed, library):
         return None
     subscriber = Subscriber()