def test_foreign_container(self):
        # This spec is targeted to a person who's not a member of our team, so
        # only those workitems that are explicitly assigned to a member of our
        # team will be returned.
        spec = self.factory.makeSpecification(
            product=self.current_milestone.product,
            milestone=self.current_milestone,
            assignee=self.factory.makePerson())
        self.factory.makeSpecificationWorkItem(title='workitem 1',
                                               specification=spec)
        workitem = self.factory.makeSpecificationWorkItem(
            title='workitem 2',
            specification=spec,
            assignee=self.team.teamowner)

        workitems = getWorkItemsDueBefore(self.team,
                                          self.current_milestone.dateexpected,
                                          user=None)

        self.assertEqual([self.current_milestone.dateexpected],
                         workitems.keys())
        containers = workitems[self.current_milestone.dateexpected]
        self.assertEqual(1, len(containers))
        [container] = containers
        self.assertEqual(1, len(container.items))
        self.assertEqual(workitem, container.items[0].actual_workitem)
    def test_future_container(self):
        spec = self.factory.makeSpecification(
            product=self.current_milestone.product,
            assignee=self.team.teamowner)
        # This workitem is targeted to a future milestone so it won't be in
        # our results below.
        self.factory.makeSpecificationWorkItem(title='workitem 1',
                                               specification=spec,
                                               milestone=self.future_milestone)
        current_wi = self.factory.makeSpecificationWorkItem(
            title='workitem 2',
            specification=spec,
            milestone=self.current_milestone)

        workitems = getWorkItemsDueBefore(self.team,
                                          self.current_milestone.dateexpected,
                                          user=None)

        self.assertEqual([self.current_milestone.dateexpected],
                         workitems.keys())
        containers = workitems[self.current_milestone.dateexpected]
        self.assertEqual(1, len(containers))
        [container] = containers
        self.assertEqual(1, len(container.items))
        self.assertEqual(current_wi, container.items[0].actual_workitem)
    def test_basic(self):
        spec = self.factory.makeSpecification(
            product=self.current_milestone.product,
            assignee=self.team.teamowner,
            milestone=self.current_milestone)
        workitem = self.factory.makeSpecificationWorkItem(title='workitem 1',
                                                          specification=spec)
        bugtask = self.factory.makeBug(
            milestone=self.current_milestone).bugtasks[0]
        removeSecurityProxy(bugtask).assignee = self.team.teamowner

        workitems = getWorkItemsDueBefore(self.team,
                                          self.current_milestone.dateexpected,
                                          user=None)

        self.assertEqual([self.current_milestone.dateexpected],
                         workitems.keys())
        containers = workitems[self.current_milestone.dateexpected]
        # We have one container for the work item from the spec and another
        # one for the bugtask.
        self.assertEqual(2, len(containers))
        [workitem_container, bugtask_container] = containers

        self.assertEqual(1, len(bugtask_container.items))
        self.assertEqual(bugtask, bugtask_container.items[0].actual_workitem)

        self.assertEqual(1, len(workitem_container.items))
        self.assertEqual(workitem, workitem_container.items[0].actual_workitem)
    def test_basic(self):
        spec = self.factory.makeSpecification(
            product=self.current_milestone.product,
            assignee=self.team.teamowner, milestone=self.current_milestone)
        workitem = self.factory.makeSpecificationWorkItem(
            title=u'workitem 1', specification=spec)
        bugtask = self.factory.makeBug(
            milestone=self.current_milestone).bugtasks[0]
        removeSecurityProxy(bugtask).assignee = self.team.teamowner

        workitems = getWorkItemsDueBefore(
            self.team, self.current_milestone.dateexpected, user=None)

        self.assertEqual(
            [self.current_milestone.dateexpected], workitems.keys())
        containers = workitems[self.current_milestone.dateexpected]
        # We have one container for the work item from the spec and another
        # one for the bugtask.
        self.assertEqual(2, len(containers))
        [workitem_container, bugtask_container] = containers

        self.assertEqual(1, len(bugtask_container.items))
        self.assertEqual(bugtask, bugtask_container.items[0].actual_workitem)

        self.assertEqual(1, len(workitem_container.items))
        self.assertEqual(
            workitem, workitem_container.items[0].actual_workitem)
    def test_multiple_milestone_separation(self):
        # A single blueprint with workitems targetted to multiple
        # milestones is processed so that the same blueprint appears
        # in both with only the relevant work items.
        spec = self.factory.makeSpecification(
            product=self.current_milestone.product,
            assignee=self.team.teamowner)
        current_workitem = self.factory.makeSpecificationWorkItem(
            title='workitem 1',
            specification=spec,
            milestone=self.current_milestone)
        future_workitem = self.factory.makeSpecificationWorkItem(
            title='workitem 2',
            specification=spec,
            milestone=self.future_milestone)

        workitems = getWorkItemsDueBefore(self.team,
                                          self.future_milestone.dateexpected,
                                          user=None)

        # Both milestone dates are present in the returned results.
        self.assertContentEqual([
            self.current_milestone.dateexpected,
            self.future_milestone.dateexpected
        ], workitems.keys())

        # Current milestone date has a single specification
        # with only the matching work item.
        containers_current = workitems[self.current_milestone.dateexpected]
        self.assertContentEqual(
            [spec], [container.spec for container in containers_current])
        self.assertContentEqual(
            [current_workitem],
            [item.actual_workitem for item in containers_current[0].items])

        # Future milestone date has the same specification
        # containing only the work item targetted to future.
        containers_future = workitems[self.future_milestone.dateexpected]
        self.assertContentEqual(
            [spec], [container.spec for container in containers_future])
        self.assertContentEqual(
            [future_workitem],
            [item.actual_workitem for item in containers_future[0].items])
    def test_multiple_milestone_separation(self):
        # A single blueprint with workitems targetted to multiple
        # milestones is processed so that the same blueprint appears
        # in both with only the relevant work items.
        spec = self.factory.makeSpecification(
            product=self.current_milestone.product,
            assignee=self.team.teamowner)
        current_workitem = self.factory.makeSpecificationWorkItem(
            title=u'workitem 1', specification=spec,
            milestone=self.current_milestone)
        future_workitem = self.factory.makeSpecificationWorkItem(
            title=u'workitem 2', specification=spec,
            milestone=self.future_milestone)

        workitems = getWorkItemsDueBefore(
            self.team, self.future_milestone.dateexpected, user=None)

        # Both milestone dates are present in the returned results.
        self.assertContentEqual(
            [self.current_milestone.dateexpected,
             self.future_milestone.dateexpected],
            workitems.keys())

        # Current milestone date has a single specification
        # with only the matching work item.
        containers_current = workitems[self.current_milestone.dateexpected]
        self.assertContentEqual(
            [spec], [container.spec for container in containers_current])
        self.assertContentEqual(
            [current_workitem],
            [item.actual_workitem for item in containers_current[0].items])

        # Future milestone date has the same specification
        # containing only the work item targetted to future.
        containers_future = workitems[self.future_milestone.dateexpected]
        self.assertContentEqual(
            [spec],
            [container.spec for container in containers_future])
        self.assertContentEqual(
            [future_workitem],
            [item.actual_workitem for item in containers_future[0].items])
    def test_future_container(self):
        spec = self.factory.makeSpecification(
            product=self.current_milestone.product,
            assignee=self.team.teamowner)
        # This workitem is targeted to a future milestone so it won't be in
        # our results below.
        self.factory.makeSpecificationWorkItem(
            title=u'workitem 1', specification=spec,
            milestone=self.future_milestone)
        current_wi = self.factory.makeSpecificationWorkItem(
            title=u'workitem 2', specification=spec,
            milestone=self.current_milestone)

        workitems = getWorkItemsDueBefore(
            self.team, self.current_milestone.dateexpected, user=None)

        self.assertEqual(
            [self.current_milestone.dateexpected], workitems.keys())
        containers = workitems[self.current_milestone.dateexpected]
        self.assertEqual(1, len(containers))
        [container] = containers
        self.assertEqual(1, len(container.items))
        self.assertEqual(current_wi, container.items[0].actual_workitem)
    def test_foreign_container(self):
        # This spec is targeted to a person who's not a member of our team, so
        # only those workitems that are explicitly assigned to a member of our
        # team will be returned.
        spec = self.factory.makeSpecification(
            product=self.current_milestone.product,
            milestone=self.current_milestone,
            assignee=self.factory.makePerson())
        self.factory.makeSpecificationWorkItem(
            title=u'workitem 1', specification=spec)
        workitem = self.factory.makeSpecificationWorkItem(
            title=u'workitem 2', specification=spec,
            assignee=self.team.teamowner)

        workitems = getWorkItemsDueBefore(
            self.team, self.current_milestone.dateexpected, user=None)

        self.assertEqual(
            [self.current_milestone.dateexpected], workitems.keys())
        containers = workitems[self.current_milestone.dateexpected]
        self.assertEqual(1, len(containers))
        [container] = containers
        self.assertEqual(1, len(container.items))
        self.assertEqual(workitem, container.items[0].actual_workitem)