コード例 #1
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)
コード例 #2
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)
コード例 #3
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))
コード例 #4
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))
コード例 #5
0
def sync(session=None,
         client=None,
         ui=None,
         customer_id=None,
         authority_id=None,
         what=None,
         ignore_running=False):
    what = what or WHAT_ALL

    # Exit if MultiAccess is running

    if not ignore_running:
        ui.info__progress("checking for running MultiAccess")
        if is_multi_access_running():
            ui.info__progress(
                "looks like MultiAccess is running, please exit MultiAccess and run again"
            )
            return

    # Log in to the MakerAdmin server unless we are already logged in
    if not client.is_logged_in():
        while not client.login():
            pass

    # Run actions on MakerAdmin (ship orders and update key timestamps)

    if WHAT_ORDERS in what:
        client.ship_orders(ui)

    # Fetch from MakerAdmin

    ma_members = client.fetch_members(ui)

    # Fetch relevant data from db and diff it

    db_members = get_multi_access_members(session, ui, customer_id)

    # Diff maker data.

    ui.info__progress('diffing multi access users against maker admin members')
    diffs = []
    if WHAT_UPDATE in what:
        diffs += UpdateMember.find_diffs(db_members, ma_members)
    if WHAT_ADD in what:
        diffs += AddMember.find_diffs(db_members, ma_members)
    if WHAT_BLOCK in what:
        diffs += BlockMember.find_diffs(db_members, ma_members)

    if not diffs:
        ui.info__progress('nothing to update')
        return

    # Present diff of what will be changed

    ui.prompt__update_db(
        heading=f'the following {len(diffs)} changes will be made',
        lines=[d.describe_update() for d in diffs])

    # Preform changes

    update_diffs(session,
                 ui,
                 diffs,
                 customer_id=customer_id,
                 authority_id=authority_id)
    ui.info__progress('finished updating db')

    return
コード例 #6
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]))
コード例 #7
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]))
コード例 #8
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]))
コード例 #9
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]))
コード例 #10
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]))