def FromJson(data): eventScheduler = EventScheduler() eventDataArray = json.loads(data) for eventData in eventDataArray: eventScheduler.AddEvent(Event.FromDict(eventData)) return eventScheduler
def CreateTestEvent2(cls): from HorizonCore.Framework.Event import Event return Event(name='TestEvent2', stateClassName='TimeForMorningGreeting', startTime=datetime.time(8, 0), endTime=datetime.time(9, 30))
def CreateTestEvent1(): from HorizonCore.Framework.Event import Event return Event(name='TestEvent1', stateClassName='StateStartWakingUp', startTime=datetime.time(7, 0), endTime=datetime.time(8, 0))
def test_SpecifyThatAnEventCanBeConstructedFromAJsonObject(self): event = Event.FromDict(eventAsJson) self.assertEqual(event.Name, 'TimeToStartWakingUp') self.assertEqual(event.StateClassName, 'StateStartWakingUp') self.assertEqual(event.StartTime, datetime.time(7, 0)) self.assertEqual(event.EndTime, datetime.time(8, 0))
def test_SpecifyThatAnEventCanBeSavedToJsonString(self): event = Event.FromDict(eventAsJson) eventSavedAsJsonString = event.ToJson() self.assertEqual( eventSavedAsJsonString, '{"Name": "TimeToStartWakingUp", "StateClassName": "StateStartWakingUp", "StartTime": "07:00", "EndTime": "08:00"}' )
def test_SpecifyThatAnEventCanBeConstructed(self): event = Event(name='TimeToStartWakingUp', stateClassName='StateStartWakingUp', startTime=datetime.time(7, 0), endTime=datetime.time(8, 0)) self.assertEqual(event.Name, 'TimeToStartWakingUp') self.assertEqual(event.StateClassName, 'StateStartWakingUp') self.assertEqual(event.StartTime, datetime.time(7, 0)) self.assertEqual(event.EndTime, datetime.time(8, 0))
def PopulateFromJson(self, data): self.Clear() eventDataArray = json.loads(data) for eventData in eventDataArray: self.AddEvent(Event.FromDict(eventData))