Ejemplo n.º 1
0
 def test_day_granularity(self):
     history = [
         {
             'ts': MID_SATURDAY - 2 * DAY,
             'column': 'In Progress'
         },
     ]
     assert 1 == helpers.task_dot_count(history, MID_SATURDAY - DAY,
                                        DAILY_DOTS)
     history = [
         {
             'ts': MID_SATURDAY - (2 * DAY - HOUR),
             'column': 'In Progress'
         },
     ]
     assert 0 == helpers.task_dot_count(history, MID_SATURDAY - DAY,
                                        DAILY_DOTS)
Ejemplo n.º 2
0
 def test_week_granularity(self):
     history = [
         {
             'ts': MID_SATURDAY - 8 * DAY,
             'column': 'In Progress'
         },
     ]
     assert 1 == helpers.task_dot_count(history, MID_SATURDAY - DAY,
                                        WEEKLY_DOTS)
     history = [
         {
             'ts': MID_SATURDAY - ((8 * DAY) - HOUR),
             'column': 'In Progress'
         },
     ]
     assert 0 == helpers.task_dot_count(history, MID_SATURDAY - DAY,
                                        WEEKLY_DOTS)
Ejemplo n.º 3
0
 def test_single_history_item(self):
     history = [
         {
             'ts': MID_SATURDAY - 3 * DAY,
             'column': None
         },
     ]
     assert 2 == helpers.task_dot_count(history, MID_SATURDAY - DAY,
                                        DAILY_DOTS)
Ejemplo n.º 4
0
    def load(self):
        now = time.time()
        client = asana.Client.access_token(self.token)
        project = client.projects.find_by_id(self.board_id)
        project_name = project['name']
        params = {'opt_expand': 'memberships,custom_fields'}
        for task in client.tasks.find_by_project(self.board_id, params):
            task_name = task['name']
            task_id = task['id']
            custom_fields = [(custom_field['name'],
                              custom_field['enum_value']['name'])
                             for custom_field in task['custom_fields']
                             if custom_field.get('enum_value')]
            section_name = None
            for membership in task['memberships']:
                if membership['project']['name'] == project_name\
                    and membership['section']:
                    section_name = membership['section']['name']
                    break

            # skip sections
            if task_name == section_name:
                continue

            # skip columns that weren't requested
            if section_name not in self.columns:
                continue

            # skip tasks that don't have the correct custom fields
            if not all(reqd in custom_fields for reqd in self.reqd_fields):
                continue

            stories = client.tasks.stories(task_id)
            history = helpers.task_history(project_name, stories)
            dot_factor = WEEKLY_DOTS if self.weekly_dots else DAILY_DOTS
            dot_count = helpers.task_dot_count(history, now, dot_factor)

            if DOTS_RE.search(task_name):
                new_task_name = task_name.rsplit(' | ', 1)[0]
            else:
                new_task_name = task_name

            if dot_count > MAX_DOTS:
                new_task_name += ' | {} x {}'.format(DOT, dot_count)
            elif dot_count > 0:
                new_task_name += ' | ' + DOT * dot_count

            if new_task_name != task_name:
                print('{} => {}'.format(task_name, new_task_name))
                client.tasks.update(task_id, {'name': new_task_name})
Ejemplo n.º 5
0
 def test_multiple_column_stints(self):
     history = [
         {
             'ts': MID_SATURDAY - 4 * DAY,
             'column': 'In Progress'
         },
         {
             'ts': MID_SATURDAY - 3 * DAY,
             'column': 'Code Review'
         },
         {
             'ts': MID_SATURDAY - 2 * DAY,
             'column': 'In Progress'
         },
     ]
     assert 2 == helpers.task_dot_count(history, MID_SATURDAY - DAY,
                                        DAILY_DOTS)
Ejemplo n.º 6
0
 def test_start_on_weekend_span_weekend_end_on_weekend(self):
     history = [{'ts': MID_SATURDAY - 14 * DAY, 'column': 'Foo'}]
     assert 10 == helpers.task_dot_count(history, MID_SATURDAY, DAILY_DOTS)
Ejemplo n.º 7
0
 def test_spanning_two_weekend(self):
     history = [{'ts': MID_SATURDAY - 9 * DAY, 'column': 'Foo'}]
     assert 8 == helpers.task_dot_count(history, MID_SATURDAY + 3 * DAY,
                                        DAILY_DOTS)
Ejemplo n.º 8
0
 def test_within_single_weekend(self):
     history = [{'ts': MID_SATURDAY, 'column': 'Foo'}]
     assert 0 == helpers.task_dot_count(history, MID_SATURDAY + DAY,
                                        DAILY_DOTS)