<s> from django . core . urlresolvers import resolve <EOL> from django . http import HttpRequest <EOL> from django . http import QueryDict <EOL> from django . test import TestCase <EOL> from django . test import Client <EOL> from django . contrib . auth . models import User <EOL> from django . contrib . auth import authenticate , login , logout <EOL> from django . contrib . auth . decorators import login_required <EOL> from django . conf . urls . static import static , settings <EOL> import json <EOL> from registrar . models import Course <EOL> from registrar . models import Teacher <EOL> from registrar . models import Student <EOL> from registrar . models import Assignment <EOL> from registrar . models import AssignmentSubmission <EOL> from registrar . models import EssayQuestion <EOL> from registrar . models import EssaySubmission <EOL> from registrar . models import MultipleChoiceQuestion <EOL> from registrar . models import MultipleChoiceSubmission <EOL> from registrar . models import ResponseQuestion <EOL> from registrar . models import ResponseSubmission <EOL> from registrar . models import TrueFalseQuestion <EOL> from registrar . models import TrueFalseSubmission <EOL> from registrar . models import PeerReview <EOL> from student . views import peer_review <EOL> TEST_USER_EMAIL = "<STR_LIT>" <EOL> TEST_USER_USERNAME = "<STR_LIT>" <EOL> TEST_USER_PASSWORD = "<STR_LIT>" <EOL> TEST_USER_EMAIL2 = "<STR_LIT>" <EOL> TEST_USER_USERNAME2 = "<STR_LIT>" <EOL> TEST_USER_PASSWORD2 = "<STR_LIT>" <EOL> class PeerReviewTestCase ( TestCase ) : <EOL> def tearDown ( self ) : <EOL> essays = EssaySubmission . objects . all ( ) <EOL> for essay in essays : <EOL> essay . delete ( ) <EOL> reviews = PeerReview . objects . all ( ) <EOL> for review in reviews : <EOL> reviews . delete ( ) <EOL> courses = Course . objects . all ( ) <EOL> for course in courses : <EOL> course . delete ( ) <EOL> User . objects . get ( email = TEST_USER_EMAIL ) . delete ( ) <EOL> User . objects . all ( ) . delete ( ) <EOL> Course . objects . all ( ) . delete ( ) <EOL> def setUp ( self ) : <EOL> User . objects . create_user ( <EOL> email = TEST_USER_EMAIL2 , <EOL> username = TEST_USER_USERNAME2 , <EOL> password = TEST_USER_PASSWORD2 <EOL> ) <EOL> user = User . objects . get ( email = TEST_USER_EMAIL2 ) <EOL> teacher = Teacher . objects . create ( user = user ) <EOL> Student . objects . create ( user = user ) . save ( ) <EOL> User . objects . create_user ( <EOL> email = TEST_USER_EMAIL , <EOL> username = TEST_USER_USERNAME , <EOL> password = TEST_USER_PASSWORD <EOL> ) <EOL> user = User . objects . get ( email = TEST_USER_EMAIL ) <EOL> teacher = Teacher . objects . create ( user = user ) <EOL> student = Student . objects . create ( user = user ) <EOL> Course . objects . create ( <EOL> id = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> sub_title = "<STR_LIT>" , <EOL> category = "<STR_LIT>" , <EOL> teacher = teacher , <EOL> ) . save ( ) <EOL> course = Course . objects . get ( id = <NUM_LIT:1> ) <EOL> Assignment . objects . create ( <EOL> assignment_id = <NUM_LIT:1> , <EOL> assignment_num = <NUM_LIT:1> , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> worth = <NUM_LIT> , <EOL> course = course , <EOL> ) <EOL> assignment = Assignment . objects . get ( assignment_id = <NUM_LIT:1> ) <EOL> EssayQuestion . objects . create ( <EOL> question_id = <NUM_LIT:1> , <EOL> assignment = assignment , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> ) <EOL> e_question = EssayQuestion . objects . get ( question_id = <NUM_LIT:1> ) <EOL> ResponseQuestion . objects . create ( <EOL> question_id = <NUM_LIT:4> , <EOL> assignment = assignment , <EOL> title = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> answer = "<STR_LIT>" , <EOL> ) <EOL> r_question = ResponseQuestion . objects . get ( question_id = <NUM_LIT:4> ) <EOL> AssignmentSubmission . objects . create ( <EOL> submission_id = <NUM_LIT:1> , <EOL> student = student , <EOL> assignment = assignment , <EOL> ) <EOL> submission = AssignmentSubmission . objects . get ( assignment_id = <NUM_LIT:1> ) <EOL> EssaySubmission . objects . create ( <EOL> student = student , <EOL> question = e_question , <EOL> ) <EOL> ResponseSubmission . objects . create ( <EOL> student = student , <EOL> question = r_question , <EOL> ) <EOL> def get_logged_in_client ( self ) : <EOL> client = Client ( ) <EOL> client . login ( <EOL> username = TEST_USER_USERNAME , <EOL> password = TEST_USER_PASSWORD <EOL> ) <EOL> return client <EOL> def test_url_resolves_to_peer_review_page_view ( self ) : <EOL> found = resolve ( '<STR_LIT>' ) <EOL> self . assertEqual ( found . func , peer_review . peer_reviews_page ) <EOL> def test_peer_reviews_page ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> response = client . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> def test_url_resolves_to_assignment_page_view ( self ) : <EOL> found = resolve ( '<STR_LIT>' ) <EOL> self . assertEqual ( found . func , peer_review . assignment_page ) <EOL> def test_assignment_page ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> response = client . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> def test_peer_review_modal_on_essay_question ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : settings . ESSAY_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , ** kwargs ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> def test_peer_review_modal_on_response_question ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : settings . RESPONSE_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> } , ** kwargs ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> def test_save_peer_review_on_essay_question ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : settings . ESSAY_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , ** kwargs ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT:success>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> def test_save_peer_review_on_response_question ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : settings . RESPONSE_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , ** kwargs ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT:success>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> def test_delete_peer_review_on_empty ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : settings . ESSAY_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , ** kwargs ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> def test_delete_peer_review_on_essay_question ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : settings . ESSAY_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , ** kwargs ) <EOL> reviews = PeerReview . objects . all ( ) <EOL> review_id = reviews [ <NUM_LIT:0> ] . review_id <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : settings . ESSAY_QUESTION_TYPE , <EOL> '<STR_LIT>' : review_id , <EOL> } , ** kwargs ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT:success>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> def test_delete_peer_review_on_response_question ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : settings . RESPONSE_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , ** kwargs ) <EOL> reviews = PeerReview . objects . all ( ) <EOL> review_id = reviews [ <NUM_LIT:0> ] . review_id <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : settings . RESPONSE_QUESTION_TYPE , <EOL> '<STR_LIT>' : review_id , <EOL> } , ** kwargs ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT:success>' ) <EOL> def test_delete_peer_review_on_incorrect_user ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : settings . RESPONSE_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , ** kwargs ) <EOL> reviews = PeerReview . objects . all ( ) <EOL> review_id = reviews [ <NUM_LIT:0> ] . review_id <EOL> client . logout ( ) <EOL> client . login ( <EOL> username = TEST_USER_USERNAME2 , <EOL> password = TEST_USER_PASSWORD2 <EOL> ) <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : settings . RESPONSE_QUESTION_TYPE , <EOL> '<STR_LIT>' : review_id , <EOL> } , ** kwargs ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT>' ) <EOL> def test_update_peer_review_on_essay_question ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : settings . ESSAY_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , ** kwargs ) <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : settings . ESSAY_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT:3> , <EOL> } , ** kwargs ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT:success>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> def test_update_peer_review_on_response_question ( self ) : <EOL> client = self . get_logged_in_client ( ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : settings . RESPONSE_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> '<STR_LIT>' : <NUM_LIT:5> , <EOL> } , ** kwargs ) <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:4> , <EOL> '<STR_LIT>' : settings . RESPONSE_QUESTION_TYPE , <EOL> '<STR_LIT>' : <NUM_LIT:2> , <EOL> } , ** kwargs ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT:success>' ) </s>
