|  | 
|  | 1 | +from pydoc import describe | 
|  | 2 | +from unittest import TestCase | 
|  | 3 | + | 
|  | 4 | +from awsiot.iotshadow import ShadowState | 
|  | 5 | + | 
|  | 6 | + | 
|  | 7 | +class ShadowTest(TestCase): | 
|  | 8 | + | 
|  | 9 | + def test_shadow_state_payload_filled(self): | 
|  | 10 | + test_state = ShadowState.from_payload({ | 
|  | 11 | + "reported": {"Color": "Red"}, | 
|  | 12 | + "desired": {"Color": "Blue"} | 
|  | 13 | + }) | 
|  | 14 | + compareState = ShadowState( | 
|  | 15 | + reported={"Color": "Red"}, | 
|  | 16 | + desired={"Color": "Blue"} | 
|  | 17 | + ) | 
|  | 18 | + self.assertTrue(test_state.to_payload() == compareState.to_payload()) | 
|  | 19 | + | 
|  | 20 | + def test_shadow_state_payload_partial_filled(self): | 
|  | 21 | + test_state = ShadowState.from_payload({ | 
|  | 22 | + "reported": {"Color": "Red"} | 
|  | 23 | + }) | 
|  | 24 | + self.assertEqual(test_state.to_payload(), {"reported": {"Color": "Red"}}) | 
|  | 25 | + | 
|  | 26 | + def test_shadow_state_payload_can_send_null(self): | 
|  | 27 | + test_state = ShadowState( | 
|  | 28 | + reported={"Color": "Red"}, | 
|  | 29 | + desired=None, | 
|  | 30 | + desired_is_nullable=True | 
|  | 31 | + ) | 
|  | 32 | + self.assertEqual(test_state.to_payload(), {"reported": {"Color": "Red"}, "desired": None}) | 
|  | 33 | + | 
|  | 34 | + def test_shadow_state_payload_with_none(self): | 
|  | 35 | + test_state = ShadowState.from_payload({"reported": {"Color": "Red"}, "desired": None}) | 
|  | 36 | + self.assertTrue(test_state.desired_is_nullable) | 
|  | 37 | + self.assertEqual(test_state.to_payload(), {"reported": {"Color": "Red"}, "desired": None}) | 
|  | 38 | + | 
|  | 39 | + def test_shadow_state_payload_without_none(self): | 
|  | 40 | + test_state = ShadowState.from_payload({"reported": {"deviceAgent": {"rebootRequired": True}}}) | 
|  | 41 | + self.assertEqual(test_state.to_payload(), {"reported": {"deviceAgent": {"rebootRequired": True}}}) | 
0 commit comments