Example #1
0
    def test_project_status(self):
        projects_db = ProjectsDb(self.taxi_dir)

        project_not_started = Project(0, 'not started project',
                                      Project.STATUS_NOT_STARTED)
        project_not_started.backend = 'test'
        project_not_started.activities.append(Activity(0, 'activity', 0))
        project_active = Project(1, 'active project', Project.STATUS_ACTIVE)
        project_active.backend = 'test'
        project_active.activities.append(Activity(0, 'activity', 0))
        project_finished = Project(2, 'finished project',
                                   Project.STATUS_FINISHED)
        project_finished.backend = 'test'
        project_finished.activities.append(Activity(0, 'activity', 0))
        project_cancelled = Project(3, 'cancelled project',
                                    Project.STATUS_CANCELLED)
        project_cancelled.backend = 'test'
        project_cancelled.activities.append(Activity(0, 'activity', 0))
        projects_db.update([
            project_not_started, project_active, project_finished,
            project_cancelled
        ])

        self.run_command('clean-aliases', args=['--yes'])

        settings = Settings(self.config_file)
        self.assertEqual(list(settings.get_aliases().keys()), ['alias_active'])
Example #2
0
def test_project_status(cli, config, data_dir):
    config.set_dict({
        'test_aliases': {
            'alias_not_started': '0/0',
            'alias_active': '1/0',
            'alias_finished': '2/0',
            'alias_cancelled': '3/0',
        }
    })
    projects_db = ProjectsDb(str(data_dir))

    project_not_started = Project(0, 'not started project',
                                  Project.STATUS_NOT_STARTED)
    project_not_started.backend = 'test'
    project_not_started.activities.append(Activity(0, 'activity', 0))
    project_active = Project(1, 'active project', Project.STATUS_ACTIVE)
    project_active.backend = 'test'
    project_active.activities.append(Activity(0, 'activity', 0))
    project_finished = Project(2, 'finished project', Project.STATUS_FINISHED)
    project_finished.backend = 'test'
    project_finished.activities.append(Activity(0, 'activity', 0))
    project_cancelled = Project(3, 'cancelled project',
                                Project.STATUS_CANCELLED)
    project_cancelled.backend = 'test'
    project_cancelled.activities.append(Activity(0, 'activity', 0))
    projects_db.update([
        project_not_started, project_active, project_finished,
        project_cancelled
    ])

    cli('clean-aliases', ['--yes'])

    settings = Settings(config.path)
    assert list(settings.get_aliases().keys()) == ['alias_active']
Example #3
0
    def test_add_multiple_choices(self):
        p1 = Project(1, 'test project', Project.STATUS_ACTIVE)
        p1.activities = [Activity(2, 'test activity', 0)]
        p2 = Project(2, 'test project 2', Project.STATUS_ACTIVE)
        p2.activities = [Activity(3, 'test activity 2', 0)]
        p = ProjectsDb(self.taxi_dir)
        p.update([p1, p2])

        self.run_project_command(['alias', 'test project'],
                                 input='1\ntest_alias')

        with open(self.config_file, 'r') as f:
            self.assertIn('test_alias = 2/3\n', f.readlines())
Example #4
0
def test_add_multiple_choices(cli, data_dir, config):
    p1 = Project(1, 'test project', Project.STATUS_ACTIVE)
    p1.activities = [Activity(2, 'test activity', 0)]
    p2 = Project(2, 'test project 2', Project.STATUS_ACTIVE)
    p2.activities = [Activity(3, 'test activity 2', 0)]
    p = ProjectsDb(str(data_dir))
    p.update([p1, p2])

    cli('project', ['alias', 'test project'], input='1\ntest_alias')

    with open(config.path, 'r') as f:
        lines = f.readlines()

    assert 'test_alias = 2/3\n' in lines
Example #5
0
def projects_db(data_dir):
    projects_db = ProjectsDb(str(data_dir))
    projects_list = []
    project = Project(42, 'not started project', Project.STATUS_NOT_STARTED)
    project.backend = 'test'
    project.activities.append(Activity(1, 'activity 1', 0))
    project.activities.append(Activity(2, 'activity 2', 0))
    projects_list.append(project)
    project = Project(123, 'my project', Project.STATUS_ACTIVE)
    project.backend = 'test'
    project.activities.append(Activity(456, 'my activity', 0))
    projects_list.append(project)
    projects_db.update(projects_list)

    return projects_db
Example #6
0
 def setUp(self):
     super(ShowCommandTestCase, self).setUp()
     self.projects_db = ProjectsDb(self.taxi_dir)
     projects_list = []
     project = Project(42, 'not started project',
                       Project.STATUS_NOT_STARTED)
     project.backend = 'test'
     project.activities.append(Activity(1, 'activity 1', 0))
     project.activities.append(Activity(2, 'activity 2', 0))
     projects_list.append(project)
     project = Project(123, 'my project', Project.STATUS_ACTIVE)
     project.backend = 'test'
     project.activities.append(Activity(456, 'my activity', 0))
     projects_list.append(project)
     self.projects_db.update(projects_list)
Example #7
0
def test_add_inactive_project(cli, data_dir):
    project = Project(1, 'test project', Project.STATUS_FINISHED)
    project.activities = [Activity(2, 'test activity', 0)]
    p = ProjectsDb(str(data_dir))
    p.update([project])

    output = cli('project', ['alias', 'test project'], input='test_alias')

    assert "No active project matches your search string" in output
Example #8
0
    def test_add_single_choice(self):
        project = Project(1, 'test project', Project.STATUS_ACTIVE)
        project.activities = [Activity(2, 'test activity', 0)]
        p = ProjectsDb(self.taxi_dir)
        p.update([project])

        self.run_project_command(['alias', 'test project'], input='test_alias')

        with open(self.config_file, 'r') as f:
            self.assertIn('test_alias = 1/2\n', f.readlines())
Example #9
0
    def test_add_inactive_project(self):
        project = Project(1, 'test project', Project.STATUS_FINISHED)
        project.activities = [Activity(2, 'test activity', 0)]
        p = ProjectsDb(self.taxi_dir)
        p.update([project])

        output = self.run_project_command(['alias', 'test project'],
                                          input='test_alias')

        self.assertIn("No active project matches your search string", output)
Example #10
0
    def get_projects(self):
        p = Project(self.name,
                    self.name,
                    Project.STATUS_ACTIVE,
                    description=self.name)

        a = Activity(0, "No activity")
        p.add_activity(a)
        p.aliases[self.name] = a.id

        return [p]
Example #11
0
def test_add_single_choice(cli, data_dir, config):
    project = Project(1, 'test project', Project.STATUS_ACTIVE)
    project.activities = [Activity(2, 'test activity', 0)]
    p = ProjectsDb(str(data_dir))
    p.update([project])

    cli('project', ['alias', 'test project'], input='test_alias')

    with open(config.path, 'r') as f:
        lines = f.readlines()

    assert 'test_alias = 1/2\n' in lines
Example #12
0
    def get_projects(self):
        projects_list = []

        for project_name, count in self.settings.config.items('tempo_projects'):
            project_name = project_name.upper()
            p = Project(self.get_project_hash(project_name), project_name, Project.STATUS_ACTIVE)
            for i in range(1, int(count) + 1):
                name = f'{project_name}-{i}'
                a = Activity(i, name, 0)
                p.add_activity(a)
                p.aliases[name] = a.id

            projects_list.append(p)

        return projects_list
Example #13
0
    def get_projects(self):
        projects_list = []

        for project_name, count in self.settings.config.items('jira_projects'):
            project_name = project_name.upper()
            p = Project(project_name, f"[JIRA] {project_name}", Project.STATUS_ACTIVE,
                    description=f"JIRA Project {project_name} (created by backend {self.name})"
            )
            for i in range(1, int(count) + 1):
                name = f"{project_name}-{i}"
                a = Activity(i, name)
                p.add_activity(a)
                p.aliases[name] = a.id

            projects_list.append(p)

        return projects_list
Example #14
0
    def get_projects(self):
        projects_url = self.get_api_url('/projects/')

        try:
            response = self._session.get(projects_url)
            projects = response.json()
        except ValueError:
            raise TaxiException(
                "Unexpected response from the server (%s).  Check your "
                "credentials" % response.content)
        projects_list = []
        date_attrs = (('start_date', 'startdate'), ('end_date', 'enddate'))

        for project in projects['data']:
            p = Project(int(project['id']), project['name'],
                        Project.STATUS_ACTIVE, project['description'],
                        project['budget'])

            for date_attr, proj_date in date_attrs:
                try:
                    date = datetime.strptime(project[proj_date],
                                             '%Y-%m-%d').date()
                except (ValueError, TypeError):
                    date = None

                setattr(p, date_attr, date)

            for activity in project['activities']:
                a = Activity(int(activity['id']), activity['name'],
                             activity['rate'])
                p.add_activity(a)

                if activity['alias']:
                    p.aliases[activity['alias']] = activity['id']

            projects_list.append(p)

        return projects_list
Example #15
0
    def get_projects(self):
        projects_list = []

        p = Project(self.instance.upper(),
                    f"[{self.name}] {self.instance}",
                    Project.STATUS_ACTIVE,
                    description=f"{self.name} Project {self.instance}")

        r = requests.get(f"https://{self.hostname}/2.0/pr_project",
                         headers={
                             'Accept': 'application/json',
                             'Authorization': f"Bearer {self.api_key}"
                         })
        response = r.json()

        if r.status_code != 200:
            raise Exception(
                f"[{self.name}] API error: HTTP {r.status_code} - {response['message']}"
            )

        for project in response:
            name = f"{self.instance.upper()}-{project['id']}"

            # @todo Ideally, we should have a [bexio_active_project_states] configuration that lists only active
            # projects and filter here again against /2.0/pr_project_state
            if project['end_date'] is not None:
                if datetime.datetime.strptime(
                        project['end_date'],
                        '%Y-%m-%d %H:%M:%S') < datetime.datetime.today():
                    continue

            a = Activity(project['id'], project['name'])
            p.add_activity(a)
            p.aliases[name] = a.id

        projects_list.append(p)

        return projects_list