|
10 | 10 | from django.utils import timezone |
11 | 11 | from django.utils.module_loading import import_string |
12 | 12 |
|
| 13 | +from fcm_django.models import DeviceType |
| 14 | + |
13 | 15 | from rest_framework import status |
14 | 16 | from rest_framework.authtoken.models import Token |
15 | 17 | from rest_framework.test import APIClient |
@@ -731,6 +733,39 @@ def test_device_without_device_id_is_updated_on_create(self, app_user): |
731 | 733 | assert device.pk == device_pk |
732 | 734 | assert Device.objects.filter(user=app_user).count() == 1 |
733 | 735 |
|
| 736 | + def test_device_with_same_fcm_token_is_updated_on_create(self, app_user, app_api_client): |
| 737 | + device = Device.objects.create( |
| 738 | + user=app_user, |
| 739 | + device_id=None, |
| 740 | + registration_id='fcm_unique_token', |
| 741 | + type=DeviceType.ANDROID, |
| 742 | + model=None, |
| 743 | + ) |
| 744 | + response = app_api_client.post( |
| 745 | + self.endpoint, |
| 746 | + data={ |
| 747 | + 'device_id': 'unique_id', |
| 748 | + 'fcm_token': 'fcm_unique_token', |
| 749 | + 'type': device.type, |
| 750 | + 'manufacturer': device.manufacturer, |
| 751 | + 'model': 'new_model', |
| 752 | + 'os': { |
| 753 | + 'name': 'test_os_name', |
| 754 | + 'version': 'test_os_version' |
| 755 | + } |
| 756 | + }, |
| 757 | + format='json' |
| 758 | + ) |
| 759 | + assert response.status_code == status.HTTP_201_CREATED |
| 760 | + assert Device.objects.filter(user=app_user).count() == 1 |
| 761 | + device.refresh_from_db() |
| 762 | + assert device.device_id == 'unique_id' |
| 763 | + assert device.model == 'new_model' |
| 764 | + assert device.registration_id == 'fcm_unique_token' |
| 765 | + assert device.os_name == 'test_os_name' |
| 766 | + assert device.os_version == 'test_os_version' |
| 767 | + |
| 768 | + |
734 | 769 | @pytest.mark.django_db |
735 | 770 | @pytest.mark.usefixtures("taxa") |
736 | 771 | class TestIdentificationTaskAnnotationsApi: |
|
0 commit comments