Skip to content

Commit 62195ea

Browse files
renzonrenzon
authored andcommitted
Fixed bug on Subscription synchronization of changing names
Fixed #3781
1 parent 4efeef2 commit 62195ea

2 files changed

Lines changed: 36 additions & 4 deletions

File tree

‎pythonpro/memberkit/facade.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
def synchronize_subscription_types() -> List[SubscriptionType]:
88
return [
9-
SubscriptionType.objects.update_or_create(id=dct['id'], name=dct['name'])[0]
9+
SubscriptionType.objects.update_or_create(
10+
id=dct['id'],
11+
defaults={'name': dct['name']}
12+
)[0]
1013
for dct in api.list_membership_levels()
1114
]
1215

‎pythonpro/memberkit/tests/test_subscription_type_synchronization.py‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import pytest
2+
from model_bakery import baker
23

34
from pythonpro.memberkit import api, facade
5+
from pythonpro.memberkit.models import SubscriptionType
46

57

68
@pytest.fixture
@@ -24,15 +26,18 @@ def test_syncronize_memberkit_subscriptions(responses, api_key, settings):
2426
api_response = [
2527
{
2628
'classroom_ids': [39668, 39731, 40566],
27-
'id': 13, 'name': 'Clientes', 'trial_period': 0},
29+
'id': 13, 'name': 'Clientes', 'trial_period': 0
30+
},
2831
{
2932
'classroom_ids': [40531, 40532, 40533, 40534, 40535, 39668, 39731, 40566],
3033
'id': 14,
31-
'name': 'Bootcampers', 'trial_period': 0},
34+
'name': 'Bootcampers', 'trial_period': 0
35+
},
3236
{
3337
'classroom_ids': [40531, 40532, 40533, 40534, 40535, 39668, 39731, 40566],
3438
'id': 15, 'name': 'Membros',
35-
'trial_period': 0},
39+
'trial_period': 0
40+
},
3641
{
3742
'classroom_ids': [40531, 40532, 39731, 40566],
3843
'id': 16, 'name': 'Webdevs', 'trial_period': 0},
@@ -62,3 +67,27 @@ def test_syncronize_memberkit_subscriptions(responses, api_key, settings):
6267
subscription_types = facade.synchronize_subscription_types()
6368

6469
assert id_name_dct == {s.id: s.name for s in subscription_types}
70+
71+
72+
def test_changes_on_subscription_name(responses, api_key, settings):
73+
settings.MEMBERKIT_ON = True
74+
subscription_id = 13
75+
old_name = 'Clientes'
76+
new_name = 'Clientes Alterados'
77+
api_response = [
78+
{
79+
'classroom_ids': [39668, 39731, 40566],
80+
'id': subscription_id, 'name': new_name, 'trial_period': 0
81+
},
82+
]
83+
responses.add(
84+
responses.GET,
85+
f'https://memberkit.com.br/api/v1/membership_levels?api_key={api_key}',
86+
json=api_response
87+
)
88+
89+
subscription_type = baker.make(SubscriptionType, id=subscription_id, name=old_name)
90+
91+
facade.synchronize_subscription_types()
92+
subscription_type.refresh_from_db()
93+
assert subscription_type.name == new_name

0 commit comments

Comments
 (0)