Ejemplo n.º 1
0
 def test_multiple_unsorted_no_diff(self):
     ds = [DbMember(UserFactory(name=str(i))) for i in range(1001, 1010)]
     shuffle(ds)
     ms = [MakerAdminMemberFactory(member_number=i) for i in range(1001, 1010)]
     shuffle(ms)
     
     self.assertEqual([], BlockMember.find_diffs(ds, ms))
Ejemplo n.º 2
0
 def test_multiple_unsorted_no_diff(self):
     ds = [DbMember(UserFactory(stop_timestamp=self.datetime(days=i), name=str(i), card=str(i)))
           for i in range(1001, 1010)]
     shuffle(ds)
     ms = [MakerAdminMemberFactory(member_number=i, end_timestamp=self.datetime(days=i), rfid_tag=str(i))
           for i in range(1001, 1010)]
     shuffle(ms)
     
     self.assertEqual([], UpdateMember.find_diffs(ds, ms))
Ejemplo n.º 3
0
 def test_update_diff_blocks_member(self):
     u = UserFactory(stop_timestamp=self.datetime(days=1), name="1001", blocked=False, card="1")
     d = DbMember(u)
     BlockMember(d).update(self.session, self.tui)
     
     self.session.refresh(u)
     
     self.assertEqual(self.datetime(days=1), u.stop_timestamp)
     self.assertEqual("1", u.card)
     self.assertTrue(u.blocked)
Ejemplo n.º 4
0
 def test_update_diff_changes_timestamp_when_called(self):
     u = UserFactory(stop_timestamp=self.datetime(days=1), name="1001", blocked=False)
     d = DbMember(u)
     m = MakerAdminMemberFactory(member_number=1001, end_timestamp=self.datetime(days=2))
     etd = UpdateMember(d, m)
     
     etd.update(self.session, self.tui)
     
     self.session.refresh(u)
     
     self.assertEqual(self.datetime(days=2), u.stop_timestamp)
     self.assertFalse(u.blocked)
Ejemplo n.º 5
0
 def test_update_diff_changes_all_three_values_when_both_diffs(self):
     u = UserFactory(stop_timestamp=self.datetime(days=1), name="1001", blocked=True, card="1")
     d = DbMember(u)
     m = MakerAdminMemberFactory(member_number=1001, end_timestamp=self.datetime(days=2), rfid_tag="2")
     etd = UpdateMember(d, m)
     
     etd.update(self.session, self.tui)
     
     self.session.refresh(u)
     
     self.assertEqual(self.datetime(days=2), u.stop_timestamp)
     self.assertEqual("2", u.card)
     self.assertFalse(u.blocked)
Ejemplo n.º 6
0
 def test_multiple_diffs_and_multiple_non_diffs_works(self):
     d1 = DbMember(UserFactory(stop_timestamp=self.datetime(days=1), name="1001", card="1", blocked=False))
     d2 = DbMember(UserFactory(stop_timestamp=self.datetime(days=2), name="1002", card="2", blocked=False))
     d3 = DbMember(UserFactory(stop_timestamp=self.datetime(days=3), name="1003", card="3", blocked=False))
     d4 = DbMember(UserFactory(stop_timestamp=self.datetime(days=4), name="1004", card="4", blocked=True))
     d5 = DbMember(UserFactory(stop_timestamp=self.datetime(days=5), name="1005", card="X", blocked=False))
     dx = DbMember(UserFactory(stop_timestamp=self.datetime(days=0), name="2001", card="1", blocked=False))
     m1 = MakerAdminMemberFactory(member_number=1001, rfid_tag="1", end_timestamp=self.datetime(days=1))
     m2 = MakerAdminMemberFactory(member_number=1002, rfid_tag="2", end_timestamp=self.datetime(days=8))
     m3 = MakerAdminMemberFactory(member_number=1003, rfid_tag="3", end_timestamp=self.datetime(days=3))
     m4 = MakerAdminMemberFactory(member_number=1004, rfid_tag="4", end_timestamp=self.datetime(days=4))
     m5 = MakerAdminMemberFactory(member_number=1005, rfid_tag="5", end_timestamp=self.datetime(days=5))
     mx = MakerAdminMemberFactory(member_number=3001, rfid_tag="1", end_timestamp=self.datetime(days=1))
     
     diffs = UpdateMember.find_diffs([d1, d2, d3, d4, d5, dx], [mx, m1, m2, m3, m4, m5])
     self.assertIn(UpdateMember(d2, m2), diffs)
     self.assertIn(UpdateMember(d4, m4), diffs)
     self.assertIn(UpdateMember(d5, m5), diffs)
     self.assertEqual(3, len(diffs))
Ejemplo n.º 7
0
 def test_two_different_members_creates_no_diff(self):
     d = DbMember(UserFactory(stop_timestamp=self.datetime(), name="1002", card="1"))
     m = MakerAdminMemberFactory(member_number=1001, end_timestamp=self.datetime(), rfid_tag="1")
     
     self.assertEqual([], UpdateMember.find_diffs([d], [m]))
Ejemplo n.º 8
0
 def test_negative_2_second_diff_creates_diff(self):
     d = DbMember(UserFactory(stop_timestamp=self.datetime(), name="1001", blocked=False, card="1"))
     m = MakerAdminMemberFactory(member_number=1001, end_timestamp=self.datetime(seconds=-2), rfid_tag="1")
     
     self.assertEqual([UpdateMember(d, m)], UpdateMember.find_diffs([d], [m]))
Ejemplo n.º 9
0
 def test_half_second_diff_creates_no_diff(self):
     d = DbMember(UserFactory(stop_timestamp=self.datetime(milliseconds=1), name="1001", blocked=False, card="1"))
     m = MakerAdminMemberFactory(member_number=1001, end_timestamp=self.datetime(milliseconds=500), rfid_tag="1")
     
     self.assertEqual([], UpdateMember.find_diffs([d], [m]))
Ejemplo n.º 10
0
 def test_diff_on_tag(self):
     d = DbMember(UserFactory(stop_timestamp=self.datetime(), name="1001", card="1"))
     m = MakerAdminMemberFactory(member_number=1001, end_timestamp=self.datetime(), rfid_tag="2")
     
     self.assertEqual([UpdateMember(d, m)], UpdateMember.find_diffs([d], [m]))
Ejemplo n.º 11
0
 def test_no_timestamp_vs_no_timestamp_creates_no_diff(self):
     d = DbMember(UserFactory(stop_timestamp=None, name="1001", blocked=False, card="1"))
     m = MakerAdminMemberFactory(member_number=1001, end_timestamp=None, rfid_tag="1")
     
     self.assertEqual([], UpdateMember.find_diffs([d], [m]))
Ejemplo n.º 12
0
 def test_multiple_diffs_and_multiple_non_diffs_works(self):
     ds = [DbMember(UserFactory(name=n)) for n in ["1001", "1002", "1003"]]
     ms = [MakerAdminMemberFactory(member_number=n) for n in [1001, 1003, 1004, 1005]]
     
     diffs = [d.db_member.member_number for d in BlockMember.find_diffs(ds, ms)]
     self.assertCountEqual([1002], diffs)
Ejemplo n.º 13
0
 def test_no_block_diff_if_already_blocked(self):
     d = DbMember(UserFactory(name="1001", blocked=True))
     
     self.assertEqual([], BlockMember.find_diffs([d], []))
Ejemplo n.º 14
0
 def test_simple_diff_block_one_user(self):
     d = DbMember(UserFactory(name="1001"))
     
     self.assertEqual([BlockMember(d)], BlockMember.find_diffs([d], []))
Ejemplo n.º 15
0
 def test_simple_no_diff(self):
     d = DbMember(UserFactory(name="1001"))
     m = MakerAdminMemberFactory(member_number=1001)
     
     self.assertEqual([], BlockMember.find_diffs([d], [m]))
Ejemplo n.º 16
0
 def test_excessive_db_user_creates_no_diff(self):
     d = DbMember(UserFactory(name="1001"))
     
     self.assertEqual([], AddMember.find_diffs([d], []))