def test_insert(smv_storage: SMVStorage): setup_parties_collection( smv_storage, [], ) # Before assert smv_storage.get_parties() == [] # note: # - each call to get date-time will tick global time by 15seconds # - tz_offset - make sure it works with a random timezone with freeze_time(START_TIME, tz_offset=-10, auto_tick_seconds=15): # Insert smv_storage.upsert_verified_party( pub_key=PUB_KEY, user_id=TWITTER_ID, screen_name=TWITTER_HANDLE, ) # validate parties = smv_storage.get_parties() assert len(parties) == 1 party = parties[0] assert party["twitter_handle"] == TWITTER_HANDLE assert party["party_id"] == PUB_KEY assert party["twitter_user_id"] == TWITTER_ID assert party["created"] == START_TIME_EPOCH assert party["last_modified"] == START_TIME_EPOCH
def test_dates_after_update(smv_storage: SMVStorage): setup_parties_collection( smv_storage, [], ) # # Create # # note: # - each call to get date-time will tick global time by 15seconds # - tz_offset - make sure it works with a random timezone with freeze_time(START_TIME, tz_offset=-10, auto_tick_seconds=15): smv_storage.upsert_verified_party( pub_key=PUB_KEY, user_id=TWITTER_ID, screen_name=TWITTER_HANDLE, ) parties = smv_storage.get_parties() assert len(parties) == 1 party = parties[0] assert party["created"] == START_TIME_EPOCH assert party["last_modified"] == START_TIME_EPOCH # # Update # # note: # - each call to get date-time will tick global time by 15seconds # - tz_offset - make sure it works with a random timezone with freeze_time( START_TIME + timedelta(seconds=11), tz_offset=-10, auto_tick_seconds=15 ): smv_storage.upsert_verified_party( pub_key=PUB_KEY, user_id=TWITTER_ID, screen_name=TWITTER_HANDLE, ) parties = smv_storage.get_parties() assert len(parties) == 1 party = parties[0] assert party["created"] == START_TIME_EPOCH assert party["last_modified"] == START_TIME_EPOCH + 11
def test_block_participants( smv_storage: SMVStorage, pub_key: str, twitter_id: int, twitter_handle: str, description: str, ): # # Prepare # setup_parties_collection( smv_storage, [], ) # # Create three entries # smv_storage.upsert_verified_party( pub_key=A_PUB_KEY, user_id=A_TWITTER_ID, screen_name=A_TWITTER_HANDLE, ) smv_storage.upsert_verified_party( pub_key=B_PUB_KEY, user_id=B_TWITTER_ID, screen_name=B_TWITTER_HANDLE, ) smv_storage.upsert_verified_party( pub_key=C_PUB_KEY, user_id=C_TWITTER_ID, screen_name=C_TWITTER_HANDLE, ) # # New Sign-up # with pytest.raises(BlocklistPartyError): smv_storage.upsert_verified_party( pub_key=pub_key, user_id=twitter_id, screen_name=twitter_handle, ) # # Validate # parties = smv_storage.get_parties() assert ( len(parties) == 1 ), "Parties A and B should be blocked and not returned by get_parties" party = parties[0] assert party["twitter_handle"] == C_TWITTER_HANDLE assert party["party_id"] == C_PUB_KEY assert party["twitter_user_id"] == C_TWITTER_ID
def test_signup_with_twitter_handle_matching_two_participants( smv_storage: SMVStorage, ): # # Prepare # setup_parties_collection( smv_storage, [], ) # # Create two entries # smv_storage.upsert_verified_party( pub_key=PUB_KEY, user_id=TWITTER_ID, screen_name=TWITTER_HANDLE, ) smv_storage.upsert_verified_party( pub_key=NEW_PUB_KEY, user_id=NEW_TWITTER_ID, screen_name=NEW_TWITTER_HANDLE, ) # # New Sign-up # smv_storage.upsert_verified_party( pub_key=PUB_KEY, user_id=TWITTER_ID, screen_name=NEW_TWITTER_HANDLE, ) # # Validate # parties = smv_storage.get_parties() assert len(parties) == 2 a_party = parties[0] b_party = parties[1] assert a_party["party_id"] == PUB_KEY assert a_party["twitter_user_id"] == TWITTER_ID assert a_party["twitter_handle"] == NEW_TWITTER_HANDLE assert b_party["party_id"] == NEW_PUB_KEY assert b_party["twitter_user_id"] == NEW_TWITTER_ID assert b_party["twitter_handle"] == NEW_TWITTER_HANDLE
def test_new_user_sign_ups( smv_storage: SMVStorage, new_pub_key: str, new_twitter_id: int, new_twitter_handle: str, description: str, ): # # Prepare # setup_parties_collection( smv_storage, [], ) # # Create # smv_storage.upsert_verified_party( pub_key=PUB_KEY, user_id=TWITTER_ID, screen_name=TWITTER_HANDLE, ) # # Create another # smv_storage.upsert_verified_party( pub_key=new_pub_key, user_id=new_twitter_id, screen_name=new_twitter_handle, ) # # Validate # parties = smv_storage.get_parties() assert len(parties) == 2 old_party = parties[0] new_party = parties[1] assert old_party["twitter_handle"] in TWITTER_HANDLE assert old_party["party_id"] == PUB_KEY assert old_party["twitter_user_id"] == TWITTER_ID assert new_party["twitter_handle"] == new_twitter_handle assert new_party["party_id"] == new_pub_key assert new_party["twitter_user_id"] == new_twitter_id
def test_allowed_user_info_updates( smv_storage: SMVStorage, new_pub_key: str, new_twitter_id: int, new_twitter_handle: str, description: str, ): # # Prepare # setup_parties_collection( smv_storage, [], ) # # Create # smv_storage.upsert_verified_party( pub_key=PUB_KEY, user_id=TWITTER_ID, screen_name=TWITTER_HANDLE, ) # # Update # smv_storage.upsert_verified_party( pub_key=new_pub_key, user_id=new_twitter_id, screen_name=new_twitter_handle, ) # # Validate # parties = smv_storage.get_parties() assert len(parties) == 1 party = parties[0] assert party["twitter_handle"] == new_twitter_handle assert party["party_id"] == new_pub_key assert party["twitter_user_id"] == new_twitter_id
def handle_parties(storage: SMVStorage, onelog: OneLog = None) -> flask.Response: parties = storage.get_parties() onelog.info(parties_count=len(parties)) return flask.jsonify(parties)