Skip to content

Commit d472daf

Browse files
authored
Merge pull request #674 from praekeltfoundation/update-turn-migration-scripts
User tier to type update
2 parents d060500 + 8f683da commit d472daf

File tree

4 files changed

+13
-31
lines changed

4 files changed

+13
-31
lines changed

scripts/migrate_to_turn/fetch_rapidpro_contacts.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
from scripts.migrate_to_turn.process_fields import (
99
get_user_babies,
10-
get_user_tier,
1110
get_user_type,
1211
process_baby_loss_status,
1312
process_datetime,
@@ -71,7 +70,6 @@
7170
}
7271

7372
NEW_TURN_FIELD_MAPPING = {
74-
"user_tier": {"process": get_user_tier},
7573
"user_type": {"process": get_user_type},
7674
"baby_loss_status": {"process": process_baby_loss_status},
7775
"pregnancy_loss_status": {"process": process_pregnancy_loss_status},

scripts/migrate_to_turn/process_fields.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def has_active_baby(contact):
6868
return False
6969

7070

71-
def get_user_tier(contact):
71+
def get_user_type(contact):
7272
# Ineligible: We don't save anything on rapidpro to identify ineligible users
7373
# Push Basic User: Clinic code is required in rapdidpro so these don't exist
7474

@@ -79,26 +79,21 @@ def get_truthy_field(field_name):
7979
prebirth_messaging = get_truthy_field("prebirth_messaging")
8080
postbirth_messaging = get_truthy_field("postbirth_messaging")
8181

82-
user_tier = "lead"
82+
user_type = "lead"
8383

8484
if opted_out:
85-
user_tier = "deregistered_user"
85+
user_type = "deregistered_user"
8686
elif prebirth_messaging or postbirth_messaging:
87-
user_tier = "push_comprehensive_user"
87+
user_type = "push_comprehensive_user"
8888

8989
if (
9090
not prebirth_messaging
9191
and postbirth_messaging
9292
and not has_active_baby(contact)
9393
):
94-
user_tier = "alumni_user"
95-
96-
return user_tier
94+
user_type = "alumni_user"
9795

98-
99-
def get_user_type(contact):
100-
# TODO: figure out user type based on rapidpro fields
101-
return None
96+
return user_type
10297

10398

10499
def get_user_babies(contact):

scripts/migrate_to_turn/tests/test_fetch_rapidpro_contacts.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ def test_fetch_rapidpro_contacts_writes_csv(self):
9696
"minor_healthcare_consent",
9797
"opt_out_reason",
9898
"active_channel",
99-
"user_tier",
10099
"user_type",
101100
"baby_loss_status",
102101
"pregnancy_loss_status",
@@ -124,8 +123,7 @@ def test_fetch_rapidpro_contacts_writes_csv(self):
124123
"minor_healthcare_consent": "true",
125124
"opt_out_reason": "baby_loss",
126125
"active_channel": "whatsapp",
127-
"user_tier": fetch_rapidpro_contacts.get_user_tier(contact) or "",
128-
"user_type": "",
126+
"user_type": fetch_rapidpro_contacts.get_user_type(contact) or "",
129127
"baby_loss_status": "true",
130128
"pregnancy_loss_status": "",
131129
"is_new_user": "no",

scripts/migrate_to_turn/tests/test_process_fields.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from scripts.migrate_to_turn.process_fields import (
88
get_user_babies,
9-
get_user_tier,
109
get_user_type,
1110
has_active_baby,
1211
is_datetime,
@@ -181,27 +180,27 @@ def test_returns_none_for_other_reasons(self):
181180
self.assertIsNone(process_pregnancy_loss_status(contact))
182181

183182

184-
class GetUserTierTests(TestCase):
183+
class GetUserTypeTests(TestCase):
185184
def test_defaults_to_lead(self):
186185
"""
187186
Defaults to lead when no flags are set
188187
"""
189188
contact = type("Contact", (), {"fields": {}})()
190-
self.assertEqual(get_user_tier(contact), "lead")
189+
self.assertEqual(get_user_type(contact), "lead")
191190

192191
def test_opted_out_is_deregistered(self):
193192
"""
194193
Opted out users are deregistered
195194
"""
196195
contact = type("Contact", (), {"fields": {"opted_out": "TRUE"}})()
197-
self.assertEqual(get_user_tier(contact), "deregistered_user")
196+
self.assertEqual(get_user_type(contact), "deregistered_user")
198197

199198
def test_prebirth_messaging_is_push_comprehensive(self):
200199
"""
201200
Prebirth messaging users are push comprehensive
202201
"""
203202
contact = type("Contact", (), {"fields": {"prebirth_messaging": "TRUE"}})()
204-
self.assertEqual(get_user_tier(contact), "push_comprehensive_user")
203+
self.assertEqual(get_user_type(contact), "push_comprehensive_user")
205204

206205
def test_postbirth_with_active_baby_is_push_comprehensive(self):
207206
"""
@@ -211,7 +210,7 @@ def test_postbirth_with_active_baby_is_push_comprehensive(self):
211210
with mock.patch(
212211
"scripts.migrate_to_turn.process_fields.has_active_baby", return_value=True
213212
):
214-
self.assertEqual(get_user_tier(contact), "push_comprehensive_user")
213+
self.assertEqual(get_user_type(contact), "push_comprehensive_user")
215214

216215
def test_postbirth_without_active_baby_is_alumni(self):
217216
"""
@@ -221,7 +220,7 @@ def test_postbirth_without_active_baby_is_alumni(self):
221220
with mock.patch(
222221
"scripts.migrate_to_turn.process_fields.has_active_baby", return_value=False
223222
):
224-
self.assertEqual(get_user_tier(contact), "alumni_user")
223+
self.assertEqual(get_user_type(contact), "alumni_user")
225224

226225

227226
class HasActiveBabyTests(TestCase):
@@ -264,14 +263,6 @@ def test_returns_false_for_invalid_date(self, datetime_mock):
264263
self.assertFalse(has_active_baby(contact))
265264

266265

267-
class GetUserTypeTests(TestCase):
268-
def test_default(self):
269-
"""
270-
Default behavior returns None
271-
"""
272-
self.assertIsNone(get_user_type(object()))
273-
274-
275266
class GetUserBabiesTests(TestCase):
276267
def test_default(self):
277268
"""

0 commit comments

Comments
 (0)