Example #1
0
def subscribe(request):
    if request.method == "POST":
        params =  request.POST
    else:
        params =  request.GET
    teller_username = params['tellerUsername']
    subscriber_email = params['subscriberEmail']    
    try:
        subscriberfacade.subscribe(teller = teller_username, subscriber = subscriber_email)
        return HttpResponse(simplejson.dumps({ "success": True }));
    except Exception as e:
        return HttpResponse(simplejson.dumps({"success": False, "errormsg": e}))
Example #2
0
    def test_subscribe_existings_user_by_username(self):
        existing_user = User.objects.all()[0]
        self.assertNotEqual(None, existing_user, "Existing user %s not found, can'\t perform the test!"%SUBSCRIBER_EMAIL)
        
        subscriberfacade.subscribe(self.teller.username, existing_user.email)
        user_list = User.objects.filter(username = existing_user.username)
#        print len(user_list)
        self.assertEqual(1, len(user_list), "There is a new user with %s email created after subscribing existing user to teller %s"%(existing_user.email, self.teller.username))
        
        subscriptions = existing_user.joke_tellers.filter(teller__username = self.teller.username)
        self.assertNotEqual(0, len(subscriptions), "New user not assigned to test teller!")
        found = False
        
        for subsc in subscriptions:
            if subsc.teller.username == self.teller.username:
                found = True
                
        self.assertTrue(found, "Subscribed Teller %s not found in user %s subscribtions"%(self.teller.username, existing_user.username))
Example #3
0
 def test_subscribe_new_user_by_username(self): #ie string usernames not objects
     user_list = User.objects.filter(email = SUBSCRIBER_EMAIL)
     self.assertEqual(0, len(user_list), "Can\'t test, user %s already exists!"%SUBSCRIBER_EMAIL)
     subscriberfacade.subscribe(self.teller.username, SUBSCRIBER_EMAIL)
     
     
     #check if there is a new user 
     new_user = User.objects.get(email = SUBSCRIBER_EMAIL)
     self.assertEqual(new_user.username, SUBSCRIBER_EMAIL)
     subscriptions = new_user.joke_tellers.filter(teller__username = self.teller.username)
     self.assertNotEqual(0, len(subscriptions), "New user not assigned to test teller!")
     
     #check if test teller has new subscriber
     listener_list = Subscriber.objects.filter(teller = self.teller)
     listener_found = False
     for listener in listener_list:
         if listener.listener.username == SUBSCRIBER_EMAIL:
             listener_found = True
             
     self.assertTrue(listener_found, "New subscriber was not found in %s list"%self.teller.username)