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))
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))
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))
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')})
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')} )
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))
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")} )
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