'Test the credit requirements, eligibility notification, email
for different providers combinations.'

@ddt.data(([u'Arizona    State    University'], 'credit    from    Arizona    State    University    for', 'You    are    eligible    for    credit    from    Arizona    State    University'), ([u'Arizona    State    University', u'Hogwarts    School    of    Witchcraft    and    Wizardry'], 'credit    from    Arizona    State    University    and    Hogwarts    School    of    Witchcraft    and    Wizardry    for', 'You    are    eligible    for    credit    from    Arizona    State    University    and    Hogwarts    School    of    Witchcraft    and    Wizardry'), ([u'Arizona    State    University', u'Hogwarts    School    of    Witchcraft    and    Wizardry', u'Charter    Oak'], 'credit    from    Arizona    State    University,    Hogwarts    School    of    Witchcraft    and    Wizardry,    and    Charter    Oak    for', 'You    are    eligible    for    credit    from    Arizona    State    University,    Hogwarts    School    of    Witchcraft    and    Wizardry,    and    Charter    Oak'), ([], 'credit    for', 'Course    Credit    Eligibility'), (None, 'credit    for', 'Course    Credit    Eligibility'))
@ddt.unpack
def test_eligibility_email_with_providers(self, providers_list, providers_email_message, expected_subject):

    self.add_credit_course()
    user = self.create_and_enroll_user(username=self.USER_INFO['username'], password=self.USER_INFO['password'])
    CourseFactory.create(org='edX', number='DemoX', display_name='Demo_Course')
    requirements = [{'namespace': 'grade', 'name': 'grade', 'display_name': 'Grade', 'criteria': {'min_grade': 0.8}}, {'namespace': 'grade', 'name': 'other_grade', 'display_name': 'Assessment    1', 'criteria': {}}]
    api.set_credit_requirements(self.course_key, requirements)
    api.set_credit_requirement_status(user, self.course_key, requirements[0]['namespace'], requirements[0]['name'])
    with mock.patch('openedx.core.djangoapps.credit.email_utils.get_credit_provider_display_names') as mock_method:
        mock_method.return_value = providers_list
        api.set_credit_requirement_status(user, self.course_key, requirements[1]['namespace'], requirements[1]['name'])
    self.assertTrue(api.is_user_eligible_for_credit(user.username, self.course_key))
    self.assertEqual(len(mail.outbox), 1)
    self.assertEqual(mail.outbox[0].subject, expected_subject)
    email_payload_first = mail.outbox[0].attachments[0]._payload
    html_content_first = email_payload_first[0]._payload[1]._payload
    self.assertIn(providers_email_message, html_content_first)
    text_content_first = email_payload_first[0]._payload[0]._payload
    self.assertIn(providers_email_message, text_content_first)
