コード例 #1
0
    def test_text_to_django_story(self):
        story_text = "= a\nb"
        dstory = wm.Story(title=" a", story_description="b")
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)

        story_text = "= a #fire\nb"
        dstory = wm.Story(title=" a #fire",
                          story_description="b",
                          is_burning=True)
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)

        story_text = "= a #timebox\nb"
        dstory = wm.Story(title=" a #timebox",
                          story_description="b",
                          time_boxed=True)
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)

        story_text = "= a #green\nb"
        dstory = wm.Story(title=" a #green",
                          story_description="b",
                          is_green=True)
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)

        story_text = "= a #must\nb"
        dstory = wm.Story(title=" a #must", story_description="b", moscow="M")
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        story_text = "= a #should\nb"
        dstory = wm.Story(title=" a #should",
                          story_description="b",
                          moscow="S")
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        story_text = "= a #could\nb"
        dstory = wm.Story(title=" a #could", story_description="b", moscow="C")
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        story_text = "= a #would\nb"
        dstory = wm.Story(title=" a #would", story_description="b", moscow="W")
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)

        # tricky... we need to figure out how to handle tag removal in the future, in order to sync from form to text
        story_text = "= a #t1 #t2\nb"
        dstory = wm.Story(title=" a #t1 #t2",
                          story_description="b",
                          tags="#t1 #t2")
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
コード例 #2
0
def backlog_duplicate_story(request, story_id):
    try:
        story = models.Story.objects.get(id=story_id)
    except models.Story.DoesNotExist:
        raise Http404

    story_new = models.Story()
    story_new.title = story.title
    story_new.story_description = story.story_description
    story_new.moscow = story.moscow
    story_new.is_green = story.is_green
    story_new.tags = story.tags
    story_new.state = 'BACKLOG'
    story_new.time_boxed = story.time_boxed
    story_new.save()

    for task in story.task_set.all():
        task_new = models.Task()
        task_new.description = task.description
        task_new.score = task.score
        task_new.story = story_new
        task_new.owner = task.owner
        task_new.save()

    return HttpResponseRedirect(
        request.GET.get('return-to', reverse('web.index')))
コード例 #3
0
 def test_username_fail_resolve(self):
     story_text = "= a\nb\n-c [@a]"
     dstory = wm.Story(title=" a", story_description="b")
     dtask = wm.Task(description="c  [@a]")
     (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
     compare_django_stories(self, rstory, dstory)
     compare_django_tasks(self, rtasks, [dtask])
コード例 #4
0
 def test_username_resolve(self):
     u = wm.User.objects.create(username="******")
     story_text = "= a\nb\n-c [@andraz]"
     dstory = wm.Story(title=" a", story_description="b")
     dtask = wm.Task(description="c ", owner=u)
     (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
     compare_django_stories(self, rstory, dstory)
     compare_django_tasks(self, rtasks, [dtask])
コード例 #5
0
 def test_django_story_to_text_existing_tags(self):
     dstory = wm.Story(title="story_title",
                       story_description="story_description")
     dtask = wm.Task(description="task description [#abc]")
     res = converter.Converter.django_story_to_text(dstory, [dtask])
     self.assertEqual(
         res, "=story_title\nstory_description\n-task description [#abc]\n")
     dtask.state = "TO_CLOSED"
     res = converter.Converter.django_story_to_text(dstory, [dtask])
     self.assertEqual(
         res,
         "=story_title\nstory_description\n-task description [#abc #done]\n"
     )
コード例 #6
0
    def test_django_story_to_text(self):
        dstory = wm.Story(title="story_title",
                          story_description="story_description")
        res = converter.Converter.django_story_to_text(dstory, [])
        self.assertEqual(res, "=story_title\nstory_description\n")

        dstory.is_green = True
        res = converter.Converter.django_story_to_text(dstory, [])
        self.assertEqual(res, "=story_title\n[#green]\nstory_description\n")
        dstory.is_green = False

        dstory.is_burning = True
        res = converter.Converter.django_story_to_text(dstory, [])
        self.assertEqual(res, "=story_title\n[#fire]\nstory_description\n")
        dstory.is_burning = False

        dstory.moscow = 'M'
        res = converter.Converter.django_story_to_text(dstory, [])
        self.assertEqual(res, "=story_title\n[#must]\nstory_description\n")
        dstory.moscow = 'S'
        res = converter.Converter.django_story_to_text(dstory, [])
        self.assertEqual(res, "=story_title\n[#should]\nstory_description\n")
        dstory.moscow = 'C'
        res = converter.Converter.django_story_to_text(dstory, [])
        self.assertEqual(res, "=story_title\n[#could]\nstory_description\n")
        dstory.moscow = 'W'
        res = converter.Converter.django_story_to_text(dstory, [])
        self.assertEqual(res, "=story_title\n[#would]\nstory_description\n")
        dstory.moscow = None

        dstory.tags = "#t1 #t2"
        res = converter.Converter.django_story_to_text(dstory, [])
        self.assertEqual(res, "=story_title\n[#t1 #t2]\nstory_description\n")
        dstory.title = "title with tag #t2"  # here we make sure we don'd duplicate tags if they are already in the title
        res = converter.Converter.django_story_to_text(dstory, [])
        self.assertEqual(res,
                         "=title with tag #t2\n[#t1]\nstory_description\n")
        dstory.tags = None
        dstory.title = "story_title"

        dtask = wm.Task(description="task description")
        res = converter.Converter.django_story_to_text(dstory, [dtask])
        self.assertEqual(
            res, "=story_title\nstory_description\n-task description\n")
        res = converter.Converter.django_story_to_text(dstory, [dtask, dtask])
        self.assertEqual(
            res,
            "=story_title\nstory_description\n-task description\n-task description\n"
        )
コード例 #7
0
    def text_to_django_story(text):
        parser = yacc.get_parser(
            'story')  # we are testing just part of the parser
        text = text.replace("\r\n", "\n")  # convert crlf -> lf
        text = text.strip(
            "\n"
        ) + "\n"  # make sure there are no multiple new lines after the tasks
        story = parser.parse(text, tracking=True)
        if not story:
            raise Exception("Story parsing wasn't successful")
        dstory = wm.Story()
        dstory.title = story.title
        dstory.story_description = story.description
        dstory.state = 'BACKLOG'

        dstory_tags_list = []
        for t in story.tags:
            if "#green" == t:
                dstory.is_green = True
            elif "#fire" == t:
                dstory.is_burning = True
            elif "#timebox" == t:
                dstory.time_boxed = True
            elif "#would" == t:
                dstory.moscow = "W"
            elif "#could" == t:
                dstory.moscow = "C"
            elif "#should" == t:
                dstory.moscow = "S"
            elif "#must" == t:
                dstory.moscow = "M"
            else:
                dstory_tags_list.append(t)
        dstory.tags = " ".join(dstory_tags_list)

        dtasks = []
        for task in story.tasks:
            dtask = wm.Task()
            dtask.score = task.score
            dtask.description = task.text.text
            tags = []
            for t in task.tags:
                if t == "#done":
                    dtask.state = "TO_CLOSED"
                elif t == "#work":
                    dtask.state = "TO_WORKING"
                else:
                    tags.append(t)

            if task.owner:
                # make sure we catch the right errors here
                try:
                    dtask.owner = wm.User.objects.get(username=task.owner[1:])
                except ObjectDoesNotExist:
                    logging.warning(
                        "Could not resolve username: %s, we will add it as regular tag"
                        % task.owner)
                    tags.append(task.owner)

            if tags:
                dtask.description += " [" + " ".join(tags) + "]"

            dtask.story = dstory
            dtasks.append(dtask)

        return (dstory, dtasks)
コード例 #8
0
    def test_text_to_django_story_with_tasks(self):
        story_text = "= a\nb\n-c"
        dstory = wm.Story(title=" a", story_description="b")
        dtask = wm.Task(description="c")
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        compare_django_tasks(self, rtasks, [dtask])

        # empty taskmeta
        story_text = "= a\nb\n-c []"
        dstory = wm.Story(title=" a", story_description="b")
        dtask = wm.Task(description="c ")
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        compare_django_tasks(self, rtasks, [dtask])

        # score taskmeta
        story_text = "= a\nb\n-c [1]"
        dstory = wm.Story(title=" a", story_description="b")
        dtask = wm.Task(description="c ", score=1)
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        compare_django_tasks(self, rtasks, [dtask])

        # TEST USER - THIS ONE FAILS UNTIL PANCHO TELLS US WHERE THE @nick CAN BE RESOLVED
        '''
		story_text = "= a\nb\n-c [@a]"
		dstory = wm.Story(title = " a", story_description = "b")
		dtask = wm.Task(description = "c ", score = 1)
		(rstory, rtasks) = converter.Converter.text_to_django_story(story_text)	
		compare_django_stories(self, rstory, dstory)		
		compare_django_tasks(self, rtasks, [dtask])		
		'''

        # tag
        story_text = "= a\nb\n-c [#t1]"
        dstory = wm.Story(title=" a", story_description="b")
        dtask = wm.Task(description="c  [#t1]")
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        compare_django_tasks(self, rtasks, [dtask])

        # tag plus score
        story_text = "= a\nb\n-c [#t1 1]"
        dstory = wm.Story(title=" a", story_description="b")
        dtask = wm.Task(description="c  [#t1]", score=1)
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        compare_django_tasks(self, rtasks, [dtask])

        # #done
        story_text = "= a\nb\n-c [#done]"
        dstory = wm.Story(title=" a", story_description="b")
        dtask = wm.Task(description="c ", state="TO_CLOSED")
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        compare_django_tasks(self, rtasks, [dtask])

        #done
        story_text = "= a\nb\n-c [#work]"
        dstory = wm.Story(title=" a", story_description="b")
        dtask = wm.Task(description="c ", state="TO_WORKING")
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        compare_django_tasks(self, rtasks, [dtask])

        # badass tag combo
        story_text = "= a\nb\n-c [1 #work #t1]"
        dstory = wm.Story(title=" a", story_description="b")
        dtask = wm.Task(description="c  [#t1]", state="TO_WORKING", score=1)
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        compare_django_tasks(self, rtasks, [dtask])

        # badass tag double combo
        story_text = "= a\nb\n-c [1 #work #t1]\n-d [2 #done]"
        dstory = wm.Story(title=" a", story_description="b")
        dtask1 = wm.Task(description="c  [#t1]", state="TO_WORKING", score=1)
        dtask2 = wm.Task(description="d ", state="TO_CLOSED", score=2)
        (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
        compare_django_stories(self, rstory, dstory)
        compare_django_tasks(self, rtasks, [dtask1, dtask2])
コード例 #9
0
 def test_text_to_django_story_crlf(self):
     # here we check if CRLF gets correctly handled (converted to only LF before parsing)
     story_text = "= a\r\nb\n\n-c\n\n"
     dstory = wm.Story(title=" a", story_description="b\n")
     (rstory, rtasks) = converter.Converter.text_to_django_story(story_text)
     compare_django_stories(self, rstory, dstory)