Ejemplo n.º 1
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'
Ejemplo n.º 2
0
 def __init__(self, session):
     super().__init__(session, Task)
     self.date = DateManager()
     self.fulid = fulid(
         config.get('fulid.characters'),
         config.get('fulid.forbidden_characters'),
     )
     self.recurrence = TableManager(session, RecurrentTask)
Ejemplo n.º 3
0
class TaskFactory(factory.alchemy.SQLAlchemyModelFactory):
    id = factory.LazyFunction(lambda: fulid().new().str)
    title = factory.Faker('sentence')
    state = factory.Faker(
        'word',
        ext_word_list=config.get('task.allowed_states')
    )
    agile = factory.Faker('word', ext_word_list=['backlog', 'todo', None])
    type = 'task'
    priority = factory.Faker('random_number')

    # Let half the tasks have a due date

    @factory.lazy_attribute
    def due(self):
        if random.random() > 0.5:
            return factory.Faker('date_time').generate({})

    @factory.lazy_attribute
    def closed(self):
        if self.state == 'completed' or self.state == 'deleted':
            return factory.Faker('date_time').generate({})

    class Meta:
        model = models.Task
        sqlalchemy_session_persistence = 'commit'
Ejemplo n.º 4
0
    def print(self, tasks, columns, labels):
        """
        Method to print the report

        Arguments:
            tasks (Query): SQLAlchemy query with the tasks to print.
            columns (list): Element attributes to print
            labels (list): Headers of the attributes
        """
        report_data = []

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

        # Transform the fulids into sulids
        sulids = fulid(
            config.get('fulid.characters'),
            config.get('fulid.forbidden_characters'),
        ).sulids([task.id for task in tasks.all()])

        for task in sorted(tasks.all(), key=lambda k: k.id, reverse=True):
            task_report = []
            for attribute in columns:
                if attribute == 'id':
                    task.sulid = sulids[task.id]
                    task_report.append(task.sulid)
                elif attribute == 'tags':
                    if len(task.tags) != 0:
                        task_report.append(', '.join(
                            [tag.id for tag in task.tags]))
                    else:
                        task_report.append('')
                elif attribute == 'due':
                    task_report.append(self._date2str(task.due))
                else:
                    try:
                        task_report.append(task.__getattribute__(attribute))
                    except AttributeError:
                        task_report.append('')
            report_data.append(task_report)
        print(tabulate(report_data, headers=labels, tablefmt='simple'))
Ejemplo n.º 5
0
    def _date2str(self, date):
        """
        Method to convert a datetime object into a string with the format
        specified in the report.date_format configuration.

        Arguments:
            date (datetime or None): Object to convert.

        Returns:
            str: converted date string.
        """
        try:
            return date.strftime(config.get('report.date_format'))
        except AttributeError:
            return None
Ejemplo n.º 6
0
    def _set_agile(self, task_attributes, agile=None):
        """
        Method to set the agile attribute.

        If the agile property value isn't between the specified ones,
        a `ValueError` will be raised.

        Arguments:
            task_attributes (dict): Dictionary with the attributes of the task.
            agile (str): Task agile state.
        """
        if agile is not None and \
                agile not in config.get('task.agile.allowed_states'):
            raise ValueError('Agile state {} is not between the specified '
                             'by task.agile.states'.format(agile))

        if agile is not None:
            task_attributes['agile'] = agile
Ejemplo n.º 7
0
    def setup(self, session):
        self.report = TaskReport(session)
        self.columns = config.get('report.open.columns').copy()
        self.labels = config.get('report.open.labels').copy()

        yield 'setup'
Ejemplo n.º 8
0
 def test_date_to_string_converts_with_desired_format(self):
     date = self.fake.date_time()
     assert self.report._date2str(date) == date.strftime(
         config.get('report.date_format')
     )
Ejemplo n.º 9
0
 def test_fulid_does_not_accept_invalid_terminal_characters(self):
     with pytest.raises(ValueError):
         fulid(
             'ilou|&:;()<>~*@?!$#[]{}\\/\'"`',
             config.get('fulid.forbidden_characters'),
         )
Ejemplo n.º 10
0
 def test_fulid_generates_an_ulid_with_the_id_in_charset(self):
     for character in self.fulid.new().id():
         assert character.lower() in config.get('fulid.characters')
Ejemplo n.º 11
0
 def test_fulid_has_forbidden_charset_attribute_set_by_default(self):
     assert self.fulid.forbidden_charset == \
         list(config.get('fulid.forbidden_characters'))
Ejemplo n.º 12
0
 def test_fulid_has_charset_attribute(self):
     assert self.fulid.charset == list(config.get('fulid.characters'))