|
1 | 1 | import json |
| 2 | +import uuid |
2 | 3 | from unittest.mock import Mock, patch, call |
3 | 4 |
|
4 | 5 | from django.test import TestCase |
@@ -458,6 +459,28 @@ def test_update(self): |
458 | 459 | self.assertEqual(user_history.change_messages['password'], UserChangeMessage.password_reset()['password']) |
459 | 460 | self.assertEqual(user_history.changed_via, USER_CHANGE_VIA_API) |
460 | 461 |
|
| 462 | + def test_cant_update_missing_user(self): |
| 463 | + response = self._assert_auth_post_resource(self.single_endpoint(uuid.uuid4().hex), |
| 464 | + json.dumps({"first_name": "test"}), |
| 465 | + content_type='application/json', |
| 466 | + method='PUT') |
| 467 | + |
| 468 | + assert response.status_code == 404, response.content |
| 469 | + |
| 470 | + def test_cant_update_user_in_another_domain(self): |
| 471 | + not_my_user = CommCareUser.create(domain='not-my-project', username="theirs", |
| 472 | + password="qwer1234", created_by=None, created_via=None) |
| 473 | + self.addCleanup(not_my_user.delete, 'not-my-project', deleted_by=None) |
| 474 | + first_name_before = not_my_user.first_name |
| 475 | + |
| 476 | + response = self._assert_auth_post_resource(self.single_endpoint(not_my_user._id), |
| 477 | + json.dumps({"first_name": "mine now"}), |
| 478 | + content_type='application/json', |
| 479 | + method='PUT') |
| 480 | + |
| 481 | + assert response.status_code == 404, response.content |
| 482 | + assert CommCareUser.get(not_my_user._id).first_name == first_name_before |
| 483 | + |
461 | 484 | def test_update_fails(self): |
462 | 485 | user = CommCareUser.create(domain=self.domain.name, username="test", password="qwer1234", |
463 | 486 | created_by=None, created_via=None, phone_number="50253311398") |
|
0 commit comments