当前位置: 首页>>代码示例>>Python>>正文


Python Messages.categoryAlreadyExists方法代码示例

本文整理汇总了Python中fivecents.lib.i18n.Messages.categoryAlreadyExists方法的典型用法代码示例。如果您正苦于以下问题:Python Messages.categoryAlreadyExists方法的具体用法?Python Messages.categoryAlreadyExists怎么用?Python Messages.categoryAlreadyExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fivecents.lib.i18n.Messages的用法示例。


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

示例1: _edit_category

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import categoryAlreadyExists [as 别名]
    def _edit_category(self, category_tc, is_new = True):
        dbFacade = self.dbFacade();
        new_category_name = request.params.get('name');
        parent_name = request.params.get('parent');

        if dbFacade.balances.categoryDao.find_by_name(new_category_name, h.authenticated_user().uid):
            return { "failure" : Messages.categoryAlreadyExists(name=new_category_name) }
        parent_tc = dbFacade.balances.categoryDao.find_by_name(parent_name, h.authenticated_user().uid)

        if not parent_tc or parent_tc.name == '' or not new_category_name:
            return { "failure" : Messages.invalidArguments() }
        if not hasattr(parent_tc, 'subcats') or not parent_tc.subcats:            
            return { "failure" : Messages.wrongParentCategory(name=parent_name) }

        category_tc.name = new_category_name
        category_tc.parent = parent_tc.key
        category_tc.user_uid = h.authenticated_user().uid
        dbFacade.balances.categoryDao.save(category_tc)

        if not is_new:
            self._change_changes_category(request.params.get('old_name'), new_category_name)

        dbFacade.db.commit()
        return { "id" : category_tc.uid }     
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:26,代码来源:balance_categories.py

示例2: test_category_manage

# 需要导入模块: from fivecents.lib.i18n import Messages [as 别名]
# 或者: from fivecents.lib.i18n.Messages import categoryAlreadyExists [as 别名]
    def test_category_manage(self):

        existing_balance_url = url_for(controller='rest/balance_changes', action='list')
        response = self.app.get(existing_balance_url)
        self.assertEquals(200, response.status)

        signin_form = response.forms.get('login_form')
        self.failUnless(signin_form)
        signin_form.set('username', '[email protected]')
        signin_form.set('password', '[email protected]')
        response = signin_form.submit()
        self.assertEquals(200, response.status)

        category_name = 'Test1'        
        
        self.failIf(self.__in_categories(category_name)) 
        
        """ Add new category - Test1 """
        existing_balance_url = url_for(controller='rest/balance_categories', action='add', name=category_name, parent='Dom')
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)        
        status = result.get('id')
        self.failIf(status is None)


        """ Add category again - Test1 should be failure"""
        existing_balance_url = url_for(controller='rest/balance_categories', action='add', name=category_name, parent='Dom')
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)
        status = result.get('failure')
        self.assertEquals(status, Messages.categoryAlreadyExists(name=category_name))
        self.assertEquals(self.__in_categories(category_name), True)

        """ Edit category name """
        category_name_edit = 'Test2'
        existing_balance_url = url_for(controller='rest/balance_categories', 
                                       action='edit', name=category_name_edit, 
                                       old_name = category_name,
                                       parent='Dom')
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)
        
        status = result.get('id')
        self.failIf(status is None)

        """ Edit category name again - should be error"""
        category_name_edit = 'Test2'
        existing_balance_url = url_for(controller='rest/balance_categories', 
                                       action='edit', name=category_name_edit, 
                                       old_name = category_name, 
                                       parent='Dom')
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)
        
        status = result.get('failure')
        self.assertEquals(status, Messages.elementNotFound(key=category_name))

        """ Delete category Test 2 """        
        existing_balance_url = url_for(controller='rest/balance_categories', 
                                       action='delete', name=category_name_edit, 
                                       )
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)
        
        status = result.get('failure')
        self.assertEquals(status, None)
        self.failIf(self.__in_categories(category_name_edit))

        """ Delete category Test 1 - Fail """        
        existing_balance_url = url_for(controller='rest/balance_categories', 
                                       action='delete', name=category_name, 
                                       )
        response = self.app.post(existing_balance_url)
        self.assertEquals(200, response.status)
        self.assertEquals('application/x-javascript', response.header('Content-Type'))
        result = json.loads(response.body)
        self.failIf(result is None)
        
        status = result.get('failure')
        self.assertEquals(status, Messages.elementNotFound(key=category_name))
        self.failIf(self.__in_categories(category_name))
开发者ID:pawelniewie,项目名称:5groszy.pl,代码行数:98,代码来源:test_rest_balance_categories.py


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