def setUp(self): super(EmbargoMiddlewareTests, self).setUp() self.user = UserFactory(username='******', password='******') self.client.login(username='******', password='******') self.embargo_course = CourseFactory.create() self.embargo_course.save() self.regular_course = CourseFactory.create(org="Regular") self.regular_course.save() self.embargoed_page = '/courses/' + self.embargo_course.id.to_deprecated_string( ) + '/info' self.regular_page = '/courses/' + self.regular_course.id.to_deprecated_string( ) + '/info' EmbargoedCourse(course_id=self.embargo_course.id, embargoed=True).save() EmbargoedState(embargoed_countries="cu, ir, Sy, SD", changed_by=self.user, enabled=True).save() CourseEnrollment.enroll(self.user, self.regular_course.id) CourseEnrollment.enroll(self.user, self.embargo_course.id) # Text from lms/templates/static_templates/embargo.html self.embargo_text = "Unfortunately, at this time edX must comply with export controls, and we cannot allow you to access this course." self.patcher = mock.patch.object(pygeoip.GeoIP, 'country_code_by_addr', self.mock_country_code_by_addr) self.patcher.start()
def test_course_embargo(self): course_id = SlashSeparatedCourseKey('abc', '123', 'doremi') # Test that course is not authorized by default self.assertFalse(EmbargoedCourse.is_embargoed(course_id)) # Authorize cauth = EmbargoedCourse(course_id=course_id, embargoed=True) cauth.save() # Now, course should be embargoed self.assertTrue(EmbargoedCourse.is_embargoed(course_id)) self.assertEquals( cauth.__unicode__(), "Course 'abc/123/doremi' is Embargoed" ) # Unauthorize by explicitly setting email_enabled to False cauth.embargoed = False cauth.save() # Test that course is now unauthorized self.assertFalse(EmbargoedCourse.is_embargoed(course_id)) self.assertEquals( cauth.__unicode__(), "Course 'abc/123/doremi' is Not Embargoed" )
def test_course_embargo(self): course_id = CourseLocator('abc', '123', 'doremi') # Test that course is not authorized by default self.assertFalse(EmbargoedCourse.is_embargoed(course_id)) # Authorize cauth = EmbargoedCourse(course_id=course_id, embargoed=True) cauth.save() # Now, course should be embargoed self.assertTrue(EmbargoedCourse.is_embargoed(course_id)) self.assertEquals( unicode(cauth), u"Course '{course_id}' is Embargoed".format(course_id=course_id)) # Unauthorize by explicitly setting email_enabled to False cauth.embargoed = False cauth.save() # Test that course is now unauthorized self.assertFalse(EmbargoedCourse.is_embargoed(course_id)) self.assertEquals( unicode(cauth), u"Course '{course_id}' is Not Embargoed".format( course_id=course_id))