示例#1
0
 def test_stories_by_task(self) -> None:
     task = f.task(gid="1")
     stories = [f.story(gid="2"), f.story(gid="3")]
     self.inner_mock.tasks.stories.return_value = [
         s.to_dict() for s in stories
     ]
     returned_stories = self.client.stories_by_task(task)
     self.assertListEqual(returned_stories, stories)
     self.inner_mock.tasks.stories.assert_called_once_with(
         task.gid, fields=list_matcher)
示例#2
0
    def test_subtype_filter(self) -> None:
        filt = subtype_filter("subtype_a")

        stories = [
            f.story(gid="1", resource_subtype="subtype_a"),
            f.story(gid="2", resource_subtype="subtype_b"),
            f.story(gid="3", resource_subtype="subtype_c"),
            f.story(gid="4", resource_subtype="subtype_a"),
        ]

        filtered = list(filter(filt, stories))
        self.assertListEqual(filtered, [stories[0], stories[3]])
示例#3
0
 def test(self) -> None:
     task = f.task()
     stories = [
         f.story(resource_subtype="comment_added"),
         f.story(resource_subtype="section_changed"),
         f.story(resource_subtype="enum_custom_field_changed"),
     ]
     client = create_autospec(Client)
     client.stories_by_task.return_value = stories
     comments = comments_by_task(task, client)
     self.assertListEqual(comments, [stories[0]])
     client.stories_by_task.assert_called_once_with(task)
示例#4
0
 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")))
示例#5
0
    def test_story_matcher(self) -> None:
        matcher = HasUnsetEnum("My custom field")._story_matcher

        self.assertTrue(
            matcher(
                f.story(
                    resource_subtype="enum_custom_field_changed",
                    custom_field=self.custom_field,
                )))
        self.assertFalse(
            matcher(
                f.story(
                    resource_subtype="enum_custom_field_changed",
                    custom_field=f.custom_field(name="Other custom field"),
                )))
        self.assertFalse(matcher(f.story(resource_subtype="unknown")))
示例#6
0
    def test_any_story(self) -> None:
        predicate = Untriaged()
        self.client.me.return_value = f.user()
        self.client.stories_by_task.return_value = [
            f.story(created_by=self.user)
        ]

        self.assertFalse(predicate(self.task, self.client))

        self.client.me.assert_called_once_with()
        self.client.stories_by_task.assert_called_once_with(self.task)
示例#7
0
    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")))
示例#8
0
    def test_old_story(self) -> None:
        self.client.me.return_value = self.user
        self.client.stories_by_task.return_value = [
            f.story(
                created_by=self.user,
                created_at=datetime(2019, 1, 1, 0, 0, 0, tzinfo=timezone.utc),
            )
        ]

        self.assertTrue(self.predicate(self.task, self.client))

        self.client.me.assert_called_once_with()
        self.client.stories_by_task.assert_called_once_with(self.task)
示例#9
0
 def test_story(self) -> None:
     matching_story = f.story(text="a",
                              created_at=datetime(2019,
                                                  1,
                                                  2,
                                                  12,
                                                  0,
                                                  0,
                                                  tzinfo=timezone.utc))
     for td, expected in [(timedelta(hours=24), False),
                          (timedelta(hours=23), True)]:
         with self.subTest(timedelta=td, expected=expected):
             result = _for_at_least(self.task, [matching_story],
                                    self.matcher, td)
             self.assertEqual(expected, result)
示例#10
0
class TestHasComment(TestCase):
    task = f.task()
    story = f.story(resource_subtype="comment_added", text="Comment text")

    def setUp(self) -> None:
        self.client = create_autospec(Client)

    def test_has_comment(self) -> None:
        self.client.stories_by_task.return_value = [self.story]
        predicate = HasComment()
        self.assertTrue(predicate(self.task, self.client))
        self.client.stories_by_task.assert_called_once_with(self.task)

    def test_has_matching_comment(self) -> None:
        self.client.stories_by_task.return_value = [self.story]
        matcher = Mock(return_value=True)
        predicate = HasComment(matcher)
        self.assertTrue(predicate(self.task, self.client))
        matcher.assert_called_once_with(self.story.text)
        self.client.stories_by_task.assert_called_once_with(self.task)

    def test_has_no_matching_comment(self) -> None:
        self.client.stories_by_task.return_value = [self.story]
        matcher = Mock(return_value=False)
        predicate = HasComment(matcher)
        self.assertFalse(predicate(self.task, self.client))
        matcher.assert_called_once_with(self.story.text)
        self.client.stories_by_task.assert_called_once_with(self.task)

    def test_has_matching_literal(self) -> None:
        self.client.stories_by_task.return_value = [self.story]
        predicate = HasComment("ment te")
        self.assertTrue(predicate(self.task, self.client))
        self.client.stories_by_task.assert_called_once_with(self.task)

    def test_has_no_matching_literal(self) -> None:
        self.client.stories_by_task.return_value = [self.story]
        predicate = HasComment("unmatched")
        self.assertFalse(predicate(self.task, self.client))
        self.client.stories_by_task.assert_called_once_with(self.task)

    def test_no_comment(self) -> None:
        self.client.stories_by_task.return_value = []
        predicate = HasComment()
        self.assertFalse(predicate(self.task, self.client))
        self.client.stories_by_task.assert_called_once_with(self.task)
示例#11
0
 def test_story_matcher(self) -> None:
     user = f.user(gid="1")
     matcher = partial(self.predicate._story_matcher, user)
     self.assertTrue(matcher(f.story(created_by=user)))
     self.assertFalse(matcher(f.story(created_by=f.user(gid="2"))))
     self.assertFalse(matcher(f.story(created_by=None)))
示例#12
0
class TestUntriaged(TestCase):
    task = f.task()
    user = f.user()
    triage_story = f.story(created_by=user)
    predicate = Untriaged(for_at_least="2d")

    def setUp(self) -> None:
        self.client = create_autospec(Client)

    def test_no_story(self) -> None:
        self.client.me.return_value = self.user
        self.client.stories_by_task.return_value = []

        self.assertTrue(self.predicate(self.task, self.client))

        self.client.me.assert_called_once_with()
        self.client.stories_by_task.assert_called_once_with(self.task)

    def test_recent_story(self) -> None:
        self.client.me.return_value = self.user
        self.client.stories_by_task.return_value = [
            f.story(
                created_by=self.user,
                created_at=datetime(2019, 1, 2, 12, 0, 0, tzinfo=timezone.utc),
            )
        ]

        self.assertFalse(self.predicate(self.task, self.client))

        self.client.me.assert_called_once_with()
        self.client.stories_by_task.assert_called_once_with(self.task)

    def test_old_story(self) -> None:
        self.client.me.return_value = self.user
        self.client.stories_by_task.return_value = [
            f.story(
                created_by=self.user,
                created_at=datetime(2019, 1, 1, 0, 0, 0, tzinfo=timezone.utc),
            )
        ]

        self.assertTrue(self.predicate(self.task, self.client))

        self.client.me.assert_called_once_with()
        self.client.stories_by_task.assert_called_once_with(self.task)

    def test_any_story(self) -> None:
        predicate = Untriaged()
        self.client.me.return_value = f.user()
        self.client.stories_by_task.return_value = [
            f.story(created_by=self.user)
        ]

        self.assertFalse(predicate(self.task, self.client))

        self.client.me.assert_called_once_with()
        self.client.stories_by_task.assert_called_once_with(self.task)

    def test_story_matcher(self) -> None:
        user = f.user(gid="1")
        matcher = partial(self.predicate._story_matcher, user)
        self.assertTrue(matcher(f.story(created_by=user)))
        self.assertFalse(matcher(f.story(created_by=f.user(gid="2"))))
        self.assertFalse(matcher(f.story(created_by=None)))