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 setUp(self) -> None: super().setUp() self.section = f.section(gid="2", name="Section 2") self.client.sections_by_project.return_value = [ f.section(gid="1", name="Section 1"), self.section, f.section(gid="3", name="Section 3"), ]
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_missing_stage(self) -> None: stage, context = self.manager.get_current_stage( f.task(memberships=[ f.task_membership(project, f.section(name="C", project=project)) ])) expected_context = _SectionWorkflowGetStageContext(project) self.assertIsNone(stage) self.assertEqual(expected_context, context)
def test_add_to_section(self) -> None: section = f.section() task = f.task() self.inner_mock.tasks.add_project.return_value = None self.client.add_to_section(task, section) self.inner_mock.tasks.add_project.assert_called_once_with( task.gid, { "project": section.project.gid, "section": section.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)
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", project=project))
class TestIsInProjectAndSection(TestCase): client = create_autospec(Client) project = f.project(name="My project") section = f.section(name="My section", project=project) task = f.task( memberships=[f.task_membership(project=project, section=section)]) def test_in_project_and_section_no_duration(self) -> None: predicate = IsInProjectAndSection("My project", "My section") self.assertTrue(predicate(self.task, self.client)) def test_not_in_section(self) -> None: predicate = IsInProjectAndSection("My project", "Other section") self.assertFalse(predicate(self.task, self.client)) def test_not_in_project(self) -> None: predicate = IsInProjectAndSection("Other project", "My section") self.assertFalse(predicate(self.task, self.client)) @patch("archie.predicates._for_at_least") def test_call(self, for_at_least_mock: Mock) -> None: predicate = IsInProjectAndSection("My project", "My section", 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 = 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")))