11import pytest
2+ from model_bakery import baker
23
34from 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