コード例 #1
0
    def test_SpecifyThatAnEntityCanAdded(self):
        # act
        entity = DummyEntityOne(1)
        EntityManager.RegisterEntity(entity)

        # assert
        self.assertEqual(len(EntityManager._getEntityMap()), 1)
コード例 #2
0
    def test_SpecifyThatDelayTelegramsCanBeDispatched(self):
        # arrange
        delayInSeconds = 5
        entityOne = EntityManager.GetEntityFromID(Entity.EntityOne.value)
        entityTwo = EntityManager.GetEntityFromID(Entity.EntityTwo.value)

        TelegramDispatcher().DispatchTelegram(delayInSeconds,
                                              Entity.EntityOne.value,
                                              Entity.EntityOne.value,
                                              Message.MessageOne.value,
                                              TelegramDispatcher.NO_ADDITIONAL_INFO)

        TelegramDispatcher().DispatchTelegram(delayInSeconds,
                                              Entity.EntityOne.value,
                                              Entity.EntityTwo.value,
                                              Message.MessageOne.value,
                                              TelegramDispatcher.NO_ADDITIONAL_INFO)
        # act
        TelegramDispatcher().DispatchDelayedTelegrams()

        # assert
        self.assertEqual(entityOne.Outcome, None, "a1")
        self.assertEqual(entityTwo.Outcome, None, "a2")

        # act
        self.datetime = self.datetime + datetime.timedelta(seconds=delayInSeconds+1)
        TelegramDispatcher().DispatchDelayedTelegrams()

        # assert
        self.assertEqual(entityOne.Outcome, "Telegram received", "a3")
        self.assertEqual(entityTwo.Outcome, "Telegram received", "a4")
コード例 #3
0
    def test_SpecifyThatAnEntityCanBeRetrievedFromItsIdAsAnEnum(self):
        entity = DummyEntityOne(TestEntity.DummyEntityOne)

        # act
        EntityManager.RegisterEntity(entity)

        # assert
        self.assertEqual(len(EntityManager._getEntityMap()), 1)
        self.assertEqual(EntityManager.GetEntityFromID(TestEntity.DummyEntityOne).__class__.__name__, 'DummyEntityOne')
コード例 #4
0
    def test_SpecifyThatTwoEntitiesCanAdded(self):
        # act
        entity1 = DummyEntityOne(1)
        entity2 = DummyEntityTwo(2)
        EntityManager.RegisterEntity(entity1)
        EntityManager.RegisterEntity(entity2)

        # assert
        self.assertEqual(len(EntityManager._getEntityMap()), 2)
コード例 #5
0
    def test_SpecifyThatAnEntityCanBeRetrievedFromItsId(self):
        # arrange
        entity1 = DummyEntityOne(1)
        entity2 = DummyEntityTwo(2)

        # act
        EntityManager.RegisterEntity(entity1)
        EntityManager.RegisterEntity(entity2)

        # assert
        self.assertEqual(len(EntityManager._getEntityMap()), 2)
        self.assertEqual(EntityManager.GetEntityFromID(1).__class__.__name__, 'DummyEntityOne')
        self.assertEqual(EntityManager.GetEntityFromID(2).__class__.__name__, 'DummyEntityTwo')
コード例 #6
0
    def setUp(self):
        entityOne = EntityOne(1)
        entityTwo = EntityTwo(2)

        EntityManager.RegisterEntity(entityOne)
        EntityManager.RegisterEntity(entityTwo)

        self.datetime = datetime.datetime(2016, 11, 8, 14, 00, 12, 18299)

        class fakeDateTime(datetime.datetime):
            @classmethod
            def utcnow(cls):
                return self.datetime

        patcher = Mock.patch('datetime.datetime', fakeDateTime)
        self.addCleanup(patcher.stop)
        patcher.start()
コード例 #7
0
    def test_SpecifyThatEntityEngineCanBeConstructed(self):

        # Ensure that all singletons are reset
        self.assertEqual(0, BaseEntity.GetNextValidId(), "GetNextValidId 1")
        self.assertEqual({}, EntityManager._getEntityMap(), "_getEntityMap 1")
        self.assertEqual(True,
                         TelegramDispatcher().PriorityQ.IsEmpty(),
                         "PriorityQ 1")

        # Create the engine
        entityEngine = self.CreateTestEntityEngine()

        # Get references to objects under test
        entityMap = EntityManager._getEntityMap()
        actionMap = entityEngine._actionMap
        entityOne = entityMap[0]
        entityTwo = entityMap[1]

        # Assert singletons
        self.assertEqual(True,
                         TelegramDispatcher().PriorityQ.IsEmpty(),
                         "PriorityQ 2")

        # Assert entityMap
        self.assertEqual(2, len(entityMap), "len(entityMap)")
        self.assertEqual("TestEntityOne",
                         type(entityMap[0]).__name__, "entityMap[0]")
        self.assertEqual("TestEntityTwo",
                         type(entityMap[1]).__name__, "entityMap[1]")
        self.assertEqual(0, entityMap[0].Id, "entityMap[0].Id")
        self.assertEqual(1, entityMap[1].Id, "entityMap[1].Id")

        # Assert actionMap
        self.assertEqual(4, len(actionMap), "len(actionMap)")
        self.assertEqual("ActionOn", list(actionMap.keys())[0], "key 0")
        self.assertEqual("ActionOff", list(actionMap.keys())[1], "key 1")
        self.assertEqual("ActionEnable", list(actionMap.keys())[2], "key 2")
        self.assertEqual("ActionDisable", list(actionMap.keys())[3], "key 3")
        self.assertEqual(actionMap['ActionOn']['FunctionToExecute'],
                         entityOne.ActionOn)
        self.assertEqual(actionMap['ActionOff']['FunctionToExecute'],
                         entityOne.ActionOff)
        self.assertEqual(actionMap['ActionEnable']['FunctionToExecute'],
                         entityTwo.ActionEnable)
        self.assertEqual(actionMap['ActionDisable']['FunctionToExecute'],
                         entityTwo.ActionDisable)
コード例 #8
0
 def CreateGoalThink():
     goalEvaluators = [
         TestGoalEvaluatorOne(characterBias=0.5),
         TestGoalEvaluatorTwo(characterBias=0.3)
     ]
     testEntity = EntityManager.GetEntityFromID(Entity.TestEntity)
     return GoalThink(testEntity, GoalType.TestGoalComposite,
                      goalEvaluators)
コード例 #9
0
    def BuildHierarchicalGoal(self):
        testEntity = EntityManager.GetEntityFromID(Entity.TestEntity)
        goalComposite = GoalComposite(testEntity, GoalType.TestGoalComposite)

        goalOne = GoalOne(self.testEntity)
        goalTwo = GoalTwo(self.testEntity)

        goalComposite.AddSubGoal(goalOne)
        goalComposite.AddSubGoal(goalTwo)

        return goalComposite
コード例 #10
0
    def test_SpecifyThatATelegramCanBeDispatchedImmediately(self):
        # arrange
        entity = EntityManager.GetEntityFromID(Entity.EntityTwo.value)

        # assert
        self.assertEqual(entity.Outcome, None)

        # act
        TelegramDispatcher().DispatchTelegram(TelegramDispatcher.SEND_MSG_IMMEDIATELY,
                                              Entity.EntityOne.value,
                                              Entity.EntityTwo.value,
                                              Message.MessageOne.value,
                                              TelegramDispatcher.NO_ADDITIONAL_INFO)

        # assert
        self.assertEqual(entity.Outcome, "Telegram received")
コード例 #11
0
ファイル: EntityEngine.py プロジェクト: SergeKrstic/show-case
    def __init__(self, firestoreClient, entities):

        self._firestoreClient = firestoreClient
        self._entities = entities
        self._actionMap = {}

        BaseEntity.ResetNextValidId()
        TelegramDispatcher().Clear()

        for entity in self._entities:
            EntityManager.RegisterEntity(entity)
            self._actionMap.update(entity.ActionMap)

        transactionsRef = self._firestoreClient \
            .collection(DIALOG_FLOW_TRANSACTIONS_URL) \
            .where('status', '==', 'UNPROCESSED')

        self._transactionListener = transactionsRef.on_snapshot(self._processRequests)
コード例 #12
0
    def test_SpecifyThatAnEntityCanBeDeletedFromTheMap(self):
        # arrange
        entity1 = DummyEntityOne(1)
        entity2 = DummyEntityTwo(2)

        # act
        EntityManager.RegisterEntity(entity1)
        EntityManager.RegisterEntity(entity2)

        # assert
        self.assertEqual(len(EntityManager._getEntityMap()), 2)
        self.assertEqual(EntityManager.GetEntityFromID(1).__class__.__name__, 'DummyEntityOne')
        self.assertEqual(EntityManager.GetEntityFromID(2).__class__.__name__, 'DummyEntityTwo')

        # act
        EntityManager.RemoveEntity(entity1)

        # assert
        self.assertEqual(len(EntityManager._getEntityMap()), 1)
        self.assertRaises(Exception, EntityManager.GetEntityFromID, 1)
        self.assertEqual(EntityManager.GetEntityFromID(2).__class__.__name__, 'DummyEntityTwo')
コード例 #13
0
    def setUp(self):
        Utils.DEBUG_PRINT_ENABLED = False

        global UpdateHistory
        self.UpdateHistory = []

        global TelegramHistory
        TelegramHistory = []

        global ActionHistory
        ActionHistory = []

        EntityManager.Reset()

        self.transactionDateTime = datetime.datetime(2018,
                                                     7,
                                                     18,
                                                     5,
                                                     45,
                                                     tzinfo=pytz.UTC)

        DialogFlowTransaction.objects.filter(
            date_event_generated=self.transactionDateTime).all().delete()
コード例 #14
0
 def setUp(self):
     EntityManager.Reset()
コード例 #15
0
 def test_SpecifyThatEntityManagerCanBeConstructed(self):
     # assert
     self.assertEqual(len(EntityManager._getEntityMap()), 0)
コード例 #16
0
 def tearDown(self):
     EntityManager.Reset()
     BaseEntity.ResetNextValidId()
     TelegramDispatcher().Clear()
コード例 #17
0
 def setUp(self):
     self.testEntity = TestBot(Entity.TestEntity)
     EntityManager.RegisterEntity(self.testEntity)
コード例 #18
0
 def tearDown(self):
     EntityManager.Reset()
     BaseEntity.ResetNextValidId()
コード例 #19
0
 def CreateGoalComposite():
     testEntity = EntityManager.GetEntityFromID(Entity.TestEntity)
     return GoalComposite(testEntity, GoalType.TestGoalComposite)