def test_not_equal_on_equal(self): """ Test that the inequality operator returns False when comparing two Check response payloads with the same data. """ a = payloads.CheckResponsePayload() b = payloads.CheckResponsePayload() self.assertFalse(a != b) self.assertFalse(b != a) a = payloads.CheckResponsePayload( unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038', usage_limits_count=200, cryptographic_usage_mask=4, lease_time=1511882848 ) b = payloads.CheckResponsePayload( unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038', usage_limits_count=200, cryptographic_usage_mask=4, lease_time=1511882848 ) self.assertFalse(a != b) self.assertFalse(b != a)
def test_not_equal_on_not_equal_usage_limits_count(self): """ Test that the inequality operator returns True when comparing two Check response payloads with different usage limits counts. """ a = payloads.CheckResponsePayload( usage_limits_count=0 ) b = payloads.CheckResponsePayload( usage_limits_count=1 ) self.assertTrue(a != b) self.assertTrue(b != a)
def test_not_equal_on_not_equal_unique_identifier(self): """ Test that the inequality operator returns True when comparing two Check response payloads with different unique identifiers. """ a = payloads.CheckResponsePayload( unique_identifier='a' ) b = payloads.CheckResponsePayload( unique_identifier='b' ) self.assertTrue(a != b) self.assertTrue(b != a)
def test_not_equal_on_not_equal_cryptographic_usage_mask(self): """ Test that the inequality operator returns True when comparing two Check response payloads with different cryptographic usage masks. """ a = payloads.CheckResponsePayload( cryptographic_usage_mask=4 ) b = payloads.CheckResponsePayload( cryptographic_usage_mask=12 ) self.assertTrue(a != b) self.assertTrue(b != a)
def test_not_equal_on_not_equal_lease_time(self): """ Test that the inequality operator returns True when comparing two Check response payloads with different lease times. """ a = payloads.CheckResponsePayload( lease_time=0 ) b = payloads.CheckResponsePayload( lease_time=1511882848 ) self.assertTrue(a != b) self.assertTrue(b != a)
def test_not_equal_on_type_mismatch(self): """ Test that the inequality operator returns True when comparing two Check response payloads with different types. """ a = payloads.CheckResponsePayload() b = 'invalid' self.assertTrue(a != b) self.assertTrue(b != a)
def test_write_empty(self): """ Test that an empty Check response payload can be written to a data stream. """ payload = payloads.CheckResponsePayload() stream = utils.BytearrayStream() payload.write(stream) self.assertEqual(len(self.empty_encoding), len(stream)) self.assertEqual(str(self.empty_encoding), str(stream))
def test_init(self): """ Test that a Check response payload can be constructed with no arguments. """ payload = payloads.CheckResponsePayload() self.assertEqual(None, payload.unique_identifier) self.assertEqual(None, payload.usage_limits_count) self.assertEqual(None, payload.cryptographic_usage_mask) self.assertEqual(None, payload.lease_time)
def test_write_partial(self): """ Test that a partial Check response payload can be written to a data stream. """ payload = payloads.CheckResponsePayload( unique_identifier='2c23217e-f53c-4bdf-ad0a-58a31fd3d4b6', usage_limits_count=500 ) stream = utils.BytearrayStream() payload.write(stream) self.assertEqual(len(self.partial_encoding), len(stream)) self.assertEqual(str(self.partial_encoding), str(stream))
def test_write(self): """ Test that a Check response payload can be written to a data stream. """ payload = payloads.CheckResponsePayload( unique_identifier='2c23217e-f53c-4bdf-ad0a-58a31fd3d4b6', usage_limits_count=500, cryptographic_usage_mask=12, lease_time=0 ) stream = utils.BytearrayStream() payload.write(stream) self.assertEqual(len(self.full_encoding), len(stream)) self.assertEqual(str(self.full_encoding), str(stream))
def test_read_empty(self): """ Test that a Check response payload can be read from an empty data stream. """ payload = payloads.CheckResponsePayload() self.assertEqual(None, payload.unique_identifier) self.assertEqual(None, payload.usage_limits_count) self.assertEqual(None, payload.cryptographic_usage_mask) self.assertEqual(None, payload.lease_time) payload.read(self.empty_encoding) self.assertEqual(None, payload.unique_identifier) self.assertEqual(None, payload.usage_limits_count) self.assertEqual(None, payload.cryptographic_usage_mask) self.assertEqual(None, payload.lease_time)
def test_init_with_args(self): """ Test that a Check response payload can be constructed with valid values. """ payload = payloads.CheckResponsePayload( unique_identifier='00000000-1111-2222-3333-444444444444', usage_limits_count=10, cryptographic_usage_mask=12, lease_time=1000000000 ) self.assertEqual( '00000000-1111-2222-3333-444444444444', payload.unique_identifier ) self.assertEqual(10, payload.usage_limits_count) self.assertEqual(12, payload.cryptographic_usage_mask) self.assertEqual(1000000000, payload.lease_time)
def test_str(self): """ Test that str can be applied to a Check response payload """ payload = payloads.CheckResponsePayload( unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038', usage_limits_count=1000, cryptographic_usage_mask=8, lease_time=1511882898 ) expected = str({ 'unique_identifier': '49a1ca88-6bea-4fb2-b450-7e58802c3038', 'usage_limits_count': 1000, 'cryptographic_usage_mask': 8, 'lease_time': 1511882898 }) observed = str(payload) self.assertEqual(expected, observed)
def test_read(self): """ Test that a Check response payload can be read from a data stream. """ payload = payloads.CheckResponsePayload() self.assertEqual(None, payload.unique_identifier) self.assertEqual(None, payload.usage_limits_count) self.assertEqual(None, payload.cryptographic_usage_mask) self.assertEqual(None, payload.lease_time) payload.read(self.full_encoding) self.assertEqual( '2c23217e-f53c-4bdf-ad0a-58a31fd3d4b6', payload.unique_identifier ) self.assertEqual(500, payload.usage_limits_count) self.assertEqual(12, payload.cryptographic_usage_mask) self.assertEqual(0, payload.lease_time)
def test_repr(self): """ Test that repr can be applied to a Check response payload. """ payload = payloads.CheckResponsePayload( unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038', usage_limits_count=1000, cryptographic_usage_mask=8, lease_time=1511882898 ) expected = ( "CheckResponsePayload(" "unique_identifier='49a1ca88-6bea-4fb2-b450-7e58802c3038', " "usage_limits_count=1000, " "cryptographic_usage_mask=8, " "lease_time=1511882898)" ) observed = repr(payload) self.assertEqual(expected, observed)
def test_invalid_unique_identifier(self): """ Test that a TypeError is raised when an invalid value is used to set the unique identifier of a Check response payload. """ kwargs = {'unique_identifier': 0} self.assertRaisesRegexp( TypeError, "Unique identifier must be a string.", payloads.CheckResponsePayload, **kwargs ) payload = payloads.CheckResponsePayload() args = (payload, 'unique_identifier', 0) self.assertRaisesRegexp( TypeError, "Unique identifier must be a string.", setattr, *args )
def test_invalid_usage_limits_count(self): """ Test that a TypeError is raised when an invalid value is used to set the usage limits count of a Check response payload. """ kwargs = {'usage_limits_count': 'invalid'} self.assertRaisesRegexp( TypeError, "Usage limits count must be an integer.", payloads.CheckResponsePayload, **kwargs ) payload = payloads.CheckResponsePayload() args = (payload, 'usage_limits_count', 'invalid') self.assertRaisesRegexp( TypeError, "Usage limits count must be an integer.", setattr, *args )
def test_invalid_cryptographic_usage_mask(self): """ Test that a TypeError is raised when an invalid value is used to set the cryptographic usage mask of a Check response payload. """ kwargs = {'cryptographic_usage_mask': 'invalid'} self.assertRaisesRegexp( TypeError, "Cryptographic usage mask must be an integer.", payloads.CheckResponsePayload, **kwargs ) payload = payloads.CheckResponsePayload() args = (payload, 'cryptographic_usage_mask', 'invalid') self.assertRaisesRegexp( TypeError, "Cryptographic usage mask must be an integer.", setattr, *args )
def test_invalid_lease_time(self): """ Test that a TypeError is raised when an invalid value is used to set the lease time of a Check response payload. """ kwargs = {'lease_time': 'invalid'} self.assertRaisesRegexp( TypeError, "Lease time must be an integer.", payloads.CheckResponsePayload, **kwargs ) payload = payloads.CheckResponsePayload() args = (payload, 'lease_time', 'invalid') self.assertRaisesRegexp( TypeError, "Lease time must be an integer.", setattr, *args )
def _create_check_payload(self): return payloads.CheckResponsePayload()