コード例 #1
0
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)
コード例 #2
0
ファイル: test_datasource.py プロジェクト: vraevrae/vraevrae
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
コード例 #3
0
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
コード例 #4
0
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
コード例 #5
0
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
コード例 #6
0
ファイル: views.py プロジェクト: zhaimobile/Take-out
 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)
コード例 #7
0
 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
コード例 #8
0
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
コード例 #9
0
ファイル: test_datasource.py プロジェクト: vraevrae/vraevrae
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
コード例 #10
0
 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
コード例 #11
0
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
コード例 #12
0
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
コード例 #13
0
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
コード例 #14
0
ファイル: product.py プロジェクト: Lamia7/P5_pur_beurre
 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]
コード例 #15
0
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"))
コード例 #16
0
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
コード例 #17
0
	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
コード例 #18
0
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')
コード例 #19
0
ファイル: stores.py プロジェクト: shubhank05/pricing-service
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")
コード例 #20
0
ファイル: stores.py プロジェクト: lbyg1003/pricing-service
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")
コード例 #21
0
 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()
コード例 #22
0
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")
コード例 #23
0
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")
コード例 #24
0
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
コード例 #25
0
ファイル: stores.py プロジェクト: CruzST/price-watch
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')
コード例 #26
0
ファイル: stores.py プロジェクト: farnsies/pricing-service
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')
コード例 #27
0
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')
コード例 #28
0
ファイル: stores.py プロジェクト: tcsterry/pricing-service
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')
コード例 #29
0
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")
コード例 #30
0
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