예제 #1
0
 def test_with_non_duplicate_attributes(self):
     """ Verify that the function will return True if no duplicated attributes found."""
     attributes = [
         {"name": "whitelist_reason", "value": "Reason for whitelisting."},
         {"name": "grade", "value": "0.85"}
     ]
     self.assertTrue(validate_duplicate_attributes(attributes))
예제 #2
0
 def test_with_non_duplicate_attributes(self):
     """ Verify that the function will return True if no duplicated attributes found."""
     attributes = [
         {"name": "whitelist_reason", "value": "Reason for whitelisting."},
         {"name": "grade", "value": "0.85"}
     ]
     self.assertTrue(validate_duplicate_attributes(attributes))
예제 #3
0
    def test_with_duplicate_attributes(self):
        """ Verify that the function will return False if duplicated attributes found."""

        attributes = [
            {"name": "whitelist_reason", "value": "Reason for whitelisting."},
            {"name": "whitelist_reason", "value": "Reason for whitelisting."},
        ]

        self.assertFalse(validate_duplicate_attributes(attributes))
예제 #4
0
    def test_with_duplicate_attributes(self):
        """ Verify that the function will return False if duplicated attributes found."""

        attributes = [
            {"name": "whitelist_reason", "value": "Reason for whitelisting."},
            {"name": "whitelist_reason", "value": "Reason for whitelisting."},
        ]

        self.assertFalse(validate_duplicate_attributes(attributes))
예제 #5
0
 def test_with_non_duplicate_attributes(self):
     """ Verify that the function will return True if no duplicated attributes found."""
     attributes = [{
         'name': 'whitelist_reason',
         'value': 'Reason for whitelisting.'
     }, {
         'name': 'grade',
         'value': '0.85'
     }]
     self.assertTrue(validate_duplicate_attributes(attributes))
예제 #6
0
    def set_credential_attributes(self, user_credential, attributes):
        if not attributes:
            return

        if not validate_duplicate_attributes(attributes):
            raise DuplicateAttributeError("Attributes cannot be duplicated.")

        for attr in attributes:
            UserCredentialAttribute.objects.update_or_create(
                user_credential=user_credential,
                name=attr.get('name'),
                defaults={'value': attr.get('value')})
예제 #7
0
파일: issuers.py 프로젝트: edx/credentials
    def set_credential_attributes(self, user_credential, attributes):
        if not attributes:
            return

        if not validate_duplicate_attributes(attributes):
            raise DuplicateAttributeError("Attributes cannot be duplicated.")

        for attr in attributes:
            UserCredentialAttribute.objects.update_or_create(
                user_credential=user_credential,
                name=attr.get('name'),
                defaults={'value': attr.get('value')}
            )
예제 #8
0
    def test_with_duplicate_attributes(self):
        """ Verify that the function will return False if duplicated attributes found."""

        attributes = [
            {
                'name': 'whitelist_reason',
                'value': 'Reason for whitelisting.'
            },
            {
                'name': 'whitelist_reason',
                'value': 'Reason for whitelisting.'
            },
        ]

        self.assertFalse(validate_duplicate_attributes(attributes))
예제 #9
0
    def set_credential_attributes(self, user_credential, attributes):
        """
        Add attributes to the given UserCredential.

        Arguments:
            user_credential (AbstractCredential): Type of credential to issue.
            attributes (List[dict]): optional list of attributes that should be associated with the issued credential.
        """
        if not attributes:
            return

        if not validate_duplicate_attributes(attributes):
            raise DuplicateAttributeError("Attributes cannot be duplicated.")

        for attr in attributes:
            UserCredentialAttribute.objects.update_or_create(
                user_credential=user_credential, name=attr.get("name"), defaults={"value": attr.get("value")}
            )
예제 #10
0
 def validate_attributes(self, data):
     """ Check that the name attributes cannot be duplicated."""
     if not validate_duplicate_attributes(data):
         raise ValidationError("Attributes cannot be duplicated.")
     return data