Esempio n. 1
0
	def test_error_invalid_discussionid(self):
		#not integer
		with self.assertRaises(APIInvalidParameterException):
			api.unsubscribeFromThread(USER_ID, False, "text")
		#doesn't exist
		with self.assertRaises(ObjectDoesNotExist):
			api.unsubscribeFromThread(USER_ID, False, -1)
Esempio n. 2
0
	def test_error_invalid_userid(self):
		#not integer
		with self.assertRaises(APIInvalidParameterException):
			api.unsubscribeFromThread("text", True, SYNMARK_ID)
		#doesn't exist
		with self.assertRaises(ObjectDoesNotExist):
			api.unsubscribeFromThread(-1, True, SYNMARK_ID)
Esempio n. 3
0
	def test_error_invalid_synmarkid(self):
		#not integer
		with self.assertRaises(APIInvalidParameterException):
			api.unsubscribeFromThread(USER_ID, True, "text")
		#doesn't exist
		with self.assertRaises(SynoteObjectDoesNotExistException):
			api.unsubscribeFromThread(USER_ID, True, -1)
Esempio n. 4
0
	def test_error_not_subscribed(self):
		#unsubscribe
		userid = USER2_ID
		threadid = SYNMARK_ID
		flag = True
		
		with self.assertRaises(NotSubscribedException):
			api.unsubscribeFromThread(userid, flag, threadid)
Esempio n. 5
0
	def test_normal_discussion(self):
		#unsubscribe
		userid = USER_ID
		threadid = DISCUSSION_ID
		flag = False
		old_subscription = Discussion_Subscription.objects.get(discussion__id=threadid, subscription__user__id=userid)
		old_gen_subid = Subscription.objects.get(id = old_subscription.subscription.id).id
		
		api.unsubscribeFromThread(userid, flag, threadid)
		
		#make sure it unsubscribed
		subscriptions = Discussion_Subscription.objects.filter(subscription__user__id=userid, discussion__id=threadid)
		if(len(subscriptions) > 0):
			self.fail("User was not unsubscribed. Synmark_Subscription still exists.")
		gen_subs = Subscription.objects.filter(id=old_gen_subid)
		if(len(gen_subs) > 0):
			self.fail("User was not unsubscribed. (General) Subscription still exists.")
Esempio n. 6
0
	def test_normal_synmark(self):
		#unsubscribe
		userid = USER_ID
		threadid = SYNMARK_ID
		flag = True
		old_subscription = Synmark_Subscription.objects.get(synmark=threadid, subscription__user__id=userid)
		old_gen_subid = Subscription.objects.get(id = old_subscription.subscription.id).id
		
		api.unsubscribeFromThread(userid, flag, threadid)
		
		#make sure it unsubscribed
		subscriptions = Synmark_Subscription.objects.filter(subscription__user__id=userid, synmark=threadid)
		if(len(subscriptions) > 0):
			self.fail("User was not unsubscribed. Synmark_Subscription still exists.")
		gen_subs = Subscription.objects.filter(id=old_gen_subid)
		if(len(gen_subs) > 0):
			self.fail("User was not unsubscribed. (General) Subscription still exists.")
Esempio n. 7
0
def deleteComment(request):
    response = dict(content='')
    commentID = request.POST.get('commentID', '')
    unsubscribe = request.POST.get('unsubscribe', '')
    usr = request.user.id
    try:
	    comment = api.deleteComment(int(commentID), int(usr))
	    if unsubscribe:
	    	if api.isSynmarkComment(comment):
	    		api.unsubscribeFromThread(usr, True, api.getSynmarkComment(comment).synmark)
	    	else:
				api.unsubscribeFromThread(usr, False, api.getDiscussionComment(comment).discussion.id)
	    response['content'] = render_to_string('comment.html', {'user': request.user, 'comment': comment})
    except APIException as e:
    	response['error'] = "There was a problem with your request. Please try again."
    	api.log_error("APIException thrown ("+str(type(e))+"): "+e.value)
    serialised = simplejson.dumps(response)
    return HttpResponse(serialised, mimetype='application/json')
Esempio n. 8
0
def unsubscribeFromThread(request):
    response = dict()
    usr = request.user.id
    flag = request.POST.get('flag', '')    
    thread = request.POST.get('thread', '')
    print 'flag '+flag+' thread '+thread
    if flag == "1":
    	flag = True
    else:
    	flag = False
    try:
    	api.unsubscribeFromThread(int(usr), bool(flag), int(thread))
    except NotSubscribedException:
    	response['error'] = "You are not yet subscribed to this Synmark"
    except APIException as e:
    	response['error'] = "There was a problem with your request. Please try again."
    	api.log_error("APIException thrown ("+str(type(e))+"): "+e.value)
    serialised = simplejson.dumps(response)
    return HttpResponse(serialised, mimetype='application/json')
Esempio n. 9
0
	def test_error_invalid_flag(self):
		#not bool
		with self.assertRaises(APIInvalidParameterException):
			api.unsubscribeFromThread(USER_ID, "text", DISCUSSION_ID)