Changeset View
Changeset View
Standalone View
Standalone View
tests/test_webhooks.py
| Show First 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | def test_change_email(self): | ||||
| expected_status=204) | expected_status=204) | ||||
| # Check the effect on the user | # Check the effect on the user | ||||
| db_user = self.fetch_user_from_db(self.uid) | db_user = self.fetch_user_from_db(self.uid) | ||||
| self.assertEqual('new.address+here-there@email.address', db_user['email']) | self.assertEqual('new.address+here-there@email.address', db_user['email']) | ||||
| self.assertEqual('ကြယ်ဆွတ်', db_user['full_name']) | self.assertEqual('ကြယ်ဆွတ်', db_user['full_name']) | ||||
| self.assertEqual(['subscriber'], db_user['roles']) | self.assertEqual(['subscriber'], db_user['roles']) | ||||
| def test_date_deletion_requested_is_set(self): | |||||
| payload = {'id': 1112333, | |||||
| 'old_email': 'old@email.address', | |||||
| 'full_name': 'ကြယ်ဆွတ်', | |||||
| 'email': 'new.address+here-there@email.address', | |||||
| 'roles': ['cloud_subscriber'], | |||||
| 'date_deletion_requested': '2020-12-31T23:02:03+00:00'} | |||||
| as_json = json.dumps(payload).encode() | |||||
| mac = hmac.new(self.hmac_secret, | |||||
| as_json, hashlib.sha256) | |||||
| self.post('/api/webhooks/user-modified', | |||||
| data=as_json, | |||||
| content_type='application/json', | |||||
| headers={'X-Webhook-HMAC': mac.hexdigest()}, | |||||
| expected_status=204) | |||||
| # Check the effect on the user | |||||
| db_user = self.fetch_user_from_db(self.uid) | |||||
| self.assertIsNone(db_user['email']) | |||||
| self.assertIsNone(db_user['full_name']) | |||||
| self.assertIsNone(db_user['username']) | |||||
| self.assertTrue(db_user['_deleted']) | |||||
| def test_change_email_unknown_old(self): | def test_change_email_unknown_old(self): | ||||
| payload = {'id': 1112333, | payload = {'id': 1112333, | ||||
| 'old_email': 'ancient@email.address', | 'old_email': 'ancient@email.address', | ||||
| 'full_name': 'ကြယ်ဆွတ်', | 'full_name': 'ကြယ်ဆွတ်', | ||||
| 'email': 'old@email.address', | 'email': 'old@email.address', | ||||
| 'roles': ['cloud_demo']} | 'roles': ['cloud_demo']} | ||||
| as_json = json.dumps(payload).encode() | as_json = json.dumps(payload).encode() | ||||
| mac = hmac.new(self.hmac_secret, | mac = hmac.new(self.hmac_secret, | ||||
| ▲ Show 20 Lines • Show All 386 Lines • Show Last 20 Lines | |||||