Example #1
0
    def test_course_credential(self):
        request = APIRequestFactory().get('/')
        course_certificate = CourseCertificateFactory()
        user_credential = UserCredentialFactory(credential=course_certificate)
        user_credential_attribute = UserCredentialAttributeFactory(user_credential=user_credential)

        expected_url = 'http://testserver{}'.format(
            reverse('credentials:render', kwargs={'uuid': user_credential.uuid.hex}))

        expected = {
            'username': user_credential.username,
            'uuid': str(user_credential.uuid),
            'credential': {
                'type': 'course-run',
                'course_run_key': course_certificate.course_id,
                'mode': course_certificate.certificate_type,
            },
            'download_url': user_credential.download_url,
            'status': user_credential.status,
            'attributes': [
                {
                    'name': user_credential_attribute.name,
                    'value': user_credential_attribute.value
                }
            ],
            'created': user_credential.created.strftime(api_settings.DATETIME_FORMAT),
            'modified': user_credential.modified.strftime(api_settings.DATETIME_FORMAT),
            'certificate_url': expected_url
        }

        actual = UserCredentialSerializer(user_credential, context={'request': request}).data
        self.assertEqual(actual, expected)
Example #2
0
 def test_data(self):
     """ Verify the serializer serializes a UserCredential exactly as UserCredentialSerializer does. """
     request = APIRequestFactory().get('/')
     user_credential = UserCredentialFactory()
     actual = UserCredentialCreationSerializer(user_credential, context={'request': request}).data
     expected = UserCredentialSerializer(user_credential, context={'request': request}).data
     self.assertEqual(actual, expected)
Example #3
0
    def test_course_credential(self):
        request = APIRequestFactory().get("/")
        course_certificate = CourseCertificateFactory()
        user_credential = UserCredentialFactory(credential=course_certificate)
        user_credential_attribute = UserCredentialAttributeFactory(user_credential=user_credential)

        expected_url = "http://testserver{}".format(
            reverse("credentials:render", kwargs={"uuid": user_credential.uuid.hex})
        )

        expected = {
            "username": user_credential.username,
            "uuid": str(user_credential.uuid),
            "credential": {
                "type": "course-run",
                "course_run_key": course_certificate.course_id,
                "mode": course_certificate.certificate_type,
            },
            "download_url": user_credential.download_url,
            "status": user_credential.status,
            "attributes": [{"name": user_credential_attribute.name, "value": user_credential_attribute.value}],
            "created": user_credential.created.strftime(api_settings.DATETIME_FORMAT),
            "modified": user_credential.modified.strftime(api_settings.DATETIME_FORMAT),
            "certificate_url": expected_url,
        }

        actual = UserCredentialSerializer(user_credential, context={"request": request}).data
        self.assertEqual(actual, expected)
Example #4
0
 def serialize_user_credential(self, user_credential, many=False):
     """ Serialize the given UserCredential object(s). """
     request = APIRequestFactory(SERVER_NAME=self.site.domain).get('/')
     return UserCredentialSerializer(user_credential,
                                     context={
                                         'request': request
                                     },
                                     many=many).data
Example #5
0
    def _generate_results(self, exists=True):
        if exists:
            return {
                "count": 1,
                "next": None,
                "previous": None,
                "results": [UserCredentialSerializer(self.user_credential, context={"request": self.request}).data],
            }

        return {"count": 0, "next": None, "previous": None, "results": []}
Example #6
0
    def _generate_results(self, exists=True):
        if exists:
            return {
                'count':
                1,
                'next':
                None,
                'previous':
                None,
                'results': [
                    UserCredentialSerializer(self.user_credential,
                                             context={
                                                 'request': self.request
                                             }).data
                ]
            }

        return {'count': 0, 'next': None, 'previous': None, 'results': []}