def setUp(self):
     self.w = wishList.build()
     self.w.attr["fridge_id"] = 1
     self.w.attr["name"] = "豆腐"
     self.w.attr["quantity"] = 1
     self.w.attr["kind"] = "乳製品"
     self.w.attr["last_updated"] = datetime.datetime.now()
     wishList.migrate()
     self.w.save()
Пример #2
0
    def get(self):
        if not self.current_user:
            self.redirect("/signin")
            return
        # サインインユーザーの取得
        _id = tornado.escape.xhtml_escape(self.current_user)
        _signedInUser = user.find(int(_id))

        w = wishList.build()
        self.render("wishList_form.html", user=_signedInUser, mode="new", wishList=w, messages=[], errors=[])
Пример #3
0
 def test_delete(self):
     w = wishList.build()
     w.attr["id"] = 1
     w.attr["user_id"] = 1
     w.attr["name"] = "豆腐"
     w.attr["quantity"] = 1
     w.attr["kind"] = "乳製品"
     result = w.save()
     self.assertTrue(type(result) is int)
     self.assertTrue(w.attr["id"] is not None)
    def test_kind(self):
        fridge_id = 2
        kind = "肉"

        w1 = wishList.build()
        w1.attr["fridge_id"] = fridge_id
        w1.attr["name"] = "牛肉"
        w1.attr["quantity"] = 1
        w1.attr["kind"] = kind
        w1_id = w1.save()

        w2 = wishList.build()
        w2.attr["fridge_id"] = fridge_id
        w2.attr["name"] = "豚肉"
        w2.attr["quantity"] = 2
        w2.attr["kind"] = kind
        w2_id = w2.save()
        w_list = wishList.kind(fridge_id, kind)
        self.assertEqual(len(w_list), 2)
        self.assertTrue(type(w_list[0]) is wishList)
        self.assertTrue(
            w_list[0].attr["quantity"] < w_list[1].attr["quantity"])
    def test_name(self):
        fridge_id = 2
        name = "豆腐"

        w1 = wishList.build()
        w1.attr["fridge_id"] = fridge_id
        w1.attr["name"] = name
        w1.attr["quantity"] = 1
        w1.attr["kind"] = "乳製品"
        w1_id = w1.save()

        w2 = wishList.build()
        w2.attr["fridge_id"] = fridge_id
        w2.attr["name"] = name
        w2.attr["quantity"] = 2
        w2.attr["kind"] = "乳製品"
        w2_id = w2.save()
        w_list = wishList.name(fridge_id, name)
        self.assertEqual(len(w_list), 2)
        self.assertTrue(type(w_list[0]) is wishList)
        self.assertTrue(
            w_list[0].attr["quantity"] < w_list[1].attr["quantity"])
Пример #6
0
    def post(self):
        if not self.current_user:
            self.redirect("/signin")
            return
        # サインインユーザーの取得
        _id = tornado.escape.xhtml_escape(self.current_user)
        _signedInUser = user.find(int(_id))

        # POSTされたパラメータを取得
        p_name = self.get_argument("form-name", None)
        p_quantity = self.get_argument("form-quantity", None)
        p_kind = self.get_argument("form-kind", None)
        #p_last_updated = self.get_argument("form-last_updated", None)

        # 現金出納帳データの組み立て
        w = wishList.build()
        w.attr["user_id"] = int(_id) # ユーザーIDはサインインユーザーより取得

        errors = []
        if p_name is None: errors.append("品名は必須です。")
        w.attr["name"] = p_name

        w.attr["quantity"] = p_quantity

        w.attr["kind"] = p_kind

        #w.attr["last_updated"] = p_last_updated

        if len(errors) > 0: # エラーは新規登録画面に渡す
            self.render("wishList_form.html", user=_signedInUser, mode="new", wishList=w, messages=[], errors=[])
            return

        # 登録
        # print(vars(w))
        w_id = w.save()
        if w_id == False:
            self.render("wishList_form.html", user=_signedInUser, mode="new", wishList=w, messages=[], errors=["登録時に致命的なエラーが発生しました。"])
        else:
            # 登録画面へリダイレクト(登録完了の旨を添えて)
            self.redirect("/wishlist?message=%s" % tornado.escape.url_escape("新規登録完了しました。(ID:%s)" % w_id))
 def test_build(self):
     w = wishList.build()
     self.assertTrue(type(w) is wishList)