def test_validate_start_event__valid_event_should_not_raise_error(): event = get_sample_start_event() try: validate_start_event(event) assert True except: pytest.fail("Valid start event raised exception")
def test_create_start_event__uuid_is_prettified(): event = get_sample_start_event( player_id='02a0511372394597aa76c89f106aa547', session_id='00000000-0123-4567-8910-000000000002') returndata = insert_start_event(event) uuid_with_dashes = '02a05113-7239-4597-aa76-c89f106aa547' assert str(returndata['player_session']['player_id']) == uuid_with_dashes
def test_create_start_event_only__no_completed_session_added_to_db(): player_id = '00000000000000000000000000000005' session_id = '00000000-0123-4567-8910-000000000005' start_event = get_sample_start_event(player_id=player_id, session_id=session_id) completed_state_before = completed_session_exists(player_id, session_id) # I dont insert end event. insert_start_event(start_event) completed_state_after = completed_session_exists(player_id, session_id) assert completed_state_before is False and completed_state_after is False
def test_create_start_event__event_is_added_to_cassandra(): event = get_sample_start_event( player_id='00000000000000000000000000000001', session_id='00000000-0123-4567-8910-000000000001') state_before = session_start_event_exists(player_id=event["player_id"], session_id=event["session_id"]) insert_start_event(event) state_after = session_start_event_exists(player_id=event["player_id"], session_id=event["session_id"]) assert state_before is False and state_after is True
def test_create_start_and_end_event__completed_session_is_added_to_cassandra(): player_id = '00000000000000000000000000000003' session_id = '00000000-0123-4567-8910-000000000003' start_event = get_sample_start_event(player_id=player_id, session_id=session_id) end_event = get_sample_end_event(player_id=player_id, session_id=session_id) completed_state_before = completed_session_exists(player_id, session_id) insert_start_event(start_event) insert_end_event(end_event) completed_state_after = completed_session_exists(player_id, session_id) assert completed_state_before is False and completed_state_after is True
def test_create_end_first_then_start_event__completed_session_added_to_db(): player_id = '00000000000000000000000000000004' session_id = '00000000-0123-4567-8910-000000000004' start_event = get_sample_start_event(player_id=player_id, session_id=session_id) end_event = get_sample_end_event(player_id=player_id, session_id=session_id) completed_state_before = completed_session_exists(player_id, session_id) # the other way around. insert_end_event(end_event) insert_start_event(start_event) completed_state_after = completed_session_exists(player_id, session_id) assert completed_state_before is False and completed_state_after is True
def test_validate_start_event__invalid_country_format(): event = get_sample_start_event() event['country'] = 'AAE' with pytest.raises(ValueError) as e_info: validate_start_event(event)
def test_validate_start_event__invalid_session_id(): event = get_sample_start_event() event['session_id'] = 'e0d83Öe6-2128-436b-a689-38c47a477118' with pytest.raises(ValueError) as e_info: validate_start_event(event)
def test_validate_start_event__invalid_player_id(): event = get_sample_start_event() event['player_id'] = '02a05GÖÖÖÖ1372394597aa76c89f106aa547' with pytest.raises(ValueError) as e_info: validate_start_event(event)
def test_validate_start_event__invalid_ts(): event = get_sample_start_event() event['ts'] = '2016-00-06T03:11:56' with pytest.raises(ValueError) as e_info: validate_start_event(event)
def test_validate_start_event__missing_ts(): event = get_sample_start_event() del event['ts'] with pytest.raises(TypeError) as e_info: validate_start_event(event)