def test_state_embargo(self): # Azerbaijan and France should not be blocked good_states = ['AZ', 'FR'] # Gah block USA and Antartica blocked_states = ['US', 'AQ'] currently_blocked = EmbargoedState.current().embargoed_countries_list for state in blocked_states + good_states: self.assertNotIn(state, currently_blocked) # Block cauth = EmbargoedState(embargoed_countries='US, AQ') cauth.save() currently_blocked = EmbargoedState.current().embargoed_countries_list for state in good_states: self.assertNotIn(state, currently_blocked) for state in blocked_states: self.assertIn(state, currently_blocked) # Change embargo - block Isle of Man too blocked_states.append('IM') cauth.embargoed_countries = 'US, AQ, IM' cauth.save() currently_blocked = EmbargoedState.current().embargoed_countries_list for state in good_states: self.assertNotIn(state, currently_blocked) for state in blocked_states: self.assertIn(state, currently_blocked)
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()