Esempio n. 1
0
 def test_cli_project_update_by_name_exists(self):
     project_identifier = "test_cli_project_update_by_name_exists"
     expected_new_name = "test_cli_project_update_by_name_exists updated"
     project_create(project_identifier)
     runner = CliRunner()
     result = runner.invoke(
         cli_project_update,
         [project_identifier, "--project_name", expected_new_name])
     self.assertIsNone(result.exception)
     self.assertIn(
         "Successfuly updated project name: {0}".format(project_identifier),
         result.output)
     project_found = project_find(project_identifier)
     self.assertIsNone(project_found)
     project_found = project_find(expected_new_name)
     self.assertIsNotNone(project_found)
Esempio n. 2
0
def task_delete(project_identifier, task_number):
    logger.info("about to delete task number:{0} from project:{1}".format(task_number, project_identifier))
    project = project_find(project_identifier)
    if project is None:
        raise Exception("project {0} not Found".format(project_identifier))
    query = Task.delete().where(Task.project == project and Task.task_number == task_number)
    total_deleted = query.execute()
    logger.info("{0} deleted task".format(total_deleted))
    return total_deleted
Esempio n. 3
0
 def test_cli_project_create(self):
     project_identifier = "test_cli_project_create"
     runner = CliRunner()
     result = runner.invoke(cli_project_create, [project_identifier])
     self.assertIsNone(result.exception)
     self.assertIn("Project created successfully", result.output)
     project_found = project_find(project_identifier)
     self.assertIsNotNone(project_found)
     self.assertEqual(project_found.project_name, project_identifier)
Esempio n. 4
0
def task_find(project_identifier, task_number):
    logger.info("about to find task number:{0} in project:{1}".format(task_number, project_identifier))
    project = project_find(project_identifier)
    if project is None:
        return None
    try:
        task = Task.get(Task.project == project, Task.task_number == task_number)
        return task
    except Task.DoesNotExist:
        return None
Esempio n. 5
0
 def test_cli_project_delete_by_name(self):
     project_identifier = "test_cli_project_delete_by_name"
     project_create(project_identifier)
     runner = CliRunner()
     result = runner.invoke(cli_project_delete, [project_identifier])
     self.assertIsNone(result.exception)
     self.assertIn(
         "Successfuly deleted project name: {0}".format(project_identifier),
         result.output)
     project_found = project_find(project_identifier)
     self.assertIsNone(project_found)
Esempio n. 6
0
 def test_cli_project_delete_by_id(self):
     project = project_create("test_cli_project_delete_by_id")
     project_identifier = str(project.id)
     runner = CliRunner()
     result = runner.invoke(cli_project_delete,
                            [project_identifier, "--identifier_type", "id"])
     self.assertIsNone(result.exception)
     self.assertIn(
         "Successfuly deleted project name: {0}".format(project_identifier),
         result.output)
     project_found = project_find(project.id)
     self.assertIsNone(project_found)
Esempio n. 7
0
def task_create(project_identifier, task_number, description = None):
    logger.info("about to create task in project:{0}, task number:{1}, description:{2}".format(project_identifier, task_number, description))
    project = project_find(project_identifier)
    if project is None:
        raise Exception("project {0} not Found".format(project_identifier))
    try:
        task = Task.get(Task.project == project, Task.task_number == task_number)
        logger.info("already exists task number:{0} in project:{1}".format(task_number, project_identifier))
        raise Exception("already exists task number:{0} in project:{1}".format(task_number, project_identifier))
    except Task.DoesNotExist:
        task = Task(project = project, task_number = task_number, description = description)
        task.save()
        logger.info("saved new task:{0} in project:{1}".format(task_number, project_identifier))
        return task
Esempio n. 8
0
 def test_cli_project_update_by_id_exists(self):
     expected_new_name = "test_cli_project_update_by_id_exists updated"
     project = project_create("test_cli_project_update_by_id_exists")
     project_identifier = str(project.id)
     runner = CliRunner()
     result = runner.invoke(cli_project_update, [
         project_identifier, "--identifier_type", "id", "--project_name",
         expected_new_name
     ])
     self.assertIsNone(result.exception)
     self.assertIn(
         "Successfuly updated project name: {0}".format(project_identifier),
         result.output)
     project_found = project_find(project.id)
     self.assertIsNotNone(project_found)
     self.assertEqual(project_found.project_name, expected_new_name)
Esempio n. 9
0
 def test_cli_project_create_full(self):
     project_identifier = "test_cli_project_create"
     expected_description = "description of test_cli_project_create"
     expected_start_date = "2020-01-01"
     expected_end_date = "2020-01-10"
     runner = CliRunner()
     result = runner.invoke(cli_project_create, [
         project_identifier, "--description", expected_description,
         "--planned_start_date", expected_start_date, "--planned_end_date",
         expected_end_date
     ])
     self.assertIsNone(result.exception)
     self.assertIn("Project created successfully", result.output)
     project_found = project_find(project_identifier)
     self.assertIsNotNone(project_found)
     self.assertEqual(project_found.project_name, project_identifier)
     self.assertEqual(project_found.description, expected_description)
     self.assertEqual(
         project_found.planned_start_date,
         datetime.datetime.strptime(expected_start_date, "%Y-%m-%d"))
     self.assertEqual(
         project_found.planned_end_date,
         datetime.datetime.strptime(expected_end_date, "%Y-%m-%d"))
Esempio n. 10
0
def task_search(project_name=None, is_closed=None, task_number=None, end_date=None, date_operator=None, user_external_id=None):
    logger.info("about to search task by criteria, project_name:{0}, is_closed:{1}, end_date:{2}, date_operator:{3}, user_external_id:{4}".format(project_name, is_closed, end_date, date_operator, user_external_id))
    clauses = True
    if not project_name is None:
        project = project_find(project_name)
        if project is None:
            return []
        else:
            clauses &= (Task.project == project)
    if not user_external_id is None:
        user = user_find(user_external_id)
        if user is None:
            return []
        else:
            clauses &= (Task.user == user)
    if not is_closed is None:
        if is_closed:
            clauses &= (Task.end_date.is_null(False))
        else:
            clauses &= (Task.end_date.is_null())
    if not end_date is None and not date_operator is None:
        if date_operator == "eq":
            clauses &= (Task.end_date == end_date)
        elif date_operator == "gt":
            clauses &= (Task.end_date > end_date)
        elif date_operator == "lt":
            clauses &= (Task.end_date < end_date)
        elif date_operator == "ge":
            clauses &= (Task.end_date >= end_date)
        elif date_operator == "le":
            clauses &= (Task.end_date <= end_date)
    tasks = Task.select().where(clauses)
    logger.info("found tasks by criteria, project_name:{0}, is_closed:{1}, end_date:{2}, date_operator:{3}, user_external_id:{4}".format(project_name, is_closed, end_date, date_operator, user_external_id))
    for task in tasks:
        logger.debug("\t\t- {0}\t{1}".format(task.project.project_name, task.task_number))
    return tasks