jiahuimbzuai/CoQuIR huggingface dataset:
//  [python]
def test_get_sale_order_records_features_csv(self):
    """
    Test that the response from get_sale_order_records is in csv format.
    """
    # add the coupon code for the course
    coupon = Coupon(
        code='test_code', description='test_description', course_id=self.course.id,
        percentage_discount='10', created_by=self.instructor, is_active=True
    )
    coupon.save()
    self.cart.order_type = 'business'
    self.cart.save()
    self.cart.add_billing_details(company_name='Test Company', company_contact_name='Test',
                                  company_contact_email='test@123', recipient_name='R1',
                                  recipient_email='', customer_reference_number='PO#23')

    paid_course_reg_item = PaidCourseRegistration.add_to_order(
        self.cart,
        self.course.id,
        mode_slug=CourseMode.HONOR
    )
    # update the quantity of the cart item paid_course_reg_item
    resp = self.client.post(
        reverse('shoppingcart.views.update_user_cart', is_dashboard_endpoint=False),
        {'ItemId': paid_course_reg_item.id, 'qty': '4'}
    )
    self.assertEqual(resp.status_code, 200)
    # apply the coupon code to the item in the cart
    resp = self.client.post(
        reverse('shoppingcart.views.use_code', is_dashboard_endpoint=False),
        {'code': coupon.code}
    )
    self.assertEqual(resp.status_code, 200)
    self.cart.purchase()
    # get the updated item
    item = self.cart.orderitem_set.all().select_subclasses()[0]
    # get the redeemed coupon information
    coupon_redemption = CouponRedemption.objects.select_related('coupon').filter(order=self.cart)

    sale_order_url = reverse('get_sale_order_records', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(sale_order_url)
    self.assertEqual(response['Content-Type'], 'text/csv')
    self.assertIn('36', response.content.split('\r\n')[1])
    self.assertIn(str(item.unit_cost), response.content.split('\r\n')[1],)
    self.assertIn(str(item.list_price), response.content.split('\r\n')[1],)
    self.assertIn(item.status, response.content.split('\r\n')[1],)
    self.assertIn(coupon_redemption[0].coupon.code, response.content.split('\r\n')[1],)
//  [python]
def test_get_sale_order_records_features_csv(self):
    """
    Test that the response from get_sale_order_records is in csv format.
    """
    # add the coupon code for the course
    coupon = Coupon(
        code='test_code', description='test_description', course_id=self.course.id,
        percentage_discount='10', created_by=self.instructor, is_active=True
    )
    coupon.save()
    self.cart.order_type = 'business'
    self.cart.save()
    self.cart.add_billing_details(company_name='Test Company', company_contact_name='Test',
                                  company_contact_email='test@123', recipient_name='R1',
                                  recipient_email='', customer_reference_number='PO#23')

    paid_course_reg_item = PaidCourseRegistration.add_to_order(
        self.cart,
        self.course.id,
        mode_slug=CourseMode.HONOR
    )
    # update the quantity of the cart item paid_course_reg_item
    resp = self.client.post(reverse('shoppingcart.views.update_user_cart'), {'ItemId': paid_course_reg_item.id, 'qty': '4'})
    self.assertEqual(resp.status_code, 200)
    # apply the coupon code to the item in the cart
    resp = self.client.post(reverse('shoppingcart.views.use_code'), {'code': coupon.code})
    self.assertEqual(resp.status_code, 200)
    self.cart.purchase()
    # get the updated item
    item = self.cart.orderitem_set.all().select_subclasses()[0]
    # get the redeemed coupon information
    coupon_redemption = CouponRedemption.objects.select_related('coupon').filter(order=self.cart)

    sale_order_url = reverse('get_sale_order_records', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(sale_order_url)
    self.assertEqual(response['Content-Type'], 'text/csv')
    self.assertIn('36', response.content.split('\r\n')[1])
    self.assertIn(str(item.unit_cost), response.content.split('\r\n')[1],)
    self.assertIn(str(item.list_price), response.content.split('\r\n')[1],)
    self.assertIn(item.status, response.content.split('\r\n')[1],)
    self.assertIn(coupon_redemption[0].coupon.code, response.content.split('\r\n')[1],)
//  [python]
def test_get_sale_records_features_json(self):
    """
    Test that the response from get_sale_records is in json format.
    """
    for i in range(5):
        course_registration_code = CourseRegistrationCode(
            code='sale_invoice{}'.format(i),
            course_id=self.course.id.to_deprecated_string(),
            created_by=self.instructor,
            invoice=self.sale_invoice_1,
            invoice_item=self.invoice_item,
            mode_slug='honor'
        )
        course_registration_code.save()

    url = reverse('get_sale_records', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {})
    res_json = json.loads(response.content)
    self.assertIn('sale', res_json)

    for res in res_json['sale']:
        self.validate_sale_records_response(
            res,
            course_registration_code,
            self.sale_invoice_1,
            0,
            invoice_item=self.invoice_item
        )
//  [python]
def test_get_sale_records_features_json(self):
    """
    Test that the response from get_sale_records is in json format.
    """
    for i in range(5):
        course_registration_code = CourseRegistrationCode(
            code='sale_invoice{}'.format(i),
            course_id=self.course.id.to_deprecated_string(),
            created_by=self.instructor,
            invoice=self.sale_invoice_1,
            invoice_item=self.invoice_item,
            mode_slug='honor'
        )
        course_registration_code.save()

    url = reverse('get_sale_records', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {})
    res_json = json.loads(response.content)
    self.assertIn('sale', res_json)

    for res in res_json['sale']:
        self.validate_sale_records_response(
            res,
            course_registration_code,
            self.sale_invoice_1,
            0,
            invoice_item=self.invoice_item
        )
//  [python]
def test_get_student_exam_results(self):
    """
    Test whether get_proctored_exam_results returns an appropriate
    status message when users request a CSV file.
    """
    url = reverse(
        'get_proctored_exam_results',
        kwargs={'course_id': unicode(self.course.id)}
    )
    # Successful case:
    response = self.client.post(url, {})
    res_json = json.loads(response.content)
    self.assertIn('status', res_json)
    self.assertNotIn('currently being created', res_json['status'])
    # CSV generation already in progress:
    with patch('instructor_task.api.submit_proctored_exam_results_report') as submit_task_function:
        error = AlreadyRunningError()
        submit_task_function.side_effect = error
        response = self.client.post(url, {})
        res_json = json.loads(response.content)
        self.assertIn('status', res_json)
        self.assertIn('currently being created', res_json['status'])
//  [python]
def test_get_student_exam_results(self):
    """
    Test whether get_proctored_exam_results returns an appropriate
    status message when users request a CSV file.
    """
    url = reverse(
        'get_proctored_exam_results',
        kwargs={'course_id': unicode(self.course.id)}
    )
    # Successful case:
    response = self.client.get(url, {})
    res_json = json.loads(response.content)
    self.assertIn('status', res_json)
    self.assertNotIn('currently being created', res_json['status'])
    # CSV generation already in progress:
    with patch('instructor_task.api.submit_proctored_exam_results_report') as submit_task_function:
        error = AlreadyRunningError()
        submit_task_function.side_effect = error
        response = self.client.get(url, {})
        res_json = json.loads(response.content)
        self.assertIn('status', res_json)
        self.assertIn('currently being created', res_json['status'])
//  [python]
def test_get_sale_records_features_with_multiple_invoices(self):
    """
    Test that the response from get_sale_records is in json format for multiple invoices
    """
    for i in range(5):
        course_registration_code = CourseRegistrationCode(
            code='qwerty{}'.format(i),
            course_id=self.course.id.to_deprecated_string(),
            created_by=self.instructor,
            invoice=self.sale_invoice_1,
            invoice_item=self.invoice_item,
            mode_slug='honor'
        )
        course_registration_code.save()

    # Create test invoice 2
    sale_invoice_2 = Invoice.objects.create(
        total_amount=1234.32, company_name='Test1', company_contact_name='TestName', company_contact_email='Test@company.com',
        recipient_name='Testw_2', recipient_email='test2@test.com', customer_reference_number='2Fwe23S',
        internal_reference="B", course_id=self.course.id
    )

    invoice_item_2 = CourseRegistrationCodeInvoiceItem.objects.create(
        invoice=sale_invoice_2,
        qty=1,
        unit_price=1234.32,
        course_id=self.course.id
    )

    for i in range(5):
        course_registration_code = CourseRegistrationCode(
            code='xyzmn{}'.format(i), course_id=self.course.id.to_deprecated_string(),
            created_by=self.instructor, invoice=sale_invoice_2, invoice_item=invoice_item_2, mode_slug='honor'
        )
        course_registration_code.save()

    url = reverse('get_sale_records', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {})
    res_json = json.loads(response.content)
    self.assertIn('sale', res_json)

    self.validate_sale_records_response(
        res_json['sale'][0],
        course_registration_code,
        self.sale_invoice_1,
        0,
        invoice_item=self.invoice_item
    )
    self.validate_sale_records_response(
        res_json['sale'][1],
        course_registration_code,
        sale_invoice_2,
        0,
        invoice_item=invoice_item_2
    )
//  [python]
def test_get_sale_records_features_with_multiple_invoices(self):
    """
    Test that the response from get_sale_records is in json format for multiple invoices
    """
    for i in range(5):
        course_registration_code = CourseRegistrationCode(
            code='qwerty{}'.format(i),
            course_id=self.course.id.to_deprecated_string(),
            created_by=self.instructor,
            invoice=self.sale_invoice_1,
            invoice_item=self.invoice_item,
            mode_slug='honor'
        )
        course_registration_code.save()

    # Create test invoice 2
    sale_invoice_2 = Invoice.objects.create(
        total_amount=1234.32, company_name='Test1', company_contact_name='TestName', company_contact_email='Test@company.com',
        recipient_name='Testw_2', recipient_email='test2@test.com', customer_reference_number='2Fwe23S',
        internal_reference="B", course_id=self.course.id
    )

    invoice_item_2 = CourseRegistrationCodeInvoiceItem.objects.create(
        invoice=sale_invoice_2,
        qty=1,
        unit_price=1234.32,
        course_id=self.course.id
    )

    for i in range(5):
        course_registration_code = CourseRegistrationCode(
            code='xyzmn{}'.format(i), course_id=self.course.id.to_deprecated_string(),
            created_by=self.instructor, invoice=sale_invoice_2, invoice_item=invoice_item_2, mode_slug='honor'
        )
        course_registration_code.save()

    url = reverse('get_sale_records', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {})
    res_json = json.loads(response.content)
    self.assertIn('sale', res_json)

    self.validate_sale_records_response(
        res_json['sale'][0],
        course_registration_code,
        self.sale_invoice_1,
        0,
        invoice_item=self.invoice_item
    )
    self.validate_sale_records_response(
        res_json['sale'][1],
        course_registration_code,
        sale_invoice_2,
        0,
        invoice_item=invoice_item_2
    )
//  [python]
def test_get_student_progress_url_from_uname(self):
    """ Test that progress_url is in the successful response. """
    url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()})
    data = {'unique_student_identifier': self.students[0].username.encode("utf-8")}
    response = self.client.post(url, data)
    self.assertEqual(response.status_code, 200)
    res_json = json.loads(response.content)
    self.assertIn('progress_url', res_json)
//  [python]
def test_get_student_progress_url_from_uname(self):
    """ Test that progress_url is in the successful response. """
    url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()})
    url += "?unique_student_identifier={}".format(
        quote(self.students[0].username.encode("utf-8"))
    )
    response = self.client.get(url)
    self.assertEqual(response.status_code, 200)
    res_json = json.loads(response.content)
    self.assertIn('progress_url', res_json)
//  [python]
def test_get_student_progress_url(self):
    """ Test that progress_url is in the successful response. """
    url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()})
    data = {'unique_student_identifier': self.students[0].email.encode("utf-8")}
    response = self.client.post(url, data)
    self.assertEqual(response.status_code, 200)
    res_json = json.loads(response.content)
    self.assertIn('progress_url', res_json)
//  [python]
def test_get_student_progress_url(self):
    """ Test that progress_url is in the successful response. """
    url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()})
    url += "?unique_student_identifier={}".format(
        quote(self.students[0].email.encode("utf-8"))
    )
    response = self.client.get(url)
    self.assertEqual(response.status_code, 200)
    res_json = json.loads(response.content)
    self.assertIn('progress_url', res_json)
//  [python]
def test_get_student_progress_url_nostudent(self):
    """ Test that the endpoint 400's when requesting an unknown email. """
    url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url)
    self.assertEqual(response.status_code, 400)
//  [python]
def test_get_student_progress_url_nostudent(self):
    """ Test that the endpoint 400's when requesting an unknown email. """
    url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url)
    self.assertEqual(response.status_code, 400)
//  [python]
def test_get_student_progress_url_noparams(self):
    """ Test that the endpoint 404's without the required query params. """
    url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url)
    self.assertEqual(response.status_code, 400)
//  [python]
def test_get_student_progress_url_noparams(self):
    """ Test that the endpoint 404's without the required query params. """
    url = reverse('get_student_progress_url', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url)
    self.assertEqual(response.status_code, 400)
//  [python]
def test_get_students_features_cohorted(self, is_cohorted):
    """
    Test that get_students_features includes cohort info when the course is
    cohorted, and does not when the course is not cohorted.
    """
    url = reverse('get_students_features', kwargs={'course_id': unicode(self.course.id)})
    set_course_cohort_settings(self.course.id, is_cohorted=is_cohorted)

    response = self.client.post(url, {})
    res_json = json.loads(response.content)

    self.assertEqual('cohort' in res_json['feature_names'], is_cohorted)
//  [python]
def test_get_students_features_cohorted(self, is_cohorted):
    """
    Test that get_students_features includes cohort info when the course is
    cohorted, and does not when the course is not cohorted.
    """
    url = reverse('get_students_features', kwargs={'course_id': unicode(self.course.id)})
    set_course_cohort_settings(self.course.id, is_cohorted=is_cohorted)

    response = self.client.get(url, {})
    res_json = json.loads(response.content)

    self.assertEqual('cohort' in res_json['feature_names'], is_cohorted)
//  [python]
def test_get_students_features(self):
    """
    Test that some minimum of information is formatted
    correctly in the response to get_students_features.
    """
    for student in self.students:
        student.profile.city = "Mos Eisley {}".format(student.id)
        student.profile.save()
    url = reverse('get_students_features', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {})
    res_json = json.loads(response.content)
    self.assertIn('students', res_json)
    for student in self.students:
        student_json = [
            x for x in res_json['students']
            if x['username'] == student.username
        ][0]
        self.assertEqual(student_json['username'], student.username)
        self.assertEqual(student_json['email'], student.email)
        self.assertEqual(student_json['city'], student.profile.city)
        self.assertEqual(student_json['country'], "")
//  [python]
def test_get_students_features(self):
    """
    Test that some minimum of information is formatted
    correctly in the response to get_students_features.
    """
    for student in self.students:
        student.profile.city = "Mos Eisley {}".format(student.id)
        student.profile.save()
    url = reverse('get_students_features', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {})
    res_json = json.loads(response.content)
    self.assertIn('students', res_json)
    for student in self.students:
        student_json = [
            x for x in res_json['students']
            if x['username'] == student.username
        ][0]
        self.assertEqual(student_json['username'], student.username)
        self.assertEqual(student_json['email'], student.email)
        self.assertEqual(student_json['city'], student.profile.city)
        self.assertEqual(student_json['country'], "")
//  [python]
def test_get_students_who_may_enroll(self):
    """
    Test whether get_students_who_may_enroll returns an appropriate
    status message when users request a CSV file of students who
    may enroll in a course.
    """
    url = reverse(
        'get_students_who_may_enroll',
        kwargs={'course_id': unicode(self.course.id)}
    )
    # Successful case:
    response = self.client.post(url, {})
    res_json = json.loads(response.content)
    self.assertIn('status', res_json)
    self.assertNotIn('currently being created', res_json['status'])
    # CSV generation already in progress:
    with patch('instructor_task.api.submit_calculate_may_enroll_csv') as submit_task_function:
        error = AlreadyRunningError()
        submit_task_function.side_effect = error
        response = self.client.post(url, {})
        res_json = json.loads(response.content)
        self.assertIn('status', res_json)
        self.assertIn('currently being created', res_json['status'])
//  [python]
def test_get_students_who_may_enroll(self):
    """
    Test whether get_students_who_may_enroll returns an appropriate
    status message when users request a CSV file of students who
    may enroll in a course.
    """
    url = reverse(
        'get_students_who_may_enroll',
        kwargs={'course_id': unicode(self.course.id)}
    )
    # Successful case:
    response = self.client.get(url, {})
    res_json = json.loads(response.content)
    self.assertIn('status', res_json)
    self.assertNotIn('currently being created', res_json['status'])
    # CSV generation already in progress:
    with patch('instructor_task.api.submit_calculate_may_enroll_csv') as submit_task_function:
        error = AlreadyRunningError()
        submit_task_function.side_effect = error
        response = self.client.get(url, {})
        res_json = json.loads(response.content)
        self.assertIn('status', res_json)
        self.assertIn('currently being created', res_json['status'])
//  [python]
def test_get_students_features_teams(self, has_teams):
    """
    Test that get_students_features includes team info when the course is
    has teams enabled, and does not when the course does not have teams enabled
    """
    if has_teams:
        self.course = CourseFactory.create(teams_configuration={
            'max_size': 2, 'topics': [{'topic-id': 'topic', 'name': 'Topic', 'description': 'A Topic'}]
        })
        course_instructor = InstructorFactory(course_key=self.course.id)
        self.client.login(username=course_instructor.username, password='test')

    url = reverse('get_students_features', kwargs={'course_id': unicode(self.course.id)})

    response = self.client.post(url, {})
    res_json = json.loads(response.content)

    self.assertEqual('team' in res_json['feature_names'], has_teams)
//  [python]
def test_get_students_features_teams(self, has_teams):
    """
    Test that get_students_features includes team info when the course is
    has teams enabled, and does not when the course does not have teams enabled
    """
    if has_teams:
        self.course = CourseFactory.create(teams_configuration={
            'max_size': 2, 'topics': [{'topic-id': 'topic', 'name': 'Topic', 'description': 'A Topic'}]
        })
        course_instructor = InstructorFactory(course_key=self.course.id)
        self.client.login(username=course_instructor.username, password='test')

    url = reverse('get_students_features', kwargs={'course_id': unicode(self.course.id)})

    response = self.client.get(url, {})
    res_json = json.loads(response.content)

    self.assertEqual('team' in res_json['feature_names'], has_teams)
//  [python]
def test_invoice_payment_is_still_pending_for_registration_codes(self):
    """
    test generate enrollment report
    enroll a user in a course using registration code
    whose invoice has not been paid yet
    """
    course_registration_code = CourseRegistrationCode.objects.create(
        code='abcde',
        course_id=self.course.id.to_deprecated_string(),
        created_by=self.instructor,
        invoice=self.sale_invoice_1,
        invoice_item=self.invoice_item,
        mode_slug='honor'
    )

    test_user1 = UserFactory()
    self.register_with_redemption_code(test_user1, course_registration_code.code)

    CourseFinanceAdminRole(self.course.id).add_users(self.instructor)
    self.client.login(username=self.instructor.username, password='test')

    url = reverse('get_enrollment_report', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {})
    self.assertIn('The detailed enrollment report is being created.', response.content)
//  [python]
def test_invoice_payment_is_still_pending_for_registration_codes(self):
    """
    test generate enrollment report
    enroll a user in a course using registration code
    whose invoice has not been paid yet
    """
    course_registration_code = CourseRegistrationCode.objects.create(
        code='abcde',
        course_id=self.course.id.to_deprecated_string(),
        created_by=self.instructor,
        invoice=self.sale_invoice_1,
        invoice_item=self.invoice_item,
        mode_slug='honor'
    )

    test_user1 = UserFactory()
    self.register_with_redemption_code(test_user1, course_registration_code.code)

    CourseFinanceAdminRole(self.course.id).add_users(self.instructor)
    self.client.login(username=self.instructor.username, password='test')

    url = reverse('get_enrollment_report', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {})
    self.assertIn('The detailed enrollment report is being created.', response.content)
//  [python]
def test_list_background_email_tasks(self, act):
    """Test list of background email tasks."""
    act.return_value = self.tasks
    url = reverse('list_background_email_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()})
    mock_factory = MockCompletionInfo()
    with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info:
        mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info
        response = self.client.post(url, {})
    self.assertEqual(response.status_code, 200)

    # check response
    self.assertTrue(act.called)
    expected_tasks = [ftask.to_dict() for ftask in self.tasks]
    actual_tasks = json.loads(response.content)['tasks']
    for exp_task, act_task in zip(expected_tasks, actual_tasks):
        self.assertDictEqual(exp_task, act_task)
    self.assertEqual(actual_tasks, expected_tasks)
//  [python]
def test_list_background_email_tasks(self, act):
    """Test list of background email tasks."""
    act.return_value = self.tasks
    url = reverse('list_background_email_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()})
    mock_factory = MockCompletionInfo()
    with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info:
        mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info
        response = self.client.get(url, {})
    self.assertEqual(response.status_code, 200)

    # check response
    self.assertTrue(act.called)
    expected_tasks = [ftask.to_dict() for ftask in self.tasks]
    actual_tasks = json.loads(response.content)['tasks']
    for exp_task, act_task in zip(expected_tasks, actual_tasks):
        self.assertDictEqual(exp_task, act_task)
    self.assertEqual(actual_tasks, expected_tasks)
//  [python]
def test_list_course_role_members_bad_rolename(self):
    """ Test with an invalid rolename parameter. """
    url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {
        'rolename': 'robot-not-a-rolename',
    })
    self.assertEqual(response.status_code, 400)
//  [python]
def test_list_course_role_members_bad_rolename(self):
    """ Test with an invalid rolename parameter. """
    url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {
        'rolename': 'robot-not-a-rolename',
    })
    self.assertEqual(response.status_code, 400)
//  [python]
def test_list_course_role_members_beta(self):
    url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {
        'rolename': 'beta',
    })
    self.assertEqual(response.status_code, 200)

    # check response content
    expected = {
        'course_id': self.course.id.to_deprecated_string(),
        'beta': []
    }
    res_json = json.loads(response.content)
    self.assertEqual(res_json, expected)
//  [python]
def test_list_course_role_members_beta(self):
    url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {
        'rolename': 'beta',
    })
    self.assertEqual(response.status_code, 200)

    # check response content
    expected = {
        'course_id': self.course.id.to_deprecated_string(),
        'beta': []
    }
    res_json = json.loads(response.content)
    self.assertEqual(res_json, expected)
//  [python]
def test_list_course_role_members_noparams(self):
    """ Test missing all query parameters. """
    url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url)
    self.assertEqual(response.status_code, 400)
//  [python]
def test_list_course_role_members_noparams(self):
    """ Test missing all query parameters. """
    url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url)
    self.assertEqual(response.status_code, 400)
//  [python]
def test_list_email_with_no_successes(self, task_history_request):
    task_info = FakeContentTask(0, 0, 10, 'expected')
    email = FakeEmail(0)
    email_info = FakeEmailInfo(email, 0, 10)
    task_history_request.return_value = [task_info]
    url = reverse('list_email_content', kwargs={'course_id': self.course.id.to_deprecated_string()})
    with patch('instructor.views.api.CourseEmail.objects.get') as mock_email_info:
        mock_email_info.return_value = email
        response = self.client.post(url, {})
    self.assertEqual(response.status_code, 200)

    self.assertTrue(task_history_request.called)
    returned_info_list = json.loads(response.content)['emails']

    self.assertEqual(len(returned_info_list), 1)
    returned_info = returned_info_list[0]
    expected_info = email_info.to_dict()
    self.assertDictEqual(expected_info, returned_info)
//  [python]
def test_list_email_with_no_successes(self, task_history_request):
    task_info = FakeContentTask(0, 0, 10, 'expected')
    email = FakeEmail(0)
    email_info = FakeEmailInfo(email, 0, 10)
    task_history_request.return_value = [task_info]
    url = reverse('list_email_content', kwargs={'course_id': self.course.id.to_deprecated_string()})
    with patch('instructor.views.api.CourseEmail.objects.get') as mock_email_info:
        mock_email_info.return_value = email
        response = self.client.get(url, {})
    self.assertEqual(response.status_code, 200)

    self.assertTrue(task_history_request.called)
    returned_info_list = json.loads(response.content)['emails']

    self.assertEqual(len(returned_info_list), 1)
    returned_info = returned_info_list[0]
    expected_info = email_info.to_dict()
    self.assertDictEqual(expected_info, returned_info)
//  [python]
def test_list_entrance_exam_instructor_tasks_all_student(self):
    """ Test list task history for entrance exam AND all student. """
    url = reverse('list_entrance_exam_instructor_tasks', kwargs={'course_id': unicode(self.course.id)})
    response = self.client.post(url, {})
    self.assertEqual(response.status_code, 200)

    # check response
    tasks = json.loads(response.content)['tasks']
    self.assertEqual(len(tasks), 0)
//  [python]
def test_list_entrance_exam_instructor_tasks_all_student(self):
    """ Test list task history for entrance exam AND all student. """
    url = reverse('list_entrance_exam_instructor_tasks', kwargs={'course_id': unicode(self.course.id)})
    response = self.client.get(url, {})
    self.assertEqual(response.status_code, 200)

    # check response
    tasks = json.loads(response.content)['tasks']
    self.assertEqual(len(tasks), 0)
//  [python]
def test_list_entrance_exam_instructor_tasks_student(self):
    """ Test list task history for entrance exam AND student. """
    # create a re-score entrance exam task
    url = reverse('rescore_entrance_exam', kwargs={'course_id': unicode(self.course.id)})
    response = self.client.post(url, {
        'unique_student_identifier': self.student.email,
    })
    self.assertEqual(response.status_code, 200)

    url = reverse('list_entrance_exam_instructor_tasks', kwargs={'course_id': unicode(self.course.id)})
    response = self.client.post(url, {
        'unique_student_identifier': self.student.email,
    })
    self.assertEqual(response.status_code, 200)

    # check response
    tasks = json.loads(response.content)['tasks']
    self.assertEqual(len(tasks), 1)
    self.assertEqual(tasks[0]['status'], _('Complete'))
//  [python]
def test_list_entrance_exam_instructor_tasks_student(self):
    """ Test list task history for entrance exam AND student. """
    # create a re-score entrance exam task
    url = reverse('rescore_entrance_exam', kwargs={'course_id': unicode(self.course.id)})
    response = self.client.get(url, {
        'unique_student_identifier': self.student.email,
    })
    self.assertEqual(response.status_code, 200)

    url = reverse('list_entrance_exam_instructor_tasks', kwargs={'course_id': unicode(self.course.id)})
    response = self.client.get(url, {
        'unique_student_identifier': self.student.email,
    })
    self.assertEqual(response.status_code, 200)

    # check response
    tasks = json.loads(response.content)['tasks']
    self.assertEqual(len(tasks), 1)
    self.assertEqual(tasks[0]['status'], _('Complete'))
//  [python]
def test_list_instructor_tasks_running(self, act):
    """ Test list of all running tasks. """
    act.return_value = self.tasks
    url = reverse('list_instructor_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()})
    mock_factory = MockCompletionInfo()
    with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info:
        mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info
        response = self.client.post(url, {})
    self.assertEqual(response.status_code, 200)

    # check response
    self.assertTrue(act.called)
    expected_tasks = [ftask.to_dict() for ftask in self.tasks]
    actual_tasks = json.loads(response.content)['tasks']
    for exp_task, act_task in zip(expected_tasks, actual_tasks):
        self.assertDictEqual(exp_task, act_task)
    self.assertEqual(actual_tasks, expected_tasks)
//  [python]
def test_list_instructor_tasks_running(self, act):
    """ Test list of all running tasks. """
    act.return_value = self.tasks
    url = reverse('list_instructor_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()})
    mock_factory = MockCompletionInfo()
    with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info:
        mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info
        response = self.client.get(url, {})
    self.assertEqual(response.status_code, 200)

    # check response
    self.assertTrue(act.called)
    expected_tasks = [ftask.to_dict() for ftask in self.tasks]
    actual_tasks = json.loads(response.content)['tasks']
    for exp_task, act_task in zip(expected_tasks, actual_tasks):
        self.assertDictEqual(exp_task, act_task)
    self.assertEqual(actual_tasks, expected_tasks)
//  [python]
def test_list_instructor_tasks_problem_student(self, act):
    """ Test list task history for problem AND student. """
    act.return_value = self.tasks
    url = reverse('list_instructor_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()})
    mock_factory = MockCompletionInfo()
    with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info:
        mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info
        response = self.client.post(url, {
            'problem_location_str': self.problem_urlname,
            'unique_student_identifier': self.student.email,
        })
    self.assertEqual(response.status_code, 200)

    # check response
    self.assertTrue(act.called)
    expected_tasks = [ftask.to_dict() for ftask in self.tasks]
    actual_tasks = json.loads(response.content)['tasks']
    for exp_task, act_task in zip(expected_tasks, actual_tasks):
        self.assertDictEqual(exp_task, act_task)

    self.assertEqual(actual_tasks, expected_tasks)
//  [python]
def test_list_instructor_tasks_problem_student(self, act):
    """ Test list task history for problem AND student. """
    act.return_value = self.tasks
    url = reverse('list_instructor_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()})
    mock_factory = MockCompletionInfo()
    with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info:
        mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info
        response = self.client.get(url, {
            'problem_location_str': self.problem_urlname,
            'unique_student_identifier': self.student.email,
        })
    self.assertEqual(response.status_code, 200)

    # check response
    self.assertTrue(act.called)
    expected_tasks = [ftask.to_dict() for ftask in self.tasks]
    actual_tasks = json.loads(response.content)['tasks']
    for exp_task, act_task in zip(expected_tasks, actual_tasks):
        self.assertDictEqual(exp_task, act_task)

    self.assertEqual(actual_tasks, expected_tasks)
//  [python]
def test_list_entrance_exam_instructor_with_invalid_exam_key(self):
    """ Test list task history for entrance exam failure if course has invalid exam. """
    url = reverse('list_entrance_exam_instructor_tasks',
                  kwargs={'course_id': unicode(self.course_with_invalid_ee.id)})
    response = self.client.post(url, {
        'unique_student_identifier': self.student.email,
    })
    self.assertEqual(response.status_code, 400)
//  [python]
def test_list_entrance_exam_instructor_with_invalid_exam_key(self):
    """ Test list task history for entrance exam failure if course has invalid exam. """
    url = reverse('list_entrance_exam_instructor_tasks',
                  kwargs={'course_id': unicode(self.course_with_invalid_ee.id)})
    response = self.client.get(url, {
        'unique_student_identifier': self.student.email,
    })
    self.assertEqual(response.status_code, 400)
//  [python]
def test_list_instructor_tasks_problem(self, act):
    """ Test list task history for problem. """
    act.return_value = self.tasks
    url = reverse('list_instructor_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()})
    mock_factory = MockCompletionInfo()
    with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info:
        mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info
        response = self.client.post(url, {
            'problem_location_str': self.problem_urlname,
        })
    self.assertEqual(response.status_code, 200)

    # check response
    self.assertTrue(act.called)
    expected_tasks = [ftask.to_dict() for ftask in self.tasks]
    actual_tasks = json.loads(response.content)['tasks']
    for exp_task, act_task in zip(expected_tasks, actual_tasks):
        self.assertDictEqual(exp_task, act_task)
    self.assertEqual(actual_tasks, expected_tasks)
//  [python]
def test_list_instructor_tasks_problem(self, act):
    """ Test list task history for problem. """
    act.return_value = self.tasks
    url = reverse('list_instructor_tasks', kwargs={'course_id': self.course.id.to_deprecated_string()})
    mock_factory = MockCompletionInfo()
    with patch('instructor.views.instructor_task_helpers.get_task_completion_info') as mock_completion_info:
        mock_completion_info.side_effect = mock_factory.mock_get_task_completion_info
        response = self.client.get(url, {
            'problem_location_str': self.problem_urlname,
        })
    self.assertEqual(response.status_code, 200)

    # check response
    self.assertTrue(act.called)
    expected_tasks = [ftask.to_dict() for ftask in self.tasks]
    actual_tasks = json.loads(response.content)['tasks']
    for exp_task, act_task in zip(expected_tasks, actual_tasks):
        self.assertDictEqual(exp_task, act_task)
    self.assertEqual(actual_tasks, expected_tasks)
//  [python]
def test_list_course_role_members_staff(self):
    url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {
        'rolename': 'staff',
    })
    self.assertEqual(response.status_code, 200)

    # check response content
    expected = {
        'course_id': self.course.id.to_deprecated_string(),
        'staff': [
            {
                'username': self.other_staff.username,
                'email': self.other_staff.email,
                'first_name': self.other_staff.first_name,
                'last_name': self.other_staff.last_name,
            }
        ]
    }
    res_json = json.loads(response.content)
    self.assertEqual(res_json, expected)
//  [python]
def test_list_course_role_members_staff(self):
    url = reverse('list_course_role_members', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {
        'rolename': 'staff',
    })
    self.assertEqual(response.status_code, 200)

    # check response content
    expected = {
        'course_id': self.course.id.to_deprecated_string(),
        'staff': [
            {
                'username': self.other_staff.username,
                'email': self.other_staff.email,
                'first_name': self.other_staff.first_name,
                'last_name': self.other_staff.last_name,
            }
        ]
    }
    res_json = json.loads(response.content)
    self.assertEqual(res_json, expected)
//  [python]
def test_list_report_downloads(self):
    url = reverse('list_report_downloads', kwargs={'course_id': self.course.id.to_deprecated_string()})
    with patch('instructor_task.models.LocalFSReportStore.links_for') as mock_links_for:
        mock_links_for.return_value = [
            ('mock_file_name_1', 'https://1.mock.url'),
            ('mock_file_name_2', 'https://2.mock.url'),
        ]
        response = self.client.post(url, {})

    expected_response = {
        "downloads": [
            {
                "url": "https://1.mock.url",
                "link": "<a href=\"https://1.mock.url\">mock_file_name_1</a>",
                "name": "mock_file_name_1"
            },
            {
                "url": "https://2.mock.url",
                "link": "<a href=\"https://2.mock.url\">mock_file_name_2</a>",
                "name": "mock_file_name_2"
            }
        ]
    }
    res_json = json.loads(response.content)
    self.assertEqual(res_json, expected_response)
//  [python]
def test_list_report_downloads(self):
    url = reverse('list_report_downloads', kwargs={'course_id': self.course.id.to_deprecated_string()})
    with patch('instructor_task.models.LocalFSReportStore.links_for') as mock_links_for:
        mock_links_for.return_value = [
            ('mock_file_name_1', 'https://1.mock.url'),
            ('mock_file_name_2', 'https://2.mock.url'),
        ]
        response = self.client.get(url, {})

    expected_response = {
        "downloads": [
            {
                "url": "https://1.mock.url",
                "link": "<a href=\"https://1.mock.url\">mock_file_name_1</a>",
                "name": "mock_file_name_1"
            },
            {
                "url": "https://2.mock.url",
                "link": "<a href=\"https://2.mock.url\">mock_file_name_2</a>",
                "name": "mock_file_name_2"
            }
        ]
    }
    res_json = json.loads(response.content)
    self.assertEqual(res_json, expected_response)
//  [python]
def test_modify_access_allow(self):
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {
        'unique_student_identifier': self.other_user.email,
        'rolename': 'staff',
        'action': 'allow',
    })
    self.assertEqual(response.status_code, 200)
//  [python]
def test_modify_access_allow(self):
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {
        'unique_student_identifier': self.other_user.email,
        'rolename': 'staff',
        'action': 'allow',
    })
    self.assertEqual(response.status_code, 200)
//  [python]
def test_modify_access_bad_role(self):
    """ Test with an invalid action parameter. """
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {
        'unique_student_identifier': self.other_staff.email,
        'rolename': 'robot-not-a-roll',
        'action': 'revoke',
    })
    self.assertEqual(response.status_code, 400)
//  [python]
def test_modify_access_bad_role(self):
    """ Test with an invalid action parameter. """
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {
        'unique_student_identifier': self.other_staff.email,
        'rolename': 'robot-not-a-roll',
        'action': 'revoke',
    })
    self.assertEqual(response.status_code, 400)
//  [python]
def test_modify_access_bad_action(self):
    """ Test with an invalid action parameter. """
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {
        'unique_student_identifier': self.other_staff.email,
        'rolename': 'staff',
        'action': 'robot-not-an-action',
    })
    self.assertEqual(response.status_code, 400)
//  [python]
def test_modify_access_bad_action(self):
    """ Test with an invalid action parameter. """
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {
        'unique_student_identifier': self.other_staff.email,
        'rolename': 'staff',
        'action': 'robot-not-an-action',
    })
    self.assertEqual(response.status_code, 400)
//  [python]
def test_modify_access_noparams(self):
    """ Test missing all query parameters. """
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url)
    self.assertEqual(response.status_code, 400)
//  [python]
def test_modify_access_noparams(self):
    """ Test missing all query parameters. """
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url)
    self.assertEqual(response.status_code, 400)
//  [python]
def test_modify_access_revoke(self):
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {
        'unique_student_identifier': self.other_staff.email,
        'rolename': 'staff',
        'action': 'revoke',
    })
    self.assertEqual(response.status_code, 200)
//  [python]
def test_modify_access_revoke(self):
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {
        'unique_student_identifier': self.other_staff.email,
        'rolename': 'staff',
        'action': 'revoke',
    })
    self.assertEqual(response.status_code, 200)
//  [python]
def test_modify_access_allow_with_uname(self):
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {
        'unique_student_identifier': self.other_instructor.username,
        'rolename': 'staff',
        'action': 'allow',
    })
    self.assertEqual(response.status_code, 200)
//  [python]
def test_modify_access_allow_with_uname(self):
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {
        'unique_student_identifier': self.other_instructor.username,
        'rolename': 'staff',
        'action': 'allow',
    })
    self.assertEqual(response.status_code, 200)
//  [python]
def test_modify_access_revoke_with_username(self):
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.post(url, {
        'unique_student_identifier': self.other_staff.username,
        'rolename': 'staff',
        'action': 'revoke',
    })
    self.assertEqual(response.status_code, 200)
//  [python]
def test_modify_access_revoke_with_username(self):
    url = reverse('modify_access', kwargs={'course_id': self.course.id.to_deprecated_string()})
    response = self.client.get(url, {
        'unique_student_identifier': self.other_staff.username,
        'rolename': 'staff',
        'action': 'revoke',
    })
    self.assertEqual(response.status_code, 200)