Beispiel #1
0
    def test_update_itemlist_success(self):
        itemlist_id = ItemList.select().get().id

        body = { 'name': 'Test' }
        response = client.put('/lists/{}'.format(itemlist_id), json=body)
        itemlist = json.loads(response.data)
        assert itemlist['name'] == 'Test'
Beispiel #2
0
    def test_update_itemlist_failure(self):
        itemlist_id = ItemList.select().get().id

        body = { 'name': None }
        response = client.put('/lists/{}'.format(itemlist_id), json=body)

        assert response.status_code == 422
Beispiel #3
0
 def update_itemlist(self, listitem_id, body):
     """Update itemlist's name field with field from body, given ID"""
     itemlist = ItemList.select().where(ItemList.id == listitem_id).get()
     itemlist.name = body[
         'name']  # If tests looked for more than name, an update query would be nessesary.
     itemlist.save()
     return itemlist  # Return model
Beispiel #4
0
def test_list():
    print(ItemList.get(26))
    try:
        print(ItemList.get(100))
    except IndexError as err:
        print(err)

    #ItemList.delete(26)
    fields = 'first_name second_name last_name birthday sex position dpt is_archive'.split()
            
    person_row = 'Иванов,Иван,Иванович,1997-08-30,М,Программист,2,True'.split(',')
    person_dict = {k:v for k,v in zip(fields, person_row)}
    print(person_dict)

    #new_person = ItemList.create(person_dict)
    #print(new_person)
Beispiel #5
0
 def getItemList(self, request):
     print "creating Customer"
     c = []
     query1 = Item.query()
     print query1
     entity1 = query1.get()
     print entity1
     for q in query1:
         c.append(self._copyItemsToForm(q))
     return ItemList(itemList=c)
Beispiel #6
0
 def get_item(self, item_id):
     """возвращает элемент по id"""
     self.set_header('Content-Type', 'application/json')
     try:
         idx = int(item_id)
         item = ItemList.get(idx)
         response = json_serialize(item)
         self.write(response)
     except IndexError as err:
         self.set_status(404, 'Item not found')
         self.write({'message': 'DoesNotExist'})
Beispiel #7
0
 def create_item(self):
     """Добавляет новый элемент"""
     self.set_header('Content-Type', 'application/json')
     try:
         req = { k: self.get_argument(k) for k in self.request.arguments }
         item = ItemList.create(req)
         response = json_serialize(item)
         self.write(response)
     except IntegrityError as err:
         self.set_status(405, 'Invalid input')
         self.write({'message': 'IntegrityError'})
Beispiel #8
0
 def delete(self, item_id, action=None):
     """Обработка путей метода DELETE"""
     if not item_id or action is not None:
         self.error404()
     else:
         #DELETE  {prefix}/{id}	    удаляет элемент
         self.set_header('Content-Type', 'application/json')
         try:
             idx = int(item_id)
             response = ItemList.delete(idx)
             self.write({'message': 'OK'})
         except IndexError as err:
             self.set_status(404, 'Item not found')
             self.write({'message': 'DoesNotExist'})
Beispiel #9
0
    def get(self):
        # Check if the list name is provided
        list_key = self.request.get('list_key')
        
        try:
            # Add the new list to the database
            grocery_list_key = ItemList.delete(list_key)

            # Respond with the list key
            self.response.set_status(201)
            self.response.write(grocery_list_key)
        except Exception as e:
            # Respond with the error
            self.response.set_status(406)
            self.response.write(str(e))
Beispiel #10
0
def seed():
    # Delete the table data.
    Item.delete().execute()
    ItemList.delete().execute()

    # Create the initial item list
    item_list = ItemList(name='Main List')
    item_list.save()

    ItemList(name='Secondary List').save()

    # Create items under the item list
    Item(name='Clean the room', item_list=item_list.id).save()
    Item(name='Take out the trash', item_list=item_list.id).save()
    Item(name='Sweep the floors', item_list=item_list.id).save()
Beispiel #11
0
    def get(self):

        # Check if the list name is provided
        list_key = self.request.get('list_key')
        changed_content_str = self.request.get('changed_content')

        try:
            # Add the new list to the database
            changed_content = JSON.decode(changed_content_str)
            new_content = ItemList.update_content(list_key, changed_content)

            # Respond with the list key
            self.response.set_status(201)
            self.response.write(new_content)
        except Exception as e:
            # Respond with the error
            self.response.set_status(406)
            self.response.write(str(e))
Beispiel #12
0
 def put(self, item_id, action=None):
     """Обработка путей метода PUT"""
     if not item_id or action is not None:
         self.error404()
     else:
         #PUT     {prefix}/{id}	    обновляет значение элемента
         self.set_header('Content-Type', 'application/json')
         try:
             idx = int(item_id)
             req = { k: self.get_argument(k) for k in self.request.arguments }
             item = ItemList.update(idx, req)
             response = json_serialize(item)
             self.write(response)
         except IndexError as err:
             self.set_status(404, 'Item not found')
             self.write({'message': 'DoesNotExist'})
         except IntegrityError as err:
             self.set_status(405, 'Validation Exception')
             self.write({'message': 'Validation Exception'})
         except OutdatedError as err:
             self.set_status(400, 'Item is outdated')
             self.write({'message': 'Item is outdated'})
Beispiel #13
0
def add_item(restaurant_id, menu_code):
    form = ItemAddForm()

    if form.validate_on_submit():
        new_menu = ItemList(
            name=form.name.data,
            description=form.description.data,
            price=form.price.data,
            menu_code=menu_code,
        )

        # Commit to the database
        db.session.add(new_menu)
        db.session.commit()

        # Now that it successfully saved to the db, we can save to disk
        save_food_image(form.image.data.read(), restaurant_id, new_menu.item_code)
        return redirect(
            url_for("list_food_items", restaurant_id=restaurant_id, menu_code=menu_code)
        )

    return render_template("item_add.html", form=form)
Beispiel #14
0
 def get_all_itemlists(self):
     """Return model array of itemlists"""
     return ItemList.select()  # Return model array
 def create_itemlist(self, body):
     return ItemList.create(name=body['name'])
 def get_all_itemlists(self):
     return ItemList.select()
Beispiel #17
0
    def test_delete_itemlist(self):
        itemlist_id = ItemList.select().get().id

        response = client.delete('/lists/{}'.format(itemlist_id))

        assert response.status_code == 404
Beispiel #18
0
 def get_index(self):
     """Возвращает список всех сотрудников"""
     self.set_header('Content-Type', 'application/json')
     items = ItemList.get_index()
     response = json_serialize(items)
     self.write(response)
Beispiel #19
0
    def test_get_itemlist(self):
        itemlist_id = ItemList.select().get().id

        response = client.get('/lists/{}'.format(itemlist_id))
        itemlist = json.loads(response.data)
        assert itemlist['id']
Beispiel #20
0
 def get(self):
     self.set_header('Content-Type', 'application/json')
     items = ItemList.get_dpt()
     response = json_serialize(items)
     self.write(response)
Beispiel #21
0
 def get_itemlist(self, listitem_id):
     """Return itemlist with given ID"""
     itemlist = ItemList.select().where(ItemList.id == listitem_id).get()
     return itemlist  # Return model
Beispiel #22
0
 def delete_itemlist(self, listitem_id):
     """Delete itemlist with given ID"""
     ItemList.delete().where(ItemList.id == listitem_id).execute()
     return  # Return nothing
Beispiel #23
0
    def test_get_all_items_for_list(self):
        itemlist_id = ItemList.select().get().id

        response = client.get('/lists/{}/items'.format(itemlist_id))
        items = json.loads(response.data)
        assert len(items) == 3
Beispiel #24
0
 def create_itemlist(self, body):
     """Create itemlist model with fields from body"""
     itemlist = ItemList.create(**body)
     return itemlist  # Return model