Esempio n. 1
0
    def test_remove_null_columns_removes_columns_if_all_nulls(
        self,
        session
    ):
        # If we don't assign a project and tags to the tasks they are all
        # going to be null.
        desired_columns = self.columns.copy()
        desired_labels = self.labels.copy()

        project_index = desired_columns.index('project_id')
        desired_columns.pop(project_index)
        desired_labels.pop(project_index)

        tags_index = desired_columns.index('tags')
        desired_columns.pop(tags_index)
        desired_labels.pop(tags_index)

        due_index = desired_columns.index('due')
        desired_columns.pop(due_index)
        desired_labels.pop(due_index)

        TaskFactory.create_batch(100, due=None)

        tasks = session.query(Task).filter_by(state='open')

        columns, labels = self.report._remove_null_columns(
            tasks,
            self.columns,
            self.labels
        )

        assert desired_columns == columns
        assert desired_labels == labels
Esempio n. 2
0
    def setup(self, session):
        self.report = Tags(session)
        self.columns = config.get('report.tags.columns')
        self.labels = config.get('report.tags.labels')
        self.tasks = TaskFactory.create_batch(20, state='open')

        yield 'setup'
Esempio n. 3
0
    def test_task_report_print_doesnt_fail_if_some_tasks_doesnt_have_attr(
        self,
        session
    ):
        # The Task tasks don't have `recurrence` attribute

        columns = ['id', 'recurrence']
        labels = ['Id', 'Recurrence']

        self.report = TaskReport(session, RecurrentTask)
        TaskFactory.create_batch(10, state='open')
        RecurrentTaskFactory.create_batch(10, state='open')

        tasks = session.query(Task).filter_by(state='open')

        self.report.print(tasks, columns, labels)
Esempio n. 4
0
    def setup(self, session):
        self.report = Projects(session)
        self.columns = self.config.get('report.projects.columns').split(', ')
        self.labels = self.config.get('report.projects.labels').split(', ')
        self.tasks = TaskFactory.create_batch(20, state='open')

        yield 'setup'
Esempio n. 5
0
    def test_task_report_print_id_and_due_if_present(self):
        tasks = TaskFactory.create_batch(10, state='open')

        id_index = self.columns.index('id')
        due_index = self.columns.index('due')

        columns = [
            self.columns[id_index],
            self.columns[due_index],
        ]
        labels = [
            self.labels[id_index],
            self.labels[due_index],
        ]
        tasks_query = self.session.query(Task).filter_by(state='open')

        self.report.print(tasks=tasks_query, columns=columns, labels=labels)

        # Prepare desired report
        report_data = []
        for task in sorted(tasks, key=lambda k: k.id, reverse=True):
            task_report = []
            for attribute in columns:
                if attribute == 'id':
                    task_report.append(task.sulid)
                else:
                    task_report.append(self.report._date2str(task.due))
            report_data.append(task_report)

        self.tabulate.assert_called_once_with(
            report_data,
            headers=labels,
            tablefmt='simple'
        )
        self.print.assert_called_once_with(self.tabulate.return_value)
Esempio n. 6
0
    def test_list_prints_id_title_and_project_if_project_existent(self):
        project = ProjectFactory.create()
        tasks = TaskFactory.create_batch(2, state='open')
        tasks[0].project = project
        self.session.commit()

        id_index = self.columns.index('id')
        project_index = self.columns.index('project_id')

        columns = [
            self.columns[id_index],
            self.columns[project_index],
        ]
        labels = [
            self.labels[id_index],
            self.labels[project_index],
        ]

        self.report.print(columns=columns, labels=labels)

        # Prepare desired report
        report_data = []
        for task in sorted(tasks, key=lambda k: k.id, reverse=True):
            task_report = []
            for attribute in columns:
                if attribute == 'id':
                    task_report.append(task.sulid)
                else:
                    task_report.append(task.__getattribute__(attribute))
            report_data.append(task_report)

        self.tabulate.assert_called_once_with(report_data,
                                              headers=labels,
                                              tablefmt='simple')
        self.print.assert_called_once_with(self.tabulate.return_value)
Esempio n. 7
0
def test_task_list(client, user_credentials):
    client.login(**user_credentials)

    tasks = TaskFactory.create_batch(5)

    response = client.get('/')
    response_body = response.content.decode()

    assert response.status_code == HTTPStatus.OK
    for task in tasks:
        assert task.name in response_body
Esempio n. 8
0
def test_task_list_with_filter(client, user_credentials):
    client.login(**user_credentials)

    selected_status = TaskStatusFactory()
    not_selected_status = TaskStatusFactory()
    current_user = User.objects.get(username=user_credentials['username'])
    another_user = UserFactory()

    my_tasks_with_selected_status = TaskFactory.create_batch(
        3,
        assigned_to=current_user,
        status=selected_status,
    )
    my_tasks_without_selected_status = TaskFactory.create_batch(
        3,
        assigned_to=current_user,
        status=not_selected_status,
    )
    not_my_task_with_selected_status = TaskFactory.create_batch(
        3,
        assigned_to=another_user,
        status=selected_status,
    )

    response = client.get('/', {
        'status': selected_status.id,
        'my_task': 'on',
    })
    response_body = response.content.decode()

    assert response.status_code == HTTPStatus.OK
    for task in my_tasks_with_selected_status:
        assert task.name in response_body

    for task in my_tasks_without_selected_status:
        assert task.name not in response_body

    for task in not_my_task_with_selected_status:
        assert task.name not in response_body
Esempio n. 9
0
    def test_remove_null_columns_doesnt_fail_if_column_doesnt_exist(
        self,
        session
    ):
        desired_columns = ['id', 'title']
        columns = desired_columns.copy()
        columns.append('unexistent_column')
        desired_labels = ['Id', 'Title']
        labels = desired_labels.copy()
        labels.append('unexistent_label')

        TaskFactory.create_batch(100, due=None)

        tasks = session.query(Task).filter_by(state='open')

        result_columns, result_labels = self.report._remove_null_columns(
            tasks,
            columns,
            labels
        )

        assert result_columns == desired_columns
        assert result_labels == desired_labels
Esempio n. 10
0
    def test_task_report_print_fills_empty_if_task_doesnt_have_attr(
        self,
        session
    ):
        # If it doesn't get filled by an empty value, it will get filled with
        # the next attribute data.

        # The Task tasks don't have `recurrence` attribute

        columns = ['id', 'recurrence']
        labels = ['Id', 'Recurrence']

        self.report = TaskReport(session, RecurrentTask)
        TaskFactory.create_batch(1, state='open')
        # RecurrentTaskFactory.create_batch(1, state='open')

        tasks = session.query(Task).filter_by(state='open')

        self.report.print(tasks, columns, labels)
        self.tabulate.assert_called_once_with(
            [['a', '']],
            headers=labels,
            tablefmt='simple',
        )
Esempio n. 11
0
    def test_task_report_print_id_title_and_tags_if_present(self):
        tasks = TaskFactory.create_batch(4, state='open')
        tags = TagFactory.create_batch(2)

        # Add tags to task
        tasks[0].tags = tags
        self.session.commit()

        # Select columns to print
        id_index = self.columns.index('id')
        tags_index = self.columns.index('tags')
        columns = [
            self.columns[id_index],
            self.columns[tags_index],
        ]
        labels = [
            self.labels[id_index],
            self.labels[tags_index],
        ]
        tasks_query = self.session.query(Task).filter_by(state='open')

        self.report.print(tasks=tasks_query, columns=columns, labels=labels)

        # Prepare desired report
        report_data = []
        for task in sorted(tasks, key=lambda k: k.id, reverse=True):
            task_report = []
            for attribute in columns:
                if attribute == 'id':
                    task_report.append(task.sulid)
                elif attribute == 'tags':
                    if len(task.tags) > 0:
                        task_report.append(
                            ', '.join([tag.id for tag in tags])
                        )
                    else:
                        task_report.append('')
            report_data.append(task_report)

        self.tabulate.assert_called_once_with(
            report_data,
            headers=labels,
            tablefmt='simple'
        )
        self.print.assert_called_once_with(self.tabulate.return_value)