|
| 1 | + |
| 2 | +from __future__ import absolute_import |
| 3 | + |
| 4 | +import pytest |
| 5 | +from django.db import IntegrityError |
| 6 | +from django.test import TestCase |
| 7 | +from push_notifications.models import APNSDevice, GCMDevice, WNSDevice, WebPushDevice |
| 8 | + |
| 9 | + |
| 10 | +class GCMModelTestCase(TestCase): |
| 11 | + def test_throws_error_for_same_gcm_registration_id(self): |
| 12 | + device = GCMDevice.objects.create( |
| 13 | + registration_id="unique_id", cloud_message_type="GCM" |
| 14 | + ) |
| 15 | + assert device.id is not None |
| 16 | + with pytest.raises(IntegrityError) as excinfo: |
| 17 | + GCMDevice.objects.create( |
| 18 | + registration_id="unique_id", cloud_message_type="GCM" |
| 19 | + ) |
| 20 | + assert "UNIQUE constraint failed" in str(excinfo.value) |
| 21 | + |
| 22 | + def test_throws_error_for_same_apns_registration_id(self): |
| 23 | + device = APNSDevice.objects.create( |
| 24 | + registration_id="unique_id", |
| 25 | + ) |
| 26 | + assert device.id is not None |
| 27 | + with pytest.raises(IntegrityError) as excinfo: |
| 28 | + APNSDevice.objects.create( |
| 29 | + registration_id="unique_id", |
| 30 | + ) |
| 31 | + assert "UNIQUE constraint failed" in str(excinfo.value) |
| 32 | + |
| 33 | + def test_throws_error_for_same_wns_registration_id(self): |
| 34 | + device = WNSDevice.objects.create( |
| 35 | + registration_id="unique_id", |
| 36 | + ) |
| 37 | + assert device.id is not None |
| 38 | + with pytest.raises(IntegrityError) as excinfo: |
| 39 | + WNSDevice.objects.create( |
| 40 | + registration_id="unique_id", |
| 41 | + ) |
| 42 | + assert "UNIQUE constraint failed" in str(excinfo.value) |
| 43 | + |
| 44 | + def test_throws_error_for_same_web_registration_id(self): |
| 45 | + device = WebPushDevice.objects.create( |
| 46 | + registration_id="unique_id", |
| 47 | + ) |
| 48 | + assert device.id is not None |
| 49 | + with pytest.raises(IntegrityError) as excinfo: |
| 50 | + WebPushDevice.objects.create( |
| 51 | + registration_id="unique_id", |
| 52 | + ) |
| 53 | + assert "UNIQUE constraint failed" in str(excinfo.value) |
0 commit comments