def test_w_mulitple_activation_events_one_e_returned(self):
        e = G(Entity)
        G(EntityActivationEvent,
          was_activated=True,
          entity=e,
          time=datetime(2013, 2, 1))
        G(EntityActivationEvent,
          was_activated=False,
          entity=e,
          time=datetime(2013, 2, 3))
        G(EntityActivationEvent,
          was_activated=False,
          entity=e,
          time=datetime(2013, 2, 4))
        G(EntityActivationEvent,
          was_activated=True,
          entity=e,
          time=datetime(2013, 2, 4, 12))
        G(EntityActivationEvent,
          was_activated=False,
          entity=e,
          time=datetime(2013, 3, 4, 12))

        res = get_entities_at_times(
            [datetime(2013, 2, 6), datetime(2012, 5, 6)])
        self.assertEquals(res, {
            datetime(2013, 2, 6): set([e.id]),
            datetime(2012, 5, 6): set(),
        })
 def test_no_events_w_input(self):
     res = get_entities_at_times([datetime(2013, 4, 5), datetime(2013, 5, 6)])
     self.assertEquals(res, {
         datetime(2013, 4, 5): set(),
         datetime(2013, 5, 6): set(),
         datetime(2013, 4, 5): set(),
         datetime(2013, 5, 6): set(),
     })
    def test_w_mulitple_activation_events_mulitple_e_returned_w_filter(self):
        e1 = G(Entity)
        e2 = G(Entity)
        G(EntityActivationEvent,
          was_activated=True,
          entity=e1,
          time=datetime(2013, 2, 1))
        G(EntityActivationEvent,
          was_activated=False,
          entity=e1,
          time=datetime(2013, 2, 3))
        G(EntityActivationEvent,
          was_activated=False,
          entity=e1,
          time=datetime(2013, 2, 4))
        G(EntityActivationEvent,
          was_activated=True,
          entity=e1,
          time=datetime(2013, 2, 4, 12))
        G(EntityActivationEvent,
          was_activated=False,
          entity=e1,
          time=datetime(2013, 3, 4, 12))

        G(EntityActivationEvent,
          was_activated=True,
          entity=e2,
          time=datetime(2013, 2, 4))
        G(EntityActivationEvent,
          was_activated=False,
          entity=e2,
          time=datetime(2013, 2, 20))
        G(EntityActivationEvent,
          was_activated=False,
          entity=e2,
          time=datetime(2013, 3, 4))
        G(EntityActivationEvent,
          was_activated=True,
          entity=e2,
          time=datetime(2013, 3, 4, 12))
        G(EntityActivationEvent,
          was_activated=True,
          entity=e2,
          time=datetime(2013, 3, 4, 13))

        res = get_entities_at_times([
            datetime(2013, 2, 2),
            datetime(2013, 2, 4, 13),
            datetime(2013, 3, 5)
        ],
                                    filter_by_entity_ids=[e1.id])

        self.assertEquals(
            res, {
                datetime(2013, 2, 2): set([e1.id]),
                datetime(2013, 2, 4, 13): set([e1.id]),
                datetime(2013, 3, 5): set(),
            })
    def test_w_events_entity_deactivated_before_date(self):
        e = G(Entity)
        G(EntityActivationEvent, was_activated=True, entity=e, time=datetime(2013, 2, 1))
        G(EntityActivationEvent, was_activated=False, entity=e, time=datetime(2013, 2, 3))

        res = get_entities_at_times([datetime(2013, 2, 4)])
        self.assertEquals(res, {
            datetime(2013, 2, 4): set(),
        })
 def test_no_events_w_input(self):
     res = get_entities_at_times(
         [datetime(2013, 4, 5), datetime(2013, 5, 6)])
     self.assertEquals(
         res, {
             datetime(2013, 4, 5): set(),
             datetime(2013, 5, 6): set(),
             datetime(2013, 4, 5): set(),
             datetime(2013, 5, 6): set(),
         })
    def test_w_events_one_e_returned(self):
        e = G(Entity)
        G(EntityActivationEvent, was_activated=True, entity=e, time=datetime(2013, 2, 1))
        G(EntityActivationEvent, was_activated=False, entity=e, time=datetime(2013, 2, 3))

        res = get_entities_at_times([datetime(2013, 2, 2), datetime(2012, 5, 6)])
        self.assertEquals(res, {
            datetime(2013, 2, 2): set([e.id]),
            datetime(2012, 5, 6): set(),
        })
    def test_w_events_no_results(self):
        e = G(Entity)
        G(EntityActivationEvent, was_activated=True, entity=e, time=datetime(2013, 2, 1))
        G(EntityActivationEvent, was_activated=False, entity=e, time=datetime(2013, 2, 2))

        res = get_entities_at_times([datetime(2012, 4, 5), datetime(2012, 5, 6)])
        self.assertEquals(res, {
            datetime(2012, 4, 5): set(),
            datetime(2012, 5, 6): set(),
        })
    def test_w_events_entity_deactivated_before_date(self):
        e = G(Entity)
        G(EntityActivationEvent,
          was_activated=True,
          entity=e,
          time=datetime(2013, 2, 1))
        G(EntityActivationEvent,
          was_activated=False,
          entity=e,
          time=datetime(2013, 2, 3))

        res = get_entities_at_times([datetime(2013, 2, 4)])
        self.assertEquals(res, {
            datetime(2013, 2, 4): set(),
        })
    def test_w_events_no_results(self):
        e = G(Entity)
        G(EntityActivationEvent,
          was_activated=True,
          entity=e,
          time=datetime(2013, 2, 1))
        G(EntityActivationEvent,
          was_activated=False,
          entity=e,
          time=datetime(2013, 2, 2))

        res = get_entities_at_times(
            [datetime(2012, 4, 5), datetime(2012, 5, 6)])
        self.assertEquals(res, {
            datetime(2012, 4, 5): set(),
            datetime(2012, 5, 6): set(),
        })
    def test_w_mulitple_activation_events_mulitple_e_returned(self):
        e1 = G(Entity)
        e2 = G(Entity)
        G(EntityActivationEvent, was_activated=True, entity=e1, time=datetime(2013, 2, 1))
        G(EntityActivationEvent, was_activated=False, entity=e1, time=datetime(2013, 2, 3))
        G(EntityActivationEvent, was_activated=False, entity=e1, time=datetime(2013, 2, 4))
        G(EntityActivationEvent, was_activated=True, entity=e1, time=datetime(2013, 2, 4, 12))
        G(EntityActivationEvent, was_activated=False, entity=e1, time=datetime(2013, 3, 4, 12))

        G(EntityActivationEvent, was_activated=True, entity=e2, time=datetime(2013, 2, 4))
        G(EntityActivationEvent, was_activated=False, entity=e2, time=datetime(2013, 2, 20))
        G(EntityActivationEvent, was_activated=False, entity=e2, time=datetime(2013, 3, 4))
        G(EntityActivationEvent, was_activated=True, entity=e2, time=datetime(2013, 3, 4, 12))
        G(EntityActivationEvent, was_activated=True, entity=e2, time=datetime(2013, 3, 4, 13))

        res = get_entities_at_times([datetime(2013, 2, 2), datetime(2013, 2, 4, 13), datetime(2013, 3, 5)])

        self.assertEquals(res, {
            datetime(2013, 2, 2): set([e1.id]),
            datetime(2013, 2, 4, 13): set([e1.id, e2.id]),
            datetime(2013, 3, 5): set([e2.id]),
        })
 def test_no_events_no_input(self):
     res = get_entities_at_times([])
     self.assertEquals(res, {})
 def test_no_events_no_input(self):
     res = get_entities_at_times([])
     self.assertEquals(res, {})