@pytest.mark.django_db
def test_reject_suggestion_with_comment(client, request_users):
 Comment = get_comment_model()
 unit = Unit.objects.filter(suggestion__state='pending', state=UNTRANSLATED)[0]
 sugg = Suggestion.objects.filter(unit=unit, state='pending')[0]
 comment = 'This is a comment!'
 user = request_users['user']
 if (user.username != 'nobody'):
  client.login(username=user.username, password=request_users['password'])
 url = ('/xhr/units/%d/suggestions/%d/' % (unit.id, sugg.id))
 response = client.delete(url, ('comment=%s' % comment), HTTP_X_REQUESTED_WITH='XMLHttpRequest')
 can_reject = (check_permission('review', response.wsgi_request) or (sugg.user.id == user.id))
 if can_reject:
  assert (response.status_code == 200)
  rejected_suggestion = Suggestion.objects.get(id=sugg.id)
  assert (rejected_suggestion.state == 'rejected')
  assert (Comment.objects.for_model(rejected_suggestion).get().comment == comment)
 else:
  assert (response.status_code == 403)

@ pytest . mark . django_db def test_reject_suggestion_with_comment ( client , request_users ) : Comment = get_comment_model ( ) unit = Unit . objects . filter ( suggestion__state = 'pending' , state = UNTRANSLATED ) [ 0 ] sugg = Suggestion . objects . filter ( unit = unit , state = 'pending' ) [ 0 ] comment = 'This is a comment!' user = request_users [ 'user' ] if ( user . username != 'nobody' ) : client . login ( username = user . username , password = request_users [ 'password' ] ) url = ( '/xhr/units/%d/suggestions/%d/' % ( unit . id , sugg . id ) ) response = client . delete ( url , ( 'comment=%s' % comment ) , HTTP_X_REQUESTED_WITH = 'XMLHttpRequest' ) can_reject = ( check_permission ( 'review' , response . wsgi_request ) or ( sugg . user . id == user . id ) ) if can_reject : assert ( response . status_code == 200 ) rejected_suggestion = Suggestion . objects . get ( id = sugg . id ) assert ( rejected_suggestion . state == 'rejected' ) assert ( Comment . objects . for_model ( rejected_suggestion ) . get ( ) . comment == comment ) else : assert ( response . status_code == 403 )
tests suggestion can be rejected with a comment .