• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python storage.delete函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中models.storage.delete函数的典型用法代码示例。如果您正苦于以下问题:Python delete函数的具体用法?Python delete怎么用?Python delete使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了delete函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: do_destroy

    def do_destroy(self, args):
        """
        Destroys an instance
        Usage: destroy <ClassName> <id>
        Order of arguments is not checked

        **Arguments**
            ClassName: name of class
            id: unique user id of instance
        """
        args = args.split()
        if len(args) == 0:
            print("** class name missing **")
            return
        if len(args) == 1:
            print("** instance id missing **")
            return
        if args[0] not in HBNBCommand.valid_classes.keys():
            print("** class doesn't exist **")
            return
        all_objs = storage.all()
        for k, v in all_objs.items():
            if k == args[1] and args[0] == v.__class__.__name__:
                storage.delete(v)
                return
        print("** no instance found **")
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:26,代码来源:console.py


示例2: test_view_one_state_wrong

 def test_view_one_state_wrong(self):
     """the id does not match a state"""
     state_args = {"name": "Zanzibar", "id": "ZA1"}
     state = State(**state_args)
     state.save()
     rv = self.app.get('{}/states/{}/'.format(self.path, "noID"))
     self.assertEqual(rv.status_code, 404)
     storage.delete(state)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:8,代码来源:test_states.py


示例3: test_delete_amenity_wrong

 def test_delete_amenity_wrong(self):
     """the id does not match a amenity"""
     amenity_args = {"name": "quokka", "id": "QO"}
     amenity = Amenity(**amenity_args)
     amenity.save()
     rv = self.app.delete('{}/amenities/{}/'.format(self.path, "noID"),
                          follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(amenity)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:9,代码来源:test_amenities.py


示例4: test_view_one_city_wrong

 def test_view_one_city_wrong(self):
     """the id does not match a city"""
     city_args = {"name": "Gaborone", "id": "GA", "state_id": "BO"}
     city = City(**city_args)
     city.save()
     rv = self.app.get('{}/cities/{}/'.format(self.path, "noID"),
                       follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(city)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:9,代码来源:test_cities.py


示例5: test_getcities_badstate

 def test_getcities_badstate(self):
     """test listing all cities with a bad state id"""
     city_args = {"name": "Gaborone", "id": "GA", "state_id": "BO"}
     city = City(**city_args)
     city.save()
     rv = self.app.get('{}/states/{}/cities'.format(self.path, "noID"),
                       follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(city)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:9,代码来源:test_cities.py


示例6: test_link_bad_amenity_place

 def test_link_bad_amenity_place(self):
     """test linking a non existing amenity to a place"""
     amenity_args = {"name": "bear", "id": "BA"}
     amenity = Amenity(**amenity_args)
     amenity.save()
     rv = self.app.post('{}/places/{}/amenities/{}/'.format(
         self.path, self.place.id, "noID"),
                       follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(amenity)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:10,代码来源:test_places_amenities.py


示例7: test_delete_review_wrong

 def test_delete_review_wrong(self):
     """the id does not match a review"""
     review_args = {"text": "sad cage", "place_id": self.place.id,
                    "user_id": self.user.id, "id": "RCA"}
     review = Review(**review_args)
     review.save()
     rv = self.app.delete('{}/reviews/{}/'.format(self.path, "noID"),
                          follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(review)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:10,代码来源:test_places_reviews.py


示例8: test_getreviews_bad_place

 def test_getreviews_bad_place(self):
     """test listing all reviews with a bad place id"""
     review_args = {"text": "what a cage", "place_id": self.place.id,
                    "user_id": self.user.id}
     review = Review(**review_args)
     review.save()
     rv = self.app.get('{}/places/{}/reviews/'.format(self.path, "noID"),
                       follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(review)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:10,代码来源:test_places_reviews.py


示例9: test_getplaces_bad_city

 def test_getplaces_bad_city(self):
     """test listing all places with a bad city id"""
     place_args = {"name": "cage", "city_id": self.city.id,
                   "user_id": self.user.id}
     place = Place(**place_args)
     place.save()
     rv = self.app.get('{}/cities/{}/places'.format(self.path, "noID"),
                       follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(place)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:10,代码来源:test_places.py


示例10: test_delete_place_wrong

 def test_delete_place_wrong(self):
     """the id does not match a place"""
     place_args = {"name": "cage", "city_id": self.city.id,
                   "user_id": self.user.id, "id": "CA"}
     place = Place(**place_args)
     place.save()
     rv = self.app.delete('{}/places/{}/'.format(self.path, "noID"),
                          follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(place)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:10,代码来源:test_places.py


示例11: test_delete_user_wrong

 def test_delete_user_wrong(self):
     """the id does not match a user"""
     user_args = {"first_name": "quokka", "id": "QO",
                  "email": "[email protected]", "password": "1234"}
     user = User(**user_args)
     user.save()
     rv = self.app.delete('{}/users/{}/'.format(self.path, "noID"),
                          follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(user)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:10,代码来源:test_users.py


示例12: test_update_amenity_bad_id

 def test_update_amenity_bad_id(self):
     """test update with no matching id"""
     amenity_args = {"name": "quokka", "id": "QO"}
     amenity = Amenity(**amenity_args)
     amenity.save()
     rv = self.app.put('{}/amenities/{}/'.format(self.path, "noID"),
                       content_type="application/json",
                       data=json.dumps({"id": "Z"}),
                       follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(amenity)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:11,代码来源:test_amenities.py


示例13: test_getstates_empty_db

 def test_getstates_empty_db(self):
     """test listing all states in empty db"""
     s = storage.all("State").values()
     for e in s:
         storage.delete(e)
     rv = self.app.get('{}/states/'.format(self.path))
     self.assertEqual(rv.status_code, 200)
     self.assertEqual(rv.headers.get("Content-Type"), "application/json")
     json_format = getJson(rv)
     self.assertTrue(type(json_format), list)
     self.assertEqual(json_format, [])
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:11,代码来源:test_states.py


示例14: test_update_state_bad_id

 def test_update_state_bad_id(self):
     """test update with no matching id"""
     state_args = {"name": "Zanzibar", "id": "ZA6"}
     state = State(**state_args)
     state.save()
     rv = self.app.put('{}/states/{}/'.format(self.path, "noID"),
                       content_type="application/json",
                       data=json.dumps({"id": "Z"}),
                       follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(state)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:11,代码来源:test_states.py


示例15: test_update_city_bad_id

 def test_update_city_bad_id(self):
     """test update with no matching id"""
     city_args = {"name": "Gaborone", "id": "GA", "state_id": "BO"}
     city = City(**city_args)
     city.save()
     rv = self.app.put('{}/cities/{}/'.format(self.path, "noID"),
                       content_type="application/json",
                       data=json.dumps({"name": "Z"}),
                       follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(city)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:11,代码来源:test_cities.py


示例16: test_delete_amenity_not_in_place

 def test_delete_amenity_not_in_place(self):
     """test remove an amenity from a place without this amenity"""
     amenity_args = {"name": "bear", "id": "BA"}
     amenity = Amenity(**amenity_args)
     amenity.save()
     # self.place.save()
     rv = self.app.delete('{}/places/{}/amenities/{}/'.format(
         self.path, self.place.id, amenity.id),
                          follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(amenity)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:11,代码来源:test_places_amenities.py


示例17: test_update_city_bad_id

 def test_update_city_bad_id(self):
     """test update with no matching id"""
     place_args = {"name": "cage", "city_id": self.city.id,
                   "user_id": self.user.id, "id": "CA"}
     place = Place(**place_args)
     place.save()
     rv = self.app.put('{}/places/{}/'.format(self.path, "noID"),
                       content_type="application/json",
                       data=json.dumps({"name": "Z"}),
                       follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(place)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:12,代码来源:test_places.py


示例18: test_update_state_bad_json

 def test_update_state_bad_json(self):
     """test update with ill formedt json"""
     state_args = {"name": "Zanzibar", "id": "ZA5"}
     state = State(**state_args)
     state.save()
     rv = self.app.put('{}/states/{}/'.format(self.path, state.id),
                       content_type="application/json",
                       data={"id": "Z"},
                       follow_redirects=True)
     self.assertEqual(rv.status_code, 400)
     self.assertEqual(rv.get_data(), b"Not a JSON")
     storage.delete(state)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:12,代码来源:test_states.py


示例19: test_getstates

 def test_getstates(self):
     """test listing all states"""
     state_args = {"name": "Zanzibar"}
     state = State(**state_args)
     state.save()
     rv = self.app.get('{}/states/'.format(self.path))
     self.assertEqual(rv.status_code, 200)
     self.assertEqual(rv.headers.get("Content-Type"), "application/json")
     json_format = getJson(rv)
     self.assertTrue(type(json_format), list)
     self.assertIn(state_args["name"], [e.get("name") for e in json_format])
     storage.delete(state)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:12,代码来源:test_states.py


示例20: test_update_user_bad_id

 def test_update_user_bad_id(self):
     """test update with no matching id"""
     user_args = {"first_name": "quokka", "id": "QO",
                  "email": "[email protected]", "password": "1234"}
     user = User(**user_args)
     user.save()
     rv = self.app.put('{}/users/{}/'.format(self.path, "noID"),
                       content_type="application/json",
                       data=json.dumps({"id": "Z"}),
                       follow_redirects=True)
     self.assertEqual(rv.status_code, 404)
     storage.delete(user)
开发者ID:butcallmeJo,项目名称:airbnb_clone,代码行数:12,代码来源:test_users.py



注:本文中的models.storage.delete函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python stream.getStream函数代码示例发布时间:2022-05-27
下一篇:
Python sitevar.Sitevar类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap