def test_update_from_json_type_only(self): plaintext_fields = [DeviceField('test_name', 'integer', 123), DeviceField('test2', 'string', 'something')] encrypted_fields = [EncryptedDeviceField('test3', 'boolean', True), EncryptedDeviceField('test4', 'string', 'something else')] device = Device('test', plaintext_fields, encrypted_fields, 'type', description='desc') device.update_from_json({'type': 'new_type'}) self.assertConstructionIsCorrect(device, 'test', plaintext_fields, encrypted_fields, 'new_type', description='desc')
def test_update_from_json_with_plaintext_fields(self): plaintext_fields = [DeviceField('test_name', 'integer', 123), DeviceField('test2', 'string', 'something')] encrypted_fields = [EncryptedDeviceField('test3', 'boolean', True), EncryptedDeviceField('test4', 'string', 'something else')] new_plaintext_fields = [DeviceField('new_test_name', 'integer', 451), DeviceField('new_test2', 'string', 'changed')] device = Device('test', plaintext_fields, encrypted_fields, 'type', description='desc') device.update_from_json({'fields': [field.as_json() for field in new_plaintext_fields]}) self.assertEqual(device.name, 'test') self.assertEqual(device.type, 'type') self.assertEqual(device.description, 'desc') self.assertSetEqual({field.name for field in device.plaintext_fields}, {'new_test_name', 'new_test2'}) self.assertSetEqual({field.name for field in device.encrypted_fields}, set())
def test_update_from_json_with_encrypted_fields(self): plaintext_fields = [DeviceField('test_name', 'integer', 123), DeviceField('test2', 'string', 'something')] encrypted_fields = [EncryptedDeviceField('test3', 'boolean', True), EncryptedDeviceField('test4', 'string', 'something else')] new_encrypted_fields = [EncryptedDeviceField('new_test3', 'boolean', True), EncryptedDeviceField('new_test4', 'string', 'something else')] encrypted_field_json1 = new_encrypted_fields[0].as_json() encrypted_field_json2 = new_encrypted_fields[1].as_json() encrypted_field_json1['value'] = True encrypted_field_json2['value'] = 'something_else' device = Device('test', plaintext_fields, encrypted_fields, 'type', description='desc') device.update_from_json({'fields': [encrypted_field_json1, encrypted_field_json2]}) self.assertEqual(device.name, 'test') self.assertEqual(device.type, 'type') self.assertEqual(device.description, 'desc') self.assertSetEqual({field.name for field in device.plaintext_fields}, set()) self.assertSetEqual({field.name for field in device.encrypted_fields}, {'new_test3', 'new_test4'})