예제 #1
0
    def test_add_registers_change(self):
        le = Ledger(0)
        t0 = Transaction(mocksubject(0), 0)
        t1 = Transaction(mocksubject(1), 0)

        le.add(t0)
        le.add(t1)

        assert 0 in le.changed
        assert 1 in le.changed
        assert le.stale is True
예제 #2
0
    def test_add_transaction(self):
        le = Ledger(0)
        t0 = Transaction(mocksubject(0), 0)
        t1 = Transaction(mocksubject(1), 0)

        le.add(t0)
        le.add(t1)

        assert le.transactions[0] == t0
        assert le.transactions[1] == t1

        assert t0.order == 0
        assert t1.order == 1
예제 #3
0
    def test_notify(self, mock):
        l = Ledger(15)
        t = Transaction(mock(), 0)
        print(mock().id)
        l.add(t)
        l.clear_changes()

        l.notify(16, Bureau(Subject))

        t.notify.assert_called_once_with(mock())
        assert l.stale is True
        assert l.changed == [16]
예제 #4
0
    def test_update_registers_change(self):
        le = Ledger(0)
        t0 = Transaction(mocksubject(0), 0)
        t1 = Transaction(mocksubject(1), 0)

        le.add(t0)
        le.add(t1)

        le.recalculate()
        le.update(0)

        assert le.changed == [0]
        assert le.stale is True
예제 #5
0
    def test_update(self):
        le = Ledger(0)
        t0 = Transaction(mocksubject(0), 0)
        t0.notify = MagicMock()

        le.add(t0)
        le.update(0)

        t0.notify.assert_not_called
예제 #6
0
    def test_recalculate_clears_changes(self):
        le = Ledger(0)
        t0 = Transaction(mocksubject(0), 0)
        t1 = Transaction(mocksubject(1), 0)

        le.add(t0)
        le.add(t1)

        le.recalculate()

        assert le.changed == []
        assert le.stale is False
예제 #7
0
    def test_notify_agents_callsnotify(self, mock):

        subject = mocksubject(0)
        t = Transaction(mocksubject(1), 0)
        t.agent(0).ledger = MagicMock()
        print(t.agent(0))

        l = Ledger(15)
        l.add(t)
        l.notify_agents(None, None)

        print(mock)
        t.agent(0).ledger.notify.assert_called_once_with(15, None)
예제 #8
0
    def test_get(self):
        le = Ledger(0)
        t = Transaction(mocksubject(0), 0)
        le.add(t)

        assert le.get(0) == t
예제 #9
0
 def test_init(self):
     le = Ledger(15)
     assert le.id == 15
     assert le.transactions == {}
     assert le.stale is True
     assert le.changed == []
예제 #10
0
    def test_notify_agents_getsagent(self, mock):
        l = Ledger(100)
        _ = [l.add(Transaction(mocksubject(i), 0)) for i in range(5)]

        l.notify_agents(None, Bureau(User))
        assert mock.call_count == 5
예제 #11
0
    def test_change(self):
        le = Ledger(0)
        le._change(1)

        assert 1 in le.changed