def from_json_to_object(json): username = json["store_name"] password = json["password"] email = json["email"] key = json['key'] return Store(username, password, email, key)
def test_create_question_from_real_source_with_category_hard(): """questions can be added form a source""" store = Store() quiz_id = store.create_quiz(OpenTDB, difficulty="hard", category=18) question_id = store.create_question_from_source(quiz_id) question = store.questions[question_id] assert question
def test_get_question(): """questions can be retrieved from the app""" store = Store() quiz_id = store.create_quiz(FakeSource) question_id = store.create_question_from_source(quiz_id) question = store.get_question_by_id(question_id) assert question
def test_get_user_by_id(): """a user can be retrieved from the app""" store = Store() quiz_id = store.create_quiz(FakeSource) user_id = store.create_user(quiz_id, "Someone", False) user = store.get_user_by_id(user_id) assert user
def test_create_user(): """a user can be added to the store and quiz""" store = Store() quiz_id = store.create_quiz(FakeSource) user_id = store.create_user(quiz_id, "Someone", False) user = store.users[user_id] assert user
def post(self, request): # 创建商店 owner = request.u name = request.json.get("name") address = request.json.get("address") announcement = request.json.get("announcement") description = request.json.get("description") phone = request.json.get("phone") image_ids = request.json.get("image_ids") if not all([owner, name, address, announcement, description]): return JsonErrorResponse("owner, name, address, announcement, description, phone are needed", 400) new_store = Store( name=name, address=address, announcement=announcement, description=description, phone=phone, image_ids=image_ids, owner=owner ) try: new_store.save() except Exception, e: print e return JsonErrorResponse("Fail:" + e.message)
def post(self, id): data = request.json if AtRiskUser.query.filter_by(at_risk_user_id=id).first() is None: at_risk_user = AtRiskUser(at_risk_user_id=id, **data) store_info = Krogerservice.closest_store(data['zipcode']) if store_info == {'error': 'no store found for this zipcode'}: return { 'data': { 'id': 'at_risk_user', 'attributes': { 'error': "No Kroger store match AtRiskUser zipcode" } } }, 400 else: store = Store(**store_info, at_risk_user=at_risk_user) db.session.add(at_risk_user) db.session.add(store) db.session.commit() return at_risk_user.json(), 201 else: return { 'data': { 'id': 'at_risk_user', 'attributes': { 'error': "AtRiskUser already exists" } } }, 400
def test_create_question_from_fake_source(): """questions can be added form a source""" store = Store() quiz_id = store.create_quiz(FakeSource) question_id = store.create_question_from_source(quiz_id) question = store.questions[question_id] assert question
def test_create_question_from_real_source(): """questions can be added form a source""" store = Store() quiz_id = store.create_quiz(OpenTDB) question_id = store.create_question_from_source(quiz_id) question = store.questions[question_id] assert question
def post(self): data = self.parser.parse_args() store = Store.find_by_name(**data) if store: return {'error': True, 'message': f'Store already exists'}, 400 store = Store(**data) store.save() return store.json(), 201
def test_create_answer(): """answers can be added to a app and quiz""" store = Store() quiz_id = store.create_quiz(FakeSource) question_id = store.create_question_from_source(quiz_id) answer_id = store.create_answer(question_id, "some answer text", True) answer = store.answers[answer_id] assert answer
def test_create_question(): """questions can be added to a app and quiz""" store = Store() quiz_id = store.create_quiz(FakeSource) question_id = store.create_question( quiz_id, {"text": "some question", "difficulty": "medium", "category": "some category"}) question = store.questions[question_id] assert question
def test_get_answer_by_id(): """answers can be retrieved from the app""" store = Store() quiz_id = store.create_quiz(FakeSource) question_id = store.create_question_from_source(quiz_id) answer_id = store.create_answer(question_id, "some answer text", True) answer = store.get_answer_by_id(answer_id) assert answer
def set_stores(self, clean_stores): """ Method that creates a list of objects stores - for each store in stores list - instantiate a store object - adds each store object to the list. """ self.stores = [Store(clean_store) for clean_store in clean_stores]
def store_created() : store_name = request.form.get("store_name") store = Store(name=store_name) if store.save(): flash("Successfully added","success") else : flash("Duplicate Entry!!","danger") return redirect(url_for("stores.store_new"))
def test_get_users_by_id(): """answers can be retrieved from the app""" store = Store() quiz_id = store.create_quiz(FakeSource) user_id_one = store.create_user(quiz_id, "Someone", False) user_id_two = store.create_user(quiz_id, "Someone", False) users = store.get_users_by_id([user_id_one, user_id_two]) assert type(users) is list
def post(self, name): if Store.findByName(name): return {"message":"a store with name {} already exists".format(name)},400 store = Store(name) try: store.saveToDB() except: return {"message":"an error occurred while creating your store"},500 return store.json(),201
def new_store(): if request.method == 'POST': store = Store(name=request.form['store_name'], url_prefix=request.form['url'], tag_name=request.form['tag_name'], query=json.loads(request.form['query'])) if store: store.save_to_mongo() return render_template('stores/new_store.html')
def create_store(): if request.method == 'POST': name = request.form['name'] url_prefix = request.form['url_prefix'] tag_name = request.form['tag_name'] query = json.loads(request.form['query']) Store(name, url_prefix, tag_name, query).save_to_mongo() return render_template("stores/new_store.html")
def create_store(): if request.method == "POST": store_name = request.form["store_name"] url_prefix = request.form["url_prefix"] tag_name = request.form["tag_name"] attrs = json.loads(request.form["attrs"]) Store(store_name, url_prefix, tag_name, attrs).save_to_mongo() return render_template("stores/new_store.html")
def post(self, name): store = Store.find_by_name(name) if store: return {"message": "store '{}'already there.".format(name)}, 400 store = Store(name) try: store.save_to_db() except(e): print(e) return store.json()
def create_store(): if request.method == "POST": name = request.form["name"] url_prefix = request.form["url_prefix"] tag_name = request.form["tag_name"] query = json.loads(request.form["query"]) Store(name, url_prefix, tag_name, query).save_to_mongo() return render_template("stores/new_store.html")
def new_store(): if request.method == "POST": name = request.form["store_name"] tag_name = request.form["tag_name"] url_prefix = request.form["store_url"] query = json.loads(request.form["query"]) Store(name, url_prefix, tag_name, query).save_to_database() return render_template("/stores/new_store.html")
def store_div_to_store(store_div): try: brand = store_div.find('b').contents[0] location = store_div.find_all('br') address = unidecode.unidecode(str(location[2].next)) postal_code = str(location[3].next).split()[0] formated_brand = raw_brand_to_formated_brand(brand) return Store(brands[formated_brand], address, postal_code, str(brand)) except: return None
def create_store(): if request.method == 'POST': name = request.form['name'] url_prefix = request.form['url_prefix'] tag_name = request.form['tag_name'] query = json.loads(request.form['query']) Store(name, url_prefix, tag_name, query).save_to_mongo() flash('Store successfully added', 'info') return render_template('stores/new_store.html')
def create_store(): if request.method == 'POST': name = request.form['name'] url_prefix = request.form['url_prefix'] tag_name = request.form['tag_name'] query = json.loads(request.form['query']) Store(name, url_prefix, tag_name, query).persist() stores = Store.all() return render_template('/stores/index.html', stores=stores) else: return render_template('/stores/new_store.html')
def new_store(): if request.method == 'POST': name = request.form['store_name'] url_prefix = request.form['url_prefix'] tag_name = request.form['tag_name'] query = json.loads(request.form['query']) Store(name, url_prefix, tag_name, query).save_to_mongo() return redirect(url_for('stores.index')) return render_template('stores/new_store.html')
def create_store(): if request.method == 'POST': name = request.form['name'] url_prefix = request.form['url_prefix'] tag_name = request.form['tag_name'] query = json.loads(request.form['query']) Store(name, url_prefix, tag_name, query).save_to_mongo() # short hand for parsing all valuables to store.py and save_to_mongo() return render_template('stores/new_store.html')
def new_store(): if request.method == "POST": store_name = request.form["store_name"] url_prefix = request.form["url_prefix"] tag_name = request.form["tag_name"] query = json.loads(request.form["html_query"]) Store(store_name, url_prefix, tag_name, query).save_to_mongo() return redirect(url_for(".index")) return render_template("/stores/new_store.html")
def test_get_answers_by_id(): """answers can be retrieved from the app""" store = Store() quiz_id = store.create_quiz(FakeSource) question_id = store.create_question_from_source(quiz_id) answer_id_one = store.create_answer( question_id, "some answer text", True) answer_id_two = store.create_answer( question_id, "some answer text", False) answers = store.get_answers_by_id([answer_id_one, answer_id_two]) assert type(answers) is list