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']
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'])
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' projects_list.append(project) project = Project(43, 'active project', Project.STATUS_ACTIVE) 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(44, '2nd active project', Project.STATUS_ACTIVE) project.backend = 'test' project.activities.append(Activity(1, 'activity 1', 0)) projects_list.append(project) projects_db.update(projects_list) return projects_db
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
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())
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)
class ShowCommandTestCase(CommandTestCase): 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) def test_show_inexistent_object(self): output = self.run_command('show', ['aoeuidhtns']) self.assertEqual(output, "Your search string aoeuidhtns is nothing.\n") def test_show_project_id(self): output = self.run_command('show', ['42']) self.assertEqual( output, "Your search string 42 is the project not " "started project.\n") def test_show_activity_id(self): output = self.run_command('show', ['42/1']) self.assertEqual( output, "Your search string 42/1 is the activity " "activity 1 of the project not started " "project.\n") def test_show_activity_id_mapped(self): output = self.run_command('show', ['123/456']) self.assertEqual( output, "Your search string 123/456 is the activity " "my activity of the project my project, " "aliased by alias_1 on the test backend.\n") def test_show_alias(self): output = self.run_command('show', ['alias_1']) self.assertEqual( output, "Your search string alias_1 is an alias to " "my project, my activity (123/456) on the " "test backend.\n") @override_settings({'local_aliases': {'__pingpong': None}}) def test_show_local_alias(self): output = self.run_command('show', ['__pingpong']) self.assertEqual( output, "Your search string __pingpong is a local " "alias.\n")
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
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())
class ShowCommandTestCase(CommandTestCase): 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) def test_show_inexistent_object(self): output = self.run_command('show', ['aoeuidhtns']) self.assertEqual(output, "Your search string aoeuidhtns is nothing.\n") def test_show_project_id(self): output = self.run_command('show', ['42']) self.assertEqual(output, "Your search string 42 is the project not " "started project.\n") def test_show_activity_id(self): output = self.run_command('show', ['42/1']) self.assertEqual(output, "Your search string 42/1 is the activity " "activity 1 of the project not started " "project.\n") def test_show_activity_id_mapped(self): output = self.run_command('show', ['123/456']) self.assertEqual(output, "Your search string 123/456 is the activity " "my activity of the project my project, " "aliased by alias_1 on the test backend.\n") def test_show_alias(self): output = self.run_command('show', ['alias_1']) self.assertEqual(output, "Your search string alias_1 is an alias to " "my project, my activity (123/456) on the " "test backend.\n") @override_settings({'local_aliases': { '__pingpong': None }}) def test_show_local_alias(self): output = self.run_command('show', ['__pingpong']) self.assertEqual(output, "Your search string __pingpong is a local " "alias.\n")
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
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
def test_project_status(self): config = self.default_config.copy() options = self.default_options.copy() config['wrmap'] = { 'alias_not_started': '0/0', 'alias_active': '1/0', 'alias_finished': '2/0', 'alias_cancelled': '3/0', } options['force_yes'] = True projects_db = ProjectsDb(options['projects_db']) project_not_started = Project(0, 'not started project', Project.STATUS_NOT_STARTED) project_not_started.activities.append(Activity(0, 'activity', 0)) project_active = Project(1, 'active project', Project.STATUS_ACTIVE) project_active.activities.append(Activity(0, 'activity', 0)) project_finished = Project(2, 'finished project', Project.STATUS_FINISHED) project_finished.activities.append(Activity(0, 'activity', 0)) project_cancelled = Project(3, 'cancelled project', Project.STATUS_CANCELLED) project_cancelled.activities.append(Activity(0, 'activity', 0)) projects_db.update([ project_not_started, project_active, project_finished, project_cancelled ]) stdout = self.run_command('clean-aliases', options=options, config_options=config) settings = Settings(self.config_file) self.assertEqual(settings.get_aliases().keys(), ['alias_active'])
class ProjectCommandTestCase(CommandTestCase): def setUp(self): super(ProjectCommandTestCase, self).setUp() self.projects_db = ProjectsDb(self.taxi_dir) projects_list = [] project = Project(42, 'not started project', Project.STATUS_NOT_STARTED) project.backend = 'test' projects_list.append(project) project = Project(43, 'active project', Project.STATUS_ACTIVE) 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(44, '2nd active project', Project.STATUS_ACTIVE) project.backend = 'test' project.activities.append(Activity(1, 'activity 1', 0)) projects_list.append(project) self.projects_db.update(projects_list) def run_project_command(self, *args, **kwargs): return self.run_command('project', *args, **kwargs) def test_no_arguments_lists_projects(self): output = self.run_project_command([]) lines = output.splitlines() self.assertEqual( set(lines), set([ 'N [test] 42 not started project', 'A [test] 43 active project', 'A [test] 44 2nd active project', ])) def test_argument_filters_search(self): output = self.run_project_command(['list', 'active']) lines = output.splitlines() self.assertEqual( set(lines), set([ 'A [test] 43 active project', 'A [test] 44 2nd active project', ])) def test_add_creates_alias(self): self.run_command('project', ['alias', 'active'], input='1\n0\nfoobar') with open(self.config_file, 'r') as f: config_lines = f.readlines() self.assertIn('foobar = 43/1\n', config_lines) def test_show_inactive_project_shows_project(self): output = self.run_command('project', ['show', '42']) lines = output.splitlines() self.assertEqual(lines[0], 'Id: 42') def test_show_shows_project(self): output = self.run_command('project', ['show', '43']) lines = output.splitlines() self.assertEqual(lines[0], 'Id: 43') def test_show_nonexistent_project_shows_error(self): output = self.run_command('project', ['show', '777']) self.assertEqual(output, 'Error: Could not find project `777`\n') 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()) 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()) 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)
class ProjectCommandTestCase(CommandTestCase): def setUp(self): super(ProjectCommandTestCase, self).setUp() self.projects_db = ProjectsDb(self.taxi_dir) projects_list = [] project = Project(42, 'not started project', Project.STATUS_NOT_STARTED) project.backend = 'test' projects_list.append(project) project = Project(43, 'active project', Project.STATUS_ACTIVE) 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(44, '2nd active project', Project.STATUS_ACTIVE) project.backend = 'test' project.activities.append(Activity(1, 'activity 1', 0)) projects_list.append(project) self.projects_db.update(projects_list) def run_project_command(self, *args, **kwargs): return self.run_command('project', *args, **kwargs) def test_no_arguments_lists_projects(self): output = self.run_project_command([]) lines = output.splitlines() self.assertEqual(set(lines), set([ 'N [test] 42 not started project', 'A [test] 43 active project', 'A [test] 44 2nd active project', ])) def test_argument_filters_search(self): output = self.run_project_command(['list', 'active']) lines = output.splitlines() self.assertEqual(set(lines), set([ 'A [test] 43 active project', 'A [test] 44 2nd active project', ])) def test_add_creates_alias(self): self.run_command('project', ['alias', 'active'], input='1\n0\nfoobar') with open(self.config_file, 'r') as f: config_lines = f.readlines() self.assertIn('foobar = 43/1\n', config_lines) def test_show_inactive_project_shows_project(self): output = self.run_command('project', ['show', '42']) lines = output.splitlines() self.assertEqual(lines[0], 'Id: 42') def test_show_shows_project(self): output = self.run_command('project', ['show', '43']) lines = output.splitlines() self.assertEqual(lines[0], 'Id: 43') def test_show_nonexistent_project_shows_error(self): output = self.run_command('project', ['show', '777']) self.assertEqual(output, 'Error: Could not find project `777`\n') 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()) 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()) 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)