def test_device_id_validation_pass(self):
		serializer = GCMDeviceSerializer(data={
			"registration_id": "foobar",
			"name": "Galaxy Note 3",
			"device_id": "0x1031af3b",
		})
		self.assertTrue(serializer.is_valid())
	def test_device_id_validation_fail_bad_hex(self):
		serializer = GCMDeviceSerializer(data={
			"registration_id": "foobar",
			"name": "Galaxy Note 3",
			"device_id": "0x10r",
		})
		self.assertFalse(serializer.is_valid())
		self.assertEqual(serializer.errors, GCM_DRF_INVALID_HEX_ERROR)
 def test_device_id_validation_pass(self):
     serializer = GCMDeviceSerializer(
         data={
             "registration_id": "foobar",
             "name": "Galaxy Note 3",
             "device_id": "0x1031af3b",
         })
     self.assertTrue(serializer.is_valid())
	def test_device_id_validation_fail_out_of_range(self):
		serializer = GCMDeviceSerializer(data={
			"registration_id": "foobar",
			"name": "Galaxy Note 3",
			"device_id": "10000000000000000",  # 2**64
		})
		self.assertFalse(serializer.is_valid())
		self.assertEqual(serializer.errors, GCM_DRF_OUT_OF_RANGE_ERROR)
 def test_device_id_validation_fail_out_of_range(self):
     serializer = GCMDeviceSerializer(
         data={
             "registration_id": "foobar",
             "name": "Galaxy Note 3",
             "device_id": "10000000000000000",  # 2**64
         })
     self.assertFalse(serializer.is_valid())
     self.assertEqual(serializer.errors, GCM_DRF_OUT_OF_RANGE_ERROR)
 def test_device_id_validation_fail_bad_hex(self):
     serializer = GCMDeviceSerializer(
         data={
             "registration_id": "foobar",
             "name": "Galaxy Note 3",
             "device_id": "0x10r",
         })
     self.assertFalse(serializer.is_valid())
     self.assertEqual(serializer.errors, GCM_DRF_INVALID_HEX_ERROR)
	def test_device_id_validation_value_between_signed_unsigned_64b_int_maximums(self):
		"""
		2**63 < 0xe87a4e72d634997c < 2**64
		"""
		serializer = GCMDeviceSerializer(data={
			"registration_id": "foobar",
			"name": "Nexus 5",
			"device_id": "e87a4e72d634997c",
		})
		self.assertTrue(serializer.is_valid())
Пример #8
0
	def test_device_id_validation_value_between_signed_unsigned_64b_int_maximums(self):
		"""
		2**63 < 0xe87a4e72d634997c < 2**64
		"""
		serializer = GCMDeviceSerializer(data={
			"registration_id": "foobar",
			"name": "Nexus 5",
			"device_id": "e87a4e72d634997c",
			"application_id": "XXXXXXXXXXXXXXXXXXXX",
		})
		self.assertTrue(serializer.is_valid())
Пример #9
0
class ProfileSerializer(serializers.ModelSerializer):
    # user = serializers.ReadOnlyField(source='user.username')
    device = GCMDeviceSerializer(read_only=True)

    # device_id = serializers.ReadOnlyField(source='device.device_id')
    # registration_id = serializers.ReadOnlyField(source='device.registration_id')

    class Meta:
        model = Profile
        fields = ('tags', 'device')
	def test_registration_id_unique(self):
		"""Validate that a duplicate registration id raises a validation error."""

		# add a device
		serializer = GCMDeviceSerializer(data={
			"registration_id": "foobar",
			"name": "Galaxy Note 3",
			"device_id": "0x1031af3b",
		})
		serializer.is_valid(raise_exception=True)
		obj = serializer.save()

		# ensure updating the same object works
		serializer = GCMDeviceSerializer(obj, data={
			"registration_id": "foobar",
			"name": "Galaxy Note 5",
			"device_id": "0x1031af3b",
		})
		serializer.is_valid(raise_exception=True)
		obj = serializer.save()

		# try to add a new device with the same token
		serializer = GCMDeviceSerializer(data={
			"registration_id": "foobar",
			"name": "Galaxy Note 3",
			"device_id": "0xdeadbeaf",
		})

		with self.assertRaises(ValidationError):
			serializer.is_valid(raise_exception=True)
Пример #11
0
    def test_registration_id_unique(self):
        """Validate that a duplicate registration id raises a validation error."""

        # add a device
        serializer = GCMDeviceSerializer(
            data={
                "registration_id": "foobar",
                "name": "Galaxy Note 3",
                "device_id": "0x1031af3b",
                "application_id": "XXXXXXXXXXXXXXXXXXXX",
            })
        serializer.is_valid(raise_exception=True)
        obj = serializer.save()

        # ensure updating the same object works
        serializer = GCMDeviceSerializer(obj,
                                         data={
                                             "registration_id":
                                             "foobar",
                                             "name":
                                             "Galaxy Note 5",
                                             "device_id":
                                             "0x1031af3b",
                                             "application_id":
                                             "XXXXXXXXXXXXXXXXXXXX",
                                         })
        serializer.is_valid(raise_exception=True)
        obj = serializer.save()

        # try to add a new device with the same token
        serializer = GCMDeviceSerializer(
            data={
                "registration_id": "foobar",
                "name": "Galaxy Note 3",
                "device_id": "0xdeadbeaf",
                "application_id": "XXXXXXXXXXXXXXXXXXXX",
            })

        with self.assertRaises(ValidationError):
            serializer.is_valid(raise_exception=True)