def test_story_matcher(self) -> None: matcher = IsInProjectAndSection("My project", "My section")._story_matcher self.assertTrue( matcher( f.story(resource_subtype="added_to_project", project=self.project))) self.assertTrue( matcher( f.story(resource_subtype="section_changed", new_section=self.section))) self.assertFalse( matcher( f.story( resource_subtype="added_to_project", project=f.project(name="Other project"), ))) self.assertFalse( matcher( f.story( resource_subtype="section_changed", new_section=f.section(name="Other section", project=self.project), ))) self.assertFalse( matcher( f.story( resource_subtype="section_changed", new_section=f.section( name="My section", project=f.project(name="Other project")), ))) self.assertFalse(matcher(f.story(resource_subtype="unknown")))
def test_story_matcher(self) -> None: matcher = IsInProject("My project")._story_matcher self.assertTrue( matcher( f.story( resource_subtype="added_to_project", project=f.project(name="My project"), ))) self.assertFalse( matcher( f.story( resource_subtype="added_to_project", project=f.project(name="Other project"), ))) self.assertFalse(matcher(f.story(resource_subtype="comment_added")))
def test_project_by_gid(self) -> None: project = f.project() self.inner_mock.projects.find_by_id.return_value = project.to_dict() returned_project = self.client.project_by_gid("1") self.assertEqual(project, returned_project) self.inner_mock.projects.find_by_id.assert_called_once_with( "1", fields=list_matcher)
def test_add_to_project(self) -> None: project = f.project() task = f.task() self.inner_mock.tasks.add_project.return_value = None self.client.add_to_project(task, project) self.inner_mock.tasks.add_project.assert_called_once_with( task.gid, {"project": project.gid})
def test_sections_by_project(self) -> None: project = f.project(gid="1") sections = [f.section(gid="2"), f.section(gid="3")] self.inner_mock.sections.find_by_project.return_value = [ s.to_dict() for s in sections ] returned_sections = self.client.sections_by_project(project) self.assertListEqual(returned_sections, sections) self.inner_mock.sections.find_by_project.assert_called_once_with( project.gid, fields=list_matcher)
def test_reorder(self) -> None: project = f.project() task = f.task(gid="1") reference = f.task(gid="2") self.inner_mock.tasks.add_project.return_value = None self.client.reorder_in_project(task, project, reference, "direction") self.inner_mock.tasks.add_project.assert_called_once_with( task.gid, { "project": project.gid, "insert_direction": reference.gid })
class TestTasksBySection(TestCaseWithClient): project = f.project() section = f.section(gid="1", project=project) other_section = f.section(gid="2", project=project) tasks = [ f.task( gid="3", memberships=[f.task_membership(project=project, section=section)]), f.task( gid="4", memberships=[f.task_membership(project=project, section=section)]), f.task( gid="5", memberships=[ f.task_membership(project=project, section=other_section) ], ), ] def setUp(self) -> None: super().setUp() self.inner_mock.tasks.find_by_project.return_value = [ t.to_dict() for t in self.tasks ] self.inner_mock.tasks.find_by_section.return_value = [ t.to_dict() for t in self.tasks[:-1] ] def test_tasks_by_section(self) -> None: returned_tasks = self.client.tasks_by_section(self.section) self.assertListEqual(returned_tasks, self.tasks[:-1]) self.inner_mock.tasks.find_by_project.assert_called_once_with( self.project.gid, params={"completed_since": "now"}, fields=list_matcher) def test_all_tasks_by_section(self) -> None: returned_tasks = self.client.tasks_by_section(self.section, only_incomplete=False) self.assertListEqual(returned_tasks, self.tasks[:-1]) self.inner_mock.tasks.find_by_section.assert_called_once_with( self.section.gid, fields=list_matcher)
class TestIsInProject(TestCase): client = create_autospec(Client) project = f.project(name="My project") task = f.task(memberships=[f.task_membership(project=project)]) def test_in_project_no_duration(self) -> None: predicate = IsInProject("My project") self.assertTrue(predicate(self.task, self.client)) def test_not_in_project(self) -> None: predicate = IsInProject("Other project") self.assertFalse(predicate(self.task, self.client)) @patch("archie.predicates._for_at_least") def test_call(self, for_at_least_mock: Mock) -> None: predicate = IsInProject("My project", for_at_least="2d") for_at_least_mock.return_value = return_sentinel = object() self.client.stories_by_task.return_value = story_sentinel = object() result = predicate(self.task, self.client) self.assertIs(result, return_sentinel) for_at_least_mock.assert_called_once_with(self.task, story_sentinel, predicate._story_matcher, timedelta(days=2)) def test_story_matcher(self) -> None: matcher = IsInProject("My project")._story_matcher self.assertTrue( matcher( f.story( resource_subtype="added_to_project", project=f.project(name="My project"), ))) self.assertFalse( matcher( f.story( resource_subtype="added_to_project", project=f.project(name="Other project"), ))) self.assertFalse(matcher(f.story(resource_subtype="comment_added")))
class TestTasksByProject(TestCaseWithClient): project = f.project() tasks = [f.task(gid="1"), f.task(gid="2")] def setUp(self) -> None: super().setUp() self.inner_mock.tasks.find_by_project.return_value = [ t.to_dict() for t in self.tasks ] def test_tasks_by_project(self) -> None: returned_tasks = self.client.tasks_by_project(self.project) self.assertListEqual(returned_tasks, self.tasks) self.inner_mock.tasks.find_by_project.assert_called_once_with( self.project.gid, params={"completed_since": "now"}, fields=list_matcher) def test_modified_tasks_by_project(self) -> None: returned_tasks = self.client.tasks_by_project(self.project, modified_since=datetime( 2019, 1, 1, 12, 0, 0)) self.assertListEqual(returned_tasks, self.tasks) self.inner_mock.tasks.find_by_project.assert_called_once_with( self.project.gid, params={ "completed_since": "now", "modified_since": "2019-01-01T12:00:00" }, fields=list_matcher, ) def test_all_tasks_by_project(self) -> None: returned_tasks = self.client.tasks_by_project(self.project, only_incomplete=False) self.assertListEqual(returned_tasks, self.tasks) self.inner_mock.tasks.find_by_project.assert_called_once_with( self.project.gid, params={}, fields=list_matcher)
def setUp(self, client_mock: Mock) -> None: self.client = client_mock.return_value = create_autospec(Client) self.project = self.client.project_by_gid.return_value = f.project() self.task_source = create_autospec(TaskSource) self.task_source.project_gid = self.project.gid self.triager = Triager("access_token", self.task_source)
from test import fixtures as f from unittest import TestCase from unittest.mock import create_autospec from archie.asana.client import Client from archie.predicates import Predicate from archie.workflows import SectionWorkflow, WorkflowStage from archie.workflows.section import ( _SectionWorkflowGetStageContext, _SectionWorkflowSetStageContext, _SectionWorkflowStageManager, ) predicate = create_autospec(Predicate) stages = [WorkflowStage("A", create_autospec(Predicate))] project = f.project(name="Project") sections = [f.section(name="A", project=project)] class TestSectionWorkflow(TestCase): def setUp(self) -> None: self.manager = _SectionWorkflowStageManager("Project", stages) def test_missing_project(self) -> None: warning = self.manager.get_current_stage(f.task(memberships=[])) self.assertEqual("Unable to find membership in 'Project'", warning) def test_missing_stage(self) -> None: stage, context = self.manager.get_current_stage( f.task(memberships=[ f.task_membership(project, f.section(name="C",
def setUp(self) -> None: self.client = create_autospec(Client) self.project = f.project() self.client.project_by_gid.return_value = self.project