class CategoryDAOTest(unittest.TestCase):
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()

        self.cat_dao = CategoryDAO()

        self.cat_arroces = Category(name="Arroces", description="Arrocitos")
        self.cat_sopas = Category(name="Sopas e cremas", description="Categoria chula")
        self.cat_pastas = Category(name="Pastas", description="Fresco, fresco")

        self.cat_arroces_key = self.cat_arroces.put()
        self.assertEqual(Category.query().count(), 1, "Failed to initialize test")

    def tearDown(self):
        self.testbed.deactivate()

    def test_save_category(self):
        self.cat_dao.save(self.cat_sopas)
        self.assertEqual(Category.query().count(), 2)
        self.cat_dao.save(self.cat_pastas)
        self.assertEqual(Category.query().count(), 3)
        self.assertIsInstance(Category.query().fetch()[0], Category)

    def test_get_category(self):
        r = self.cat_dao.get(self.cat_arroces_key.urlsafe())
        self.assertIsInstance(r, Category)
        self.assertEqual(r.name, u"Arroces")

    def test_delete_category(self):
        self.cat_dao.delete(self.cat_arroces.key.urlsafe())
        num_categories = Category.query().count()
        self.assertEqual(num_categories, 0)

    def test_update_category(self):
        self.cat_arroces.name = "Arrocines"
        self.cat_dao.update(self.cat_arroces)
        self.cat_arroces = Category.query().fetch()[0]
        self.assertEqual(self.cat_arroces.name, "Arrocines")

    def test_get_all(self):
        self.cat_pastas.put()
        self.cat_sopas.put()
        cat_list = self.cat_dao.get_all()
        self.assertEqual(len(cat_list), 3)
        self.assertIsInstance(cat_list[0], Category)
        self.assertEqual(cat_list[0].name, u"Arroces")
        self.assertIsInstance(cat_list[1], Category)
        self.assertEqual(cat_list[1].name, u"Pastas")
        self.assertIsInstance(cat_list[2], Category)
        self.assertEqual(cat_list[2].name, u"Sopas e cremas")
Beispiel #2
0
def do_inserts():
    cat_arroces = Category(name="Arroces", description="Arrocitos")
    code = cat_arroces.put().urlsafe()
    cat_arroces.id = code
    cat_arroces.put()
    cat_pastas = Category(name="Pastas", description="Lorem ipsum")
    code = cat_pastas.put().urlsafe()
    cat_pastas.id = code
    cat_pastas.put()
    cat_sopas = Category(name="Sopas e cremas", description="Fresco, fresco")
    code = cat_sopas.put().urlsafe()
    cat_sopas.id = code
    cat_sopas.put()
    rec1 = Recipe(name="Arroz con chícharos",
                  category=cat_arroces,
                  servings=4,
                  ingredients=[Ingredient(name="Arroz", quantity="500gr"),
                               Ingredient(name="Chícharos", quantity="300gr")],
                  steps=["Cocemos o arroz", "Botámoslle os chícharos", "Servir en quente"])
    rec2 = Recipe(name="Macarróns con tomate",
                  category=cat_pastas,
                  servings=6,
                  ingredients=[Ingredient(name="Macarróns", quantity="600gr"),
                               Ingredient(name="Tomate frito", quantity="100gr")],
                  steps=["Cocemos os macarróns",
                         "Botámoslleo tomate frito",
                         "Servimos en quente"])
    rec3 = Recipe(name="Gazpacho andaluz",
                  category=cat_sopas,
                  servings=6,
                  ingredients=[Ingredient(name="Aceite de oliva", quantity="120cc"),
                               Ingredient(name="Auga", quantity="500cc"),
                               Ingredient(name="Dente de allo", quantity="2"),
                               Ingredient(name="Ovo duro", quantity="1"),
                               Ingredient(name="Miga de pan", quantity="100gr"),
                               Ingredient(name="Pepino", quantity="50gr"),
                               Ingredient(name="Pemento verdeo", quantity="50gr"),
                               Ingredient(name="Sal", quantity="1 pizca"),
                               Ingredient(name="Tomates naturais", quantity="1kg"),
                               Ingredient(name="Vinagre", quantity="60cc"),
                               Ingredient(name="Cebola picada", quantity="1/2")],
                  steps=[
                      "No bol da batidora ponse o aceite, a vinagre, a sal e ben cortados, os allos, o pepino e o pemento."
                      " Triturase todo ben e vaise metendo na batidora",
                      "Vaise incorporando o tomate, previamente escaldado e pelado, e siguese pasando pola batidora",
                      "Ponse o pan en remollo e escorese e engadeselle o anterior",
                      "Incorporase a auga para que non quede tan espeso e uns cubiños de xeo para que este mais grio",
                      "Servese en tazons e en diferentes pratos individuais. Disponse un pouco de pemento picado, a "
                      "cebola, o pepino, o tomate natural e o ovo duro, previamente cocido, e todo elo finalmente "
                      "picado para engadir se se desexa ao gazpacho"])
    rec1.put()
    rec2.put()
    rec3.put()
Beispiel #3
0
def admin():
    if not session.get("admin"):
        return login()

    if request.method == "POST":
        file = request.files.get("file", None)
        content_type = None
        photo = None
        if file:
            file_data = file.read()
            content_type = file.content_type
            # photo=images.Image(file_data)
            photo = images.resize(file_data, width=500, height=500)

        category = Category(id=request.form["name"].strip(),
                            categoryID=request.form["name"],
                            name=request.form["name"],
                            photo=photo,
                            photo_mimetype=content_type)
        category.put()

    fields = []

    fields.append(
        Field(name="name",
              title="Category Name",
              the_type='text',
              identifier='name',
              placeholder="Category Name"))
    fields.append(
        Field(name='file',
              title="Upload Photo",
              the_type="file",
              placeholder="Upload Photo",
              identifier="file",
              tag="file"))
    title = "Create Category"
    form = Form(fields=fields, title=title)
    reviews = Review.query(Review.flagged == True)
    categories = Category.query()
    return render_template("admin_homepage.html",
                           reviews=reviews,
                           categories=categories,
                           category_form=form)
Beispiel #4
0
def c():
    """Return a friendly HTTP greeting."""
    for i in xrange(10):
        category = Category(categoryID=str(i), name=str(i))
        category.put()
    return "splash!"