Skip to content

Commit

Permalink
feat: expose display_name via REST API. ENT-7595
Browse files Browse the repository at this point in the history
  • Loading branch information
iloveagent57 committed Aug 24, 2023
1 parent dc487fd commit 2c4e315
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
13 changes: 13 additions & 0 deletions enterprise_access/apps/api/serializers/subsidy_access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Meta:
fields = [
'uuid',
'policy_type',
'display_name',
'description',
'active',
'enterprise_customer_uuid',
Expand Down Expand Up @@ -73,6 +74,7 @@ class Meta:
fields = [
'uuid',
'policy_type',
'display_name',
'description',
'active',
'enterprise_customer_uuid',
Expand All @@ -89,6 +91,11 @@ class Meta:
read_only_fields = ['uuid']
extra_kwargs = {
'uuid': {'read_only': True},
'display_name': {
'min_length': None,
'max_length': 512,
'trim_whitespace': True,
},
'description': {
'allow_blank': False,
'min_length': None,
Expand Down Expand Up @@ -283,6 +290,7 @@ class SubsidyAccessPolicyUpdateRequestSerializer(serializers.ModelSerializer):
class Meta:
model = SubsidyAccessPolicy
fields = (
'display_name',
'description',
'active',
'catalog_uuid',
Expand All @@ -296,6 +304,11 @@ class Meta:
'is_subsidy_active',
)
extra_kwargs = {
'display_name': {
'min_length': None,
'max_length': 512,
'trim_whitespace': True,
},
'description': {
'required': False,
'allow_blank': False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ def setUpTestData(cls):
cls.enterprise_uuid = TEST_ENTERPRISE_UUID

cls.redeemable_policy = PerLearnerEnrollmentCapLearnerCreditAccessPolicyFactory(
display_name='A redeemable policy',
enterprise_customer_uuid=cls.enterprise_uuid,
spend_limit=3,
active=True,
)
cls.non_redeemable_policy = PerLearnerEnrollmentCapLearnerCreditAccessPolicyFactory(
display_name='A non-redeemable policy',
enterprise_customer_uuid=cls.enterprise_uuid,
spend_limit=0,
active=True,
Expand Down Expand Up @@ -253,6 +255,7 @@ def test_detail_view(self, role_context_dict):
'access_method': 'direct',
'active': True,
'catalog_uuid': str(self.redeemable_policy.catalog_uuid),
'display_name': self.redeemable_policy.display_name,
'description': '',
'enterprise_customer_uuid': str(self.enterprise_uuid),
'per_learner_enrollment_limit': self.redeemable_policy.per_learner_enrollment_limit,
Expand Down Expand Up @@ -295,6 +298,7 @@ def test_list_view(self, role_context_dict):
'access_method': 'direct',
'active': True,
'catalog_uuid': str(self.non_redeemable_policy.catalog_uuid),
'display_name': self.non_redeemable_policy.display_name,
'description': '',
'enterprise_customer_uuid': str(self.enterprise_uuid),
'per_learner_enrollment_limit': self.non_redeemable_policy.per_learner_enrollment_limit,
Expand All @@ -311,6 +315,7 @@ def test_list_view(self, role_context_dict):
'access_method': 'direct',
'active': True,
'catalog_uuid': str(self.redeemable_policy.catalog_uuid),
'display_name': self.redeemable_policy.display_name,
'description': '',
'enterprise_customer_uuid': str(self.enterprise_uuid),
'per_learner_enrollment_limit': self.redeemable_policy.per_learner_enrollment_limit,
Expand Down Expand Up @@ -370,6 +375,7 @@ def test_destroy_view(self, request_payload, expected_change_reason):
'access_method': 'direct',
'active': False,
'catalog_uuid': str(self.redeemable_policy.catalog_uuid),
'display_name': self.redeemable_policy.display_name,
'description': '',
'enterprise_customer_uuid': str(self.enterprise_uuid),
'per_learner_enrollment_limit': self.redeemable_policy.per_learner_enrollment_limit,
Expand Down Expand Up @@ -410,12 +416,14 @@ def test_update_views(self, is_patch):

policy_for_edit = PerLearnerSpendCapLearnerCreditAccessPolicyFactory(
enterprise_customer_uuid=self.enterprise_uuid,
display_name='old display_name',
spend_limit=5,
active=False,
)

request_payload = {
'description': 'the new description',
'display_name': 'new display_name',
'active': True,
'catalog_uuid': str(uuid4()),
'subsidy_uuid': str(uuid4()),
Expand All @@ -437,6 +445,7 @@ def test_update_views(self, is_patch):
'access_method': AccessMethods.ASSIGNED,
'active': True,
'catalog_uuid': request_payload['catalog_uuid'],
'display_name': request_payload['display_name'],
'description': request_payload['description'],
'enterprise_customer_uuid': str(self.enterprise_uuid),
'per_learner_enrollment_limit': None,
Expand Down Expand Up @@ -643,6 +652,7 @@ def test_create_view(self, policy_type, extra_fields, expected_response_code, ex
# Test the retrieve endpoint
payload = {
'policy_type': policy_type,
'display_name': 'created policy',
'description': 'test description',
'active': True,
'enterprise_customer_uuid': str(TEST_ENTERPRISE_UUID),
Expand Down Expand Up @@ -697,6 +707,7 @@ def test_idempotent_create_view(self, policy_type, extra_fields, expected_respon
subsidy_uuid = str(uuid4())
payload = {
'policy_type': policy_type,
'display_name': 'new policy',
'description': 'test description',
'active': True,
'enterprise_customer_uuid': enterprise_customer_uuid,
Expand Down

0 comments on commit 2c4e315

Please sign in to comment.