Пример #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))
Пример #2
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)
Пример #3
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
Пример #4
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)
Пример #5
0
 def test_excessive_ma_user_creates_no_diff(self):
     m = MakerAdminMemberFactory(member_number=1001)
     
     self.assertEqual([], BlockMember.find_diffs([], [m]))
Пример #6
0
 def test_no_block_diff_if_already_blocked(self):
     d = DbMember(UserFactory(name="1001", blocked=True))
     
     self.assertEqual([], BlockMember.find_diffs([d], []))
Пример #7
0
 def test_simple_diff_block_one_user(self):
     d = DbMember(UserFactory(name="1001"))
     
     self.assertEqual([BlockMember(d)], BlockMember.find_diffs([d], []))
Пример #8
0
 def test_simple_no_diff(self):
     d = DbMember(UserFactory(name="1001"))
     m = MakerAdminMemberFactory(member_number=1001)
     
     self.assertEqual([], BlockMember.find_diffs([d], [m]))