Example #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)
Example #2
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)
Example #3
0
 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