def test_get_property_should_return_value_for_property_if_already_answered( app): # Given obj_to_save = [] user = create_user(email='*****@*****.**', username='******', password='******') obj_to_save.append(user) question = Question() question.question_name = 'question_1' obj_to_save.append(question) BaseObject.check_and_save(*obj_to_save) user_property_obj = UserProperty() user_property_obj.user_id = user.id user_property_obj.question_id = question.id user_property_obj.value = float(0.5) BaseObject.check_and_save(user_property_obj) # When property_request = req_with_auth(email='*****@*****.**', password='******') \ .get(API_URL + '/property') # Then assert property_request.status_code == 200 content = property_request.json() assert 'question_1' in content assert content['question_1'] == 0.5
def signup(): data = request.json new_user = User(from_dict=request.json) new_user.id = None footprints = data.get('footprints')[0] BaseObject.check_and_save(new_user) objects_to_save = [] for footprint in footprints.get('footprints'): footprint_obj = Footprint(from_dict=footprint) footprint_obj.user_id = int(new_user.get_id()) objects_to_save.append(footprint_obj) # TODO: c'est pas beau mais c'était plus rapide :( answers = footprints.get('answers') for key, value in answers.items(): property_obj = Property.query.filter_by(property_name=key).first() answer_obj = UserProperty() answer_obj.user_id = int(new_user.get_id()) answer_obj.property_id = property_obj.id answer_obj.value = float(value) objects_to_save.append(answer_obj) BaseObject.check_and_save(*objects_to_save) login_user(new_user) return jsonify(new_user._asdict(include=USER_INCLUDES)), 201
def execute(self, data: dict, user_id: int): object_to_save = [] for key, value in data.items(): question = Question.query.filter_by(question_name=key).first() if question is not None \ and value != "": user_property = UserProperty.query. \ filter_by(user_id=user_id). \ filter_by(question_id=question.id). \ first() if user_property is None: user_property = UserProperty() user_property.user_id = user_id user_property.question_id = question.id user_property.value = float(value) object_to_save.append(user_property) else: user_property.value = float(value) object_to_save.append(user_property) BaseObject.check_and_save(*object_to_save) for user_property in object_to_save: HistoryUserProperties().execute(user_property.id, user_property.value)
def execute(self, data: dict, user_id: int): object_to_save = [] for key, value in data.items(): property_obj = Property.query.filter_by(property_name=key).first() if property_obj is not None\ and value != "": user_property_obj = UserProperty.query.\ filter_by(user_id=user_id).\ filter_by(property_id=property_obj.id).\ first() if user_property_obj is None: user_property = UserProperty() user_property.user_id = user_id user_property.property_id = property_obj.id user_property.value = float(value) object_to_save.append(user_property) else: user_property_obj.value = float(value) object_to_save.append(user_property_obj) BaseObject.check_and_save(*object_to_save)