Ejemplo n.º 1
0
def test_sync_teams_to_groups(user_creation, invite_only_user_creation,
                              blacklisted_emails, app):
    # Necessary for the fake auth entries to be created in FederatedLogin.
    database.LoginService.create(name=_FAKE_AUTH)

    # Assert the team has not yet been updated.
    sync_team_info = model.team.get_team_sync_information(
        "buynlarge", "synced")
    assert sync_team_info.last_updated is None

    # Call to sync all teams.
    fake_auth = FakeUsers([])
    sync_teams_to_groups(fake_auth, timedelta(seconds=1))

    # Ensure the team was synced.
    updated_sync_info = model.team.get_team_sync_information(
        "buynlarge", "synced")
    assert updated_sync_info.last_updated is not None
    assert updated_sync_info.transaction_id != sync_team_info.transaction_id

    # Set the stale threshold to a high amount and ensure the team is not resynced.
    current_info = model.team.get_team_sync_information("buynlarge", "synced")
    current_info.last_updated = datetime.now() - timedelta(seconds=2)
    current_info.save()

    sync_teams_to_groups(fake_auth, timedelta(seconds=120))

    third_sync_info = model.team.get_team_sync_information(
        "buynlarge", "synced")
    assert third_sync_info.transaction_id == updated_sync_info.transaction_id

    # Set the stale threshold to 10 seconds, and ensure the team is resynced, after making it
    # "updated" 20s ago.
    current_info = model.team.get_team_sync_information("buynlarge", "synced")
    current_info.last_updated = datetime.now() - timedelta(seconds=20)
    current_info.save()

    sync_teams_to_groups(fake_auth, timedelta(seconds=10))

    fourth_sync_info = model.team.get_team_sync_information(
        "buynlarge", "synced")
    assert fourth_sync_info.transaction_id != updated_sync_info.transaction_id
Ejemplo n.º 2
0
 def _sync_teams_to_groups(self):
     sync_teams_to_groups(authentication, STALE_CUTOFF)