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)
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
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()
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')
class MyUser (Mock): def is_authenticated(self): return True def subscription(self, feed, library): return None subscriber = Subscriber()