<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> 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 CourseFinalMark <EOL> from registrar . views import enrollment <EOL> TEST_USER_EMAIL = "<STR_LIT>" <EOL> TEST_USER_USERNAME = "<STR_LIT>" <EOL> TEST_USER_PASSWORD = "<STR_LIT:password>" <EOL> class EnrollmentTestCase ( TestCase ) : <EOL> def tearDown ( self ) : <EOL> courses = Course . objects . all ( ) <EOL> for course in courses : <EOL> course . delete ( ) <EOL> User . objects . get ( email = TEST_USER_EMAIL ) . delete ( ) <EOL> def setUp ( self ) : <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 = 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> ) <EOL> CourseFinalMark . objects . create ( <EOL> credit_id = <NUM_LIT:1> , <EOL> percent = <NUM_LIT> , <EOL> is_public = True , <EOL> course = course , <EOL> student = student , <EOL> ) <EOL> def test_url_resolves_to_enrollment_page_view ( self ) : <EOL> found = resolve ( '<STR_LIT>' ) <EOL> self . assertEqual ( found . func , enrollment . enrollment_page ) <EOL> def test_enrollment_page_with_no_enrollments ( self ) : <EOL> client = Client ( ) <EOL> client . login ( <EOL> username = TEST_USER_USERNAME , <EOL> password = TEST_USER_PASSWORD <EOL> ) <EOL> response = client . post ( '<STR_LIT>' ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertIn ( b'<STR_LIT>' , response . content ) <EOL> def test_enrollment_page_with_enrollments ( self ) : <EOL> user = User . objects . get ( email = TEST_USER_EMAIL ) <EOL> student = Student . objects . get ( user = user ) <EOL> course = Course . objects . get ( id = <NUM_LIT:1> ) <EOL> course . students . add ( student ) <EOL> course . save ( ) <EOL> client = Client ( ) <EOL> client . login ( <EOL> username = TEST_USER_USERNAME , <EOL> password = TEST_USER_PASSWORD <EOL> ) <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> def test_url_resolves_to_disenroll_modal_view ( self ) : <EOL> found = resolve ( '<STR_LIT>' ) <EOL> self . assertEqual ( found . func , enrollment . disenroll_modal ) <EOL> def test_disenroll_modal_returns_correct_html ( self ) : <EOL> client = Client ( ) <EOL> client . login ( <EOL> username = TEST_USER_USERNAME , <EOL> password = TEST_USER_PASSWORD <EOL> ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> response = client . post ( '<STR_LIT>' , { <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_url_resolves_to_disenroll_view ( self ) : <EOL> found = resolve ( '<STR_LIT>' ) <EOL> self . assertEqual ( found . func , enrollment . disenroll ) <EOL> def test_disenroll_with_no_enrollment ( self ) : <EOL> courses = Course . objects . all ( ) <EOL> for course in courses : <EOL> course . delete ( ) <EOL> client = Client ( ) <EOL> client . login ( <EOL> username = TEST_USER_USERNAME , <EOL> password = TEST_USER_PASSWORD <EOL> ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , ** kwargs ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT>' ) <EOL> def test_disenroll_with_enrollment ( self ) : <EOL> client = Client ( ) <EOL> client . login ( <EOL> username = TEST_USER_USERNAME , <EOL> password = TEST_USER_PASSWORD <EOL> ) <EOL> kwargs = { '<STR_LIT>' : '<STR_LIT>' } <EOL> response = client . post ( '<STR_LIT>' , { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> } , ** kwargs ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> json_string = response . content . decode ( encoding = '<STR_LIT>' ) <EOL> array = json . loads ( json_string ) <EOL> self . assertEqual ( array [ '<STR_LIT:message>' ] , '<STR_LIT>' ) <EOL> self . assertEqual ( array [ '<STR_LIT:status>' ] , '<STR_LIT:success>' ) </s>
