예제 #1
0
    def test_find_snippet_with_tags(self):

        # These two posts are equivalent, except that only is tagged with a tag that we
        # will use for filtering in the test.
        post1 = create_post(body=self._make_post_body('\n'.join([
            'import re',
            'characters = re.findall(r"\w", "foo")',
            'for c in characters:',
            '    print c',
        ])))
        post2 = create_post(body=self._make_post_body('\n'.join([
            'import re',
            'characters = re.findall(r"\w", "foo")',
            'for c in characters:',
            '    print c',
        ])))
        tag1 = create_tag(tag_name='javascript')
        tag2 = create_tag(tag_name='python')
        PostTag.create(post_id=post1.id, tag_id=tag1.id)
        PostTag.create(post_id=post2.id, tag_id=tag2.id)

        self._extract(['re.findall'], tags=['python'])
        self.assertEqual(PostSnippet.select().count(), 1)
        self.assertEqual(PostSnippet.select().first().post, post2)
 def _create_post(self, body, tag_name='node.js'):
     post = create_post(body=self._make_post_body(body))
     tag = create_tag(tag_name=tag_name)
     PostTag.create(post_id=post.id, tag_id=tag.id)
     return post