def test_sets(db_conn, users_sets_table): """ Expect to require a list of set IDs. """ user_sets, errors = UserSets.insert({'user_id': 'A'}) assert len(errors) == 1 user_sets['set_ids'] = [ 'A', 'B', ] user_sets, errors = user_sets.save() assert len(errors) == 0
def test_user(db_conn, users_sets_table): """ Expect to require a user ID. """ user_sets, errors = UserSets.insert(db_conn, { 'set_ids': [ 'A', 'B', ], }) assert len(errors) == 1 user_sets['user_id'] = 'A' user_sets, errors = user_sets.save(db_conn) assert len(errors) == 0
def test_sets(db_conn, users_sets_table): """ Expect to require a list of set IDs. """ user_sets, errors = UserSets.insert(db_conn, { 'user_id': 'A' }) assert len(errors) == 1 user_sets['set_ids'] = [ 'A', 'B', ] user_sets, errors = user_sets.save(db_conn) assert len(errors) == 0
def test_user(db_conn, users_sets_table): """ Expect to require a user ID. """ user_sets, errors = UserSets.insert({ 'set_ids': [ 'A', 'B', ], }) assert len(errors) == 1 user_sets['user_id'] = 'A' user_sets, errors = user_sets.save() assert len(errors) == 0
def add_set_route(request, user_id, set_id): """ Add a set to the learner's list of sets. """ db_conn = request['db_conn'] current_user = get_current_user(request) if not current_user: return abort(401) if user_id != current_user['id']: return abort(403) set_ = Set.get(db_conn, entity_id=set_id) if not set_: return abort(404) uset = UserSets.get(db_conn, user_id=user_id) if uset and set_id in uset['set_ids']: return 400, { 'errors': [{ 'name': 'set_id', 'message': 'Set is already added.', }], 'ref': 'kPZ95zM3oxFDGGl8vBdR3J3o', } if uset: uset['set_ids'].append(set_id) uset, errors = uset.save(db_conn) else: uset, errors = UserSets.insert(db_conn, { 'user_id': user_id, 'set_ids': [set_id], }) if errors: return 400, { 'errors': errors, 'ref': 'zCFUbLBTg9n2DnTkQYbqO4X9' } return 200, {'sets': uset['set_ids']}
def add_set_route(request, user_id, set_id): """ Add a set to the learner's list of sets. """ current_user = get_current_user(request) if not current_user: return abort(401) if user_id != current_user['id']: return abort(403) set_ = Set.get(entity_id=set_id) if not set_: return abort(404) uset = UserSets.get(user_id=user_id) if uset and set_id in uset['set_ids']: return 400, { 'errors': [{ 'name': 'set_id', 'message': 'Set is already added.', }], 'ref': 'kPZ95zM3oxFDGGl8vBdR3J3o', } if uset: uset['set_ids'].append(set_id) uset, errors = uset.save() else: uset, errors = UserSets.insert({ 'user_id': user_id, 'set_ids': [set_id], }) if errors: return 400, {'errors': errors, 'ref': 'zCFUbLBTg9n2DnTkQYbqO4X9'} return 200, {'sets': uset['set_ids']}