def setUpTestData(cls): super(DashboardTokensTest, cls).setUpTestData() # create a user cls.user = SocialUserFactory.create(social_auth__extra_data=social_extra_data) cls.social_auth = cls.user.social_auth.first() cls.enrollments = Enrollments([]) # url for the dashboard cls.url = reverse('dashboard_api', args=[cls.social_auth.uid])
def setUpTestData(cls): super(DashboardTokensTest, cls).setUpTestData() # create an user cls.user = UserFactory.create() # create a social auth for the user cls.user.social_auth.create( provider=EdxOrgOAuth2.name, uid="{}_edx".format(cls.user.username), extra_data= '{"access_token": "fooooootoken", "refresh_token": "baaaarrefresh"}' ) cls.enrollments = Enrollments([]) # url for the dashboard cls.url = reverse('dashboard_api')
def test_certificates_enrollments(self, mocked_refresh): """ Make sure we call the right functions to retrieve student certificates and enrollments whenever user dashboard data is fetched """ certificates = Certificates([]) enrollments = Enrollments([]) with patch('dashboard.views.get_student_certificates', autospec=True, return_value=certificates) as cert,\ patch('dashboard.views.get_student_enrollments', autospec=True, return_value=enrollments) as enroll: resp = self.client.get(self.url) assert resp.status_code == 200, resp.content.decode('utf-8') assert cert.call_count == 1 assert enroll.call_count == 1 assert mocked_refresh.call_count == 1
def setUpTestData(cls): """ Set up data """ cls.user = UserFactory.create() cls.user.social_auth.create( provider=EdxOrgOAuth2.name, uid="{}_edx".format(cls.user.username), extra_data={"access_token": "fooooootoken"}) certificates_json = load_json_from_file( 'dashboard/fixtures/certificates.json') cls.certificates = Certificates( [Certificate(cert_json) for cert_json in certificates_json]) enrollments_json = load_json_from_file( 'dashboard/fixtures/user_enrollments.json') cls.enrollments = Enrollments(enrollments_json) # the grades need to have all the same usernames current_grades_json = [] for grade in load_json_from_file( 'dashboard/fixtures/current_grades.json'): grade.update({'username': cls.user.username}) current_grades_json.append(grade) cls.current_grades = CurrentGrades( [CurrentGrade(grade_json) for grade_json in current_grades_json]) cls.certificates_ids = set(cls.certificates.all_courses_certs) cls.verified_certificates_ids = set( cls.certificates.all_courses_verified_certs) cls.enrollment_ids = set(cls.enrollments.get_enrolled_course_ids()) cls.grades_ids = set(cls.current_grades.all_course_ids) cls.all_course_run_ids = list(cls.certificates_ids | cls.enrollment_ids | cls.grades_ids) cls.all_runs = [] for course_id in cls.all_course_run_ids: cls.all_runs.append( CourseRunFactory.create( edx_course_key=course_id, course__program__live=True, )) cls.edx_client = MagicMock() cls.edx_client.enrollments.get_student_enrollments.return_value = cls.enrollments cls.edx_client.certificates.get_student_certificates.return_value = cls.certificates cls.edx_client.current_grades.get_student_current_grades.return_value = cls.current_grades
def setUpTestData(cls): super(DashboardTest, cls).setUpTestData() # create an user cls.user = UserFactory.create() # create a social auth for the user cls.user.social_auth.create( provider=EdxOrgOAuth2.name, uid="{}_edx".format(cls.user.username), extra_data='{"access_token": "fooooootoken"}') # create an enrollments object with open( os.path.join(os.path.dirname(__file__), 'fixtures/user_enrollments.json')) as file_obj: cls.enrollments_json = json.loads(file_obj.read()) cls.enrollments = Enrollments(cls.enrollments_json) with open( os.path.join(os.path.dirname(__file__), 'fixtures/certificates.json')) as file_obj: certificates_json = json.loads(file_obj.read()) cls.certificates = Certificates( [Certificate(cert_json) for cert_json in certificates_json]) # create the programs cls.program_1 = ProgramFactory.create(live=True) cls.program_2 = ProgramFactory.create(live=True) cls.program_no_live = ProgramFactory.create(live=False) # create some courses for each program cls.courses_1 = [] cls.courses_2 = [] for num in range(2): cls.courses_1.append( CourseFactory.create(title="title course prog1 {}".format(num), program=cls.program_1)) cls.courses_2.append( CourseFactory.create(title="title course prog2 {}".format(num), program=cls.program_2)) # url for the dashboard cls.url = reverse('dashboard_api')