def getAllCategories():
     try:
         categories = Category.getAllCategories()
         result_list = []
         for category in categories:
             result_list.append(to_dict(category))
         result = {
             "message": "Success!",
             "categories": result_list
         }
         return jsonify(result), HttpStatus.OK
     except Exception as e:
         return jsonify(reason="Server error", error=e.__str__()), HttpStatus.INTERNAL_SERVER_ERROR # pragma: no mutate
Example #2
0
    def test_get_all_categories(self):
        userData = {'email': 'test', 'password': '******', 'username': '******'}
        user = User(**userData).create()

        categoryData = {'user_id': user.user_id, 'name': 'test_category1'}
        category1 = Category(**categoryData).create()
        categoryData = {'user_id': user.user_id, 'name': 'test_category2'}
        category2 = Category(**categoryData).create()
        categoryData = {'user_id': user.user_id, 'name': 'test_category3'}
        category3 = Category(**categoryData).create()
        categories = Category.getAllCategories()
        assert categories[0] == category1
        assert categories[1] == category2
        assert categories[2] == category3