def sample_login_event(notify_db, notify_db_session): user = create_user() event = LoginEvent(data={ "ip": "8.8.8.8", "user-agent": "GoogleBot" }, user_id=user.id) save_login_event(event) return event
def verify_user_password(user_id): user_to_verify = get_user_by_id(user_id=user_id) data = request.get_json() try: txt_pwd = data['password'] except KeyError: message = 'Required field missing data' errors = {'password': [message]} raise InvalidRequest(errors, status_code=400) if user_to_verify.check_password(txt_pwd): reset_failed_login_count(user_to_verify) if "loginData" in data and data["loginData"] != {}: save_login_event( LoginEvent(user_id=user_id, data=data["loginData"])) return jsonify({}), 204 else: increment_failed_login_count(user_to_verify) message = 'Incorrect password' errors = {'password': [message]} raise InvalidRequest(errors, status_code=400)
def test_save_login_event_should_create_new_login_event(sample_user): login_event = LoginEvent(**{'user': sample_user, 'data': {}}) save_login_event(login_event) assert LoginEvent.query.count() == 1
def test_list_login_events(sample_login_event): LoginEvent(**{'user': sample_login_event.user, 'data': {}}) keys = list_login_events(sample_login_event.user.id) assert len(keys) == 2
def test_list_login_events(sample_login_event): LoginEvent(**{"user": sample_login_event.user, "data": {}}) keys = list_login_events(sample_login_event.user.id) assert len(keys) == 2