Skip to content

Commit ed098a2

Browse files
Merge pull request #565 from ayobi/master
scrub interested users
2 parents 5fd0c39 + 60222dd commit ed098a2

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed

microsetta_private_api/admin/admin_impl.py

+3
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ def delete_account(account_id, token_info):
836836
src_repo = SourceRepo(t)
837837
samp_repo = SampleRepo(t)
838838
sar_repo = SurveyAnswersRepo(t)
839+
interested_users_repo = InterestedUserRepo(t)
839840

840841
acct = acct_repo.get_account(account_id)
841842
if acct is None:
@@ -873,6 +874,8 @@ def delete_account(account_id, token_info):
873874

874875
acct_repo.scrub(account_id)
875876

877+
interested_users_repo.scrub(acct.email)
878+
876879
t.commit()
877880

878881
return None, 204

microsetta_private_api/repo/interested_user_repo.py

+44
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def update_interested_user(self, interested_user):
6666
"state = %s, "
6767
"postal_code = %s, "
6868
"country = %s, "
69+
"latitude = %s, "
70+
"longitude = %s, "
71+
"confirm_consent = %s, "
6972
"address_checked = %s, "
7073
"address_valid = %s, "
7174
"residential_address = %s, "
@@ -82,6 +85,9 @@ def update_interested_user(self, interested_user):
8285
interested_user.state,
8386
interested_user.postal_code,
8487
interested_user.country,
88+
interested_user.latitude,
89+
interested_user.longitude,
90+
interested_user.confirm_consent,
8591
interested_user.address_checked,
8692
interested_user.address_valid,
8793
interested_user.residential_address,
@@ -207,3 +213,41 @@ def verify_address(self, interested_user_id):
207213
(interested_user_id,)
208214
)
209215
return False
216+
217+
def get_interested_user_by_just_email(self, email):
218+
with self._transaction.dict_cursor() as cur:
219+
cur.execute(
220+
"SELECT * FROM campaign.interested_users "
221+
"WHERE lower(email) = lower(%s)",
222+
(email,)
223+
)
224+
rs = cur.fetchall()
225+
return [__class__._row_to_interested_user(r) for r in rs]
226+
227+
def scrub(self, interested_user_email):
228+
interested_users = self. \
229+
get_interested_user_by_just_email(interested_user_email)
230+
231+
for interested_user in interested_users:
232+
interested_user.first_name = "scrubbed"
233+
interested_user.last_name = "scrubbed"
234+
interested_user.email = "scrubbed"
235+
interested_user.phone = "scrubbed"
236+
interested_user.address_1 = "scrubbed"
237+
interested_user.address_2 = "scrubbed"
238+
interested_user.address_3 = "scrubbed"
239+
interested_user.city = "scrubbed"
240+
interested_user.state = "scrubbed"
241+
interested_user.postal_code = "scrubbed"
242+
interested_user.country = "scrubbed"
243+
interested_user.latitude = None
244+
interested_user.longitude = None
245+
interested_user.confirm_consent = False
246+
interested_user.ip_address = "scrubbed"
247+
interested_user.address_checked = False
248+
interested_user.address_valid = False
249+
interested_user.residential_address = False
250+
251+
if not self.update_interested_user(interested_user):
252+
raise RepoException("Error scrubbing interested user: "
253+
+ interested_user.interested_user_id)

microsetta_private_api/repo/tests/test_interested_user_repo.py

+44
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,50 @@ def test_opt_out_interested_user(self):
324324
# Verify that the user is now opted out
325325
self.assertFalse(i_u.confirm_consent)
326326

327+
def test_scrub_interested_users_success(self):
328+
# Create a test interested user
329+
dummy_user = {
330+
"campaign_id": self.test_campaign_id,
331+
"first_name": "Test",
332+
"last_name": "McTesterson",
333+
"email": "[email protected]"
334+
}
335+
interested_user = InterestedUser.from_dict(dummy_user)
336+
with Transaction() as t:
337+
interested_user_repo = InterestedUserRepo(t)
338+
iuid = interested_user_repo.insert_interested_user(interested_user)
339+
340+
# Scrub the interested user with the right email
341+
interested_user_repo.scrub("[email protected]")
342+
343+
# Verify that the interested user is scrubbed
344+
obs = interested_user_repo.get_interested_user_by_id(iuid)
345+
self.assertEqual(obs.first_name, 'scrubbed')
346+
self.assertEqual(obs.last_name, 'scrubbed')
347+
self.assertEqual(obs.email, 'scrubbed')
348+
349+
def test_scrub_interested_users_failure(self):
350+
# Create a test interested user
351+
dummy_user = {
352+
"campaign_id": self.test_campaign_id,
353+
"first_name": "Test",
354+
"last_name": "McTesterson",
355+
"email": "[email protected]"
356+
}
357+
interested_user = InterestedUser.from_dict(dummy_user)
358+
with Transaction() as t:
359+
interested_user_repo = InterestedUserRepo(t)
360+
iuid = interested_user_repo.insert_interested_user(interested_user)
361+
362+
# Scrub the interested user with the wrong email
363+
interested_user_repo.scrub("[email protected]")
364+
365+
# Verify that the interested user isn't scrubbed
366+
obs = interested_user_repo.get_interested_user_by_id(iuid)
367+
self.assertEqual(obs.first_name, 'Test')
368+
self.assertEqual(obs.last_name, 'McTesterson')
369+
self.assertEqual(obs.email, '[email protected]')
370+
327371

328372
if __name__ == '__main__':
329373
unittest.main()

0 commit comments

Comments
 (0)