def test_item_to_project(resource): user_id = resource item = ItemRepo.add_item(description="Thing", location="inbox", user=user_id) project = ItemRepo.item_to_project(item["id"], user_id) assert project is not None assert len(ItemRepo.get_all_items()) == 0 assert project["description"] == "Thing"
def test_store_item(resource): user_id = resource ItemRepo.add_item(description="This is an item", location="inbox", user=user_id) items = ItemRepo.get_all_items() assert len(items) == 1 assert items[0]["description"] == "This is an item" assert items[0]["location"] == "inbox"
def test_item_to_task(resource): user_id = resource ItemRepo.add_item(description="Thing", location="inbox", user=user_id) added_item = ItemRepo.get_all_items()[0] task = ItemRepo.item_to_task(added_item["id"], user_id) # No more items assert len(ItemRepo.get_all_items()) == 0 # Task used to be the item assert task is not None assert task["description"] == "Thing"
def test_item_to_someday(resource): user_id = resource item = ItemRepo.add_item(description="This is an item", location="inbox", user=user_id) someday_item = ItemRepo.item_to_someday(item["id"], user_id) assert someday_item is not None assert item["id"] == someday_item["id"] assert item["description"] == someday_item["description"] assert someday_item["location"] == "someday/maybe"
def test_delete_item(resource): user_id = resource ItemRepo.add_item(description="This is an item", location="inbox", user=user_id) items = ItemRepo.get_all_items() assert len(items) == 1 item_id = str(items[0]["id"]) assert ItemRepo.delete_item(item_id) == True items = ItemRepo.get_all_items() assert len(items) == 0
def item_to_project(item_id): uid = current_user.get_obj_id() project = ItemRepo.item_to_project(item_id, uid) if not project: return json.dumps({"success": False}) else: return json.dumps({"success": True, "data": project})
def item_to_task(item_id): uid = current_user.get_obj_id() task = ItemRepo.item_to_task(item_id, uid) if not task: return json.dumps({"success": False}) else: return json.dumps({"success": True, "data": task})
def item_to_someday(item_id): uid = current_user.get_obj_id() item = ItemRepo.item_to_someday(item_id, uid) if not item: return json.dumps({"success": False}) else: return json.dumps({"success": True, "data": item})
def item_get(): uid = current_user.get_obj_id() user_items = ItemRepo.get_all_items(user=uid) res = {} res["success"] = True res["data"] = user_items return json.dumps(res)
def test_delete_two_item(resource): user_id = resource ItemRepo.add_item(description="This is an item", location="inbox", user=user_id) ItemRepo.add_item(description="This is another item", location="inbox", user=user_id) items = ItemRepo.get_all_items() assert len(items) == 2 item_id_1 = str(items[0]["id"]) item_id_2 = str(items[1]["id"]) assert ItemRepo.delete_item(item_id_1) == True assert len(ItemRepo.get_all_items()) == 1 assert ItemRepo.delete_item(item_id_2) == True assert len(ItemRepo.get_all_items()) == 0
def item_add(): uid = current_user.get_obj_id() payload = request.get_json() if "description" not in payload: res = {"success": False} else: location = payload.get("location", "inbox") res = {} added_item = ItemRepo.add_item(payload["description"], uid, location=location) if added_item: res["success"] = True res["data"] = added_item else: res["success"] = False return json.dumps(res)
def item_delete(item_id): delete_res = ItemRepo.delete_item(item_id) return json.dumps({"success": delete_res})
def test_delete_nonexistent_item(resource): user_id = resource assert ItemRepo.delete_item("thisisafakeid") == False
from flask_login import LoginManager from GTDApp.repo import ItemRepo, TaskRepo, UserRepo, ProjectRepo # Initialize the app app = Flask(__name__) app.secret_key = "myspookysecret" # TODO: Make this configurable if os.environ.get("CONFIG_TYPE") == "test": app.config.from_pyfile(os.path.join(os.path.dirname(__file__), "..", "./config/config.cfg.test")) else: app.config.from_pyfile(os.path.join(os.path.dirname(__file__), "..", "./config/config.cfg.default")) # Initialize the login manager for the app login_manager = LoginManager() login_manager.init_app(app) # Connect to the database ItemRepo.connect(app.config["DBNAME"]) TaskRepo.connect(app.config["DBNAME"]) UserRepo.connect(app.config["DBNAME"]) ProjectRepo.connect(app.config["DBNAME"]) from GTDApp.views import index from GTDApp.views import item from GTDApp.views import task from GTDApp.views import project