Esempio n. 1
0
def _dict_to_historian(d):
    host_h = historian.Historian()
    for a in d.keys():
        for b in d[a].keys():
            for event_date in d[a][b]:
                host_h.push_host_date(a, b, event_date)
    return host_h
Esempio n. 2
0
    def test_get_best_match_config(self):
        a = h2h.Participant(name="a",
                            is_family=True,
                            participating=True,
                            can_host=True,
                            child_count=0,
                            gender_if_single='')
        b = h2h.Participant(name="b",
                            is_family=True,
                            participating=True,
                            can_host=True,
                            child_count=0,
                            gender_if_single='')
        p_info = {a.name: a, b.name: b}

        host_historian = historian.Historian()
        host_historian.push_host_date(a.name, b.name,
                                      datetime.datetime(2018, 10, 22))
        host_historian.push_host_date(b.name, a.name,
                                      datetime.datetime(2018, 10, 23))

        best_config, _ = h2h.get_best_match_config(
            p_info, host_historian, datetime.datetime(2018, 10, 30), 10)
        expected_config = MatchSet(
            date_yyyymmdd="20181030",
            match=[Match(host=a.name, member=[a.name, b.name])],
        )

        self.assertEqual(expected_config, best_config)
Esempio n. 3
0
    def test_push_pop_get(self):
        h = historian.Historian()

        event_date = datetime.datetime(2018, 10, 30)
        h.push_host_date('a', 'b', event_date)

        self.assertEqual([event_date], h.get_host_dates('a', 'b'))
        self.assertEqual(set(['b']), set(h.get_past_guests('a')))

        h.pop_host_date('a', 'b', event_date)
        self.assertEqual([], h.get_host_dates('a', 'b'))
Esempio n. 4
0
    def test_pops_last_event_date(self):
        h = historian.Historian()

        event_date_a = datetime.datetime(2018, 10, 30)
        event_date_b = datetime.datetime(2018, 10, 31)

        h.push_host_date('a', 'b', event_date_a)
        h.push_host_date('a', 'b', event_date_b)

        self.assertEqual([event_date_a, event_date_b],
                         h.get_host_dates('a', 'b'))

        h.pop_host_date('a', 'b', event_date_b)

        self.assertEqual([event_date_a], h.get_host_dates('a', 'b'))
Esempio n. 5
0
    def test_date_ordering(self):
        h = historian.Historian()

        event_date_a = datetime.datetime(2018, 10, 30)
        event_date_b = datetime.datetime(2018, 10, 31)
        event_date_c = datetime.datetime(2018, 11, 1)

        # insert later date first.
        h.push_host_date('a', 'b', event_date_b)
        h.push_host_date('a', 'b', event_date_c)
        h.push_host_date('a', 'b', event_date_a)

        # dates are ordered independently of insert order.
        self.assertEqual([event_date_a, event_date_b, event_date_c],
                         h.get_host_dates('a', 'b'))

        h.pop_host_date('a', 'b', event_date_c)

        # pops last date.
        self.assertEqual([event_date_a, event_date_b],
                         h.get_host_dates('a', 'b'))
Esempio n. 6
0
    def test_zero_state(self):
        h = historian.Historian()

        # 0-state functions correctly.
        self.assertEqual([], h.get_host_dates('a', 'b'))
        self.assertEqual(set(), set(h.get_past_guests('a')))
Esempio n. 7
0
 def test_zero_state(self):
     self.assertEqual([],
                      history_warnings.get_warnings(historian.Historian()))