def setUp(self):
     super(UserCredentialAttributeSerializerTests, self).setUp()
     self.program_cert = ProgramCertificateFactory()
     self.program_credential = UserCredentialFactory(
         credential=self.program_cert)
     self.program_cert_attr = UserCredentialAttributeFactory(
         user_credential=self.program_credential)
示例#2
0
 def setUp(self):
     super(ProgramCertificateIssuerTests, self).setUp()
     self.issuer = ProgramCertificateIssuer()
     self.program_certificate = ProgramCertificateFactory.create()
     self.username = '******'
     self.user_program_cred = self.issuer.issue_credential(self.program_certificate, self.username)
     self.attributes = [{"name": "whitelist_reason", "value": "Reason for whitelisting."}]
示例#3
0
 def setUp(self):
     super(AccreditorTests, self).setUp()
     self.accreditor = Accreditor()
     self.program_cert = ProgramCertificateFactory()
     self.program_credential = ProgramCertificate
     self.attributes = [{
         "name": "whitelist_reason",
         "value": "Reason for whitelisting."
     }]
示例#4
0
 def setUp(self):
     super(ProgramCertificateIssuerTests, self).setUp()
     self.issuer = ProgramCertificateIssuer()
     self.program_certificate = ProgramCertificateFactory.create()
     self.username = '******'
     self.user_program_cred = self.issuer.issue_credential(
         self.program_certificate, self.username)
     self.attributes = [{
         "name": "whitelist_reason",
         "value": "Reason for whitelisting."
     }]
    def setUp(self):
        super(UserCredentialSerializerTests, self).setUp()

        self.program_cert = ProgramCertificateFactory()
        self.program_credential = UserCredentialFactory(
            credential=self.program_cert)
        self.program_cert_attr = UserCredentialAttributeFactory(
            user_credential=self.program_credential)

        self.course_cert = CourseCertificateFactory.create()
        self.course_credential = UserCredentialFactory.create(
            credential=self.course_cert)
        self.course_cert_attr = UserCredentialAttributeFactory(
            user_credential=self.course_credential)
        self.request = APIRequestFactory().get('/')
 def setUp(self):
     super(CredentialFieldTests, self).setUp()
     self.program_cert = ProgramCertificateFactory()
     self.field_instance = serializers.CredentialField()
示例#7
0
 def setUp(self):
     super(CredentialFieldTests, self).setUp()
     self.program_cert = ProgramCertificateFactory()
     self.field_instance = serializers.CredentialField()
示例#8
0
class CredentialFieldTests(TestCase):
    """ CredentialField tests. """

    def setUp(self):
        super(CredentialFieldTests, self).setUp()
        self.program_cert = ProgramCertificateFactory()
        self.field_instance = serializers.CredentialField()

    @ddt.data(
        {"program_id": ""},
        {"course_id": ""},
        {"course_id": 404, 'certificate_type': ''},
    )
    def test_to_internal_value_with_empty_credential(self, credential_data):
        """Verify that it will return error message if credential-id attributes are empty."""

        with self.assertRaisesRegexp(ValidationError, "Credential ID is missing"):
            self.field_instance.to_internal_value(credential_data)

    def test_to_internal_value_with_invalid_program_credential(self,):
        """Verify that it will return error message if program-id does not exist in db."""

        with self.assertRaisesRegexp(ValidationError, "ProgramCertificate matching query does not exist."):
            self.field_instance.to_internal_value({"program_id": 404})

    def test_to_internal_value_with_in_active_program_credential(self,):
        """Verify that it will return error message if program is not active in db."""
        self.program_cert.is_active = False
        self.program_cert.save()

        with self.assertRaisesRegexp(ValidationError, "ProgramCertificate matching query does not exist."):
            self.field_instance.to_internal_value({"program_id": 404})

    def test_to_internal_value_with_invalid_course_credential(self):
        """Verify that it will return error message if course-id does not exist in db."""

        with self.assertRaisesRegexp(ValidationError, "CourseCertificate matching query does not exist."):
            self.field_instance.to_internal_value({"course_id": 404, 'certificate_type': "honor"})

    def test_to_internal_value_with_valid_program_credential(self):
        """Verify that it will return credential object if program-id found in db."""

        self.assertEqual(
            self.program_cert,
            self.field_instance.to_internal_value({"program_id": self.program_cert.program_id})
        )

    def test_to_internal_value_with_valid_course_credential(self):
        """Verify that it will return credential object if course-id and certificate type
        found in db."""

        course_cert = CourseCertificateFactory()
        self.assertEqual(
            course_cert,
            self.field_instance.to_internal_value({"course_id": course_cert.course_id, "certificate_type": "honor"})
        )

    def test_to_representation_data_with_program(self):
        """Verify that it will return program certificate credential object in dict format."""

        expected_data = {"program_id": self.program_cert.program_id, "credential_id": self.program_cert.id}
        self.assertEqual(
            expected_data,
            self.field_instance.to_representation(
                self.program_cert
            )
        )

    def test_to_representation_with_course(self):
        """Verify that it will return course certificate credential object in dict format."""

        course_cert = CourseCertificateFactory()
        expected_data = {
            "course_id": course_cert.course_id,
            "credential_id": course_cert.id,
            "certificate_type": course_cert.certificate_type
        }
        self.assertEqual(
            expected_data,
            self.field_instance.to_representation(
                course_cert
            )
        )