Exemple #1
0
    def test_annul_tags(self):
        p = BlogPost(tags=['tag 1'])

        dummy = []
        p.tags = dummy
        dummy.append('tag 2')

        self.assertEqual(p.tags, [])
Exemple #2
0
    def test_decoding_of_encoded(self):
        p = BlogPost(text='foo bar baz',
                     tags=['tag 1', 'tag 2'
                           ])  # TODO: add tag with commas (will fail now)

        decoded = BlogPost.decode(p.encode())

        self.assertEqual(p.text, decoded.text)
        self.assertEqual(p.tags, decoded.tags)
        self.assertEqual(p.private, decoded.private)
Exemple #3
0
    def test_modifying(self):
        p = BlogPost(text='sample text', tags=['tag1', 'tag2'])

        p.text = 'new text'

        self.assertEqual(p.text, 'new text')

        p.tags = ['new tag']

        self.assertEqual(p.tags, ['new tag'])

        p.private = True

        self.assertEqual(p.private, True)
Exemple #4
0
    def test_decoding_post(self):
        text = "*tag 1, tag 2, tag 3\n\nfoobar"

        p = BlogPost.decode(text)

        self.assertEqual(p.text, 'foobar')
        self.assertEqual(p.tags, ['tag 1', 'tag 2', 'tag 3'])
        self.assertEqual(p.private, False)
Exemple #5
0
    def test_basic(self):
        p = BlogPost(text='foo', tags=['tag 1', 'tag 2'])

        expected = """------
*tag 1, tag 2

foo
------"""

        self.assertEqual(render('pre_post_preview', {'post': p}), expected)
Exemple #6
0
    def test_private(self):
        p = BlogPost(text='foo',
                     tags=['tag 1', 'tag 2', 'tag', 'tag'],
                     private=True)

        expected = """---PRIVATE POST---
*tag 1, tag 2, tag, tag

foo
---PRIVATE POST---"""

        self.assertEqual(render('pre_post_preview', {'post': p}), expected)
Exemple #7
0
    def test_add_tag(self):
        p = BlogPost()

        self.assertEqual(p.tags, [])
        p.add_tag('tag')

        self.assertEqual(p.tags, ['tag'])

        p.add_tag('   \n\t  tag 2 \t\t\n ')

        self.assertEqual(p.tags, ['tag', 'tag 2'])

        p.add_tags(['tag 3', '   \n\ttag 4 \n\t'])

        self.assertEqual(p.tags, ['tag', 'tag 2', 'tag 3', 'tag 4'])
Exemple #8
0
    def test_strip(self):
        p = BlogPost(text="""

                     foo bar baz

                     """,
                     tags=['   tag  ', '\ttag\t'])

        self.assertEqual(p.text, 'foo bar baz')
        self.assertEqual(p.tags, ['tag', 'tag'])

        p.text = """
        \t
        test
        \t

        """

        self.assertEqual(p.text, 'test')

        p.tags = ['   \ttag\t   ']

        self.assertEqual(p.tags, ['tag'])
Exemple #9
0
    def run(self, args):
        if args['pin']:
            self.pin(args['pin'])
            return

        if args['unpin']:
            self.unpin(args['unpin'])
            return

        post = BlogPost()

        post.private = args['private']

        if args['tag']:
            post.add_tags(
                args['tag'])  # yes, 'tag' is an array, and 'tags' is a string

        if args['tags']:
            post.add_tags(args['tags'].split(","))

        if args['message']:
            post.text = args['message']

        if args['stdin']:
            # --stdin -> --fast + --yes
            args['fast'] = True
            args['yes'] = True

            tmp = sys.stdin.read()
            tmp_post = BlogPost.decode(tmp)

            post.add_tags(tmp_post.tags)
            post.text = tmp_post.text

        self.post(post, args['fast'], args['yes'], args['draft'])
Exemple #10
0
    def test_decoding_empty(self):
        p = BlogPost.decode('')

        self.assertEqual(p.text, '')
        self.assertEqual(p.tags, [])
        self.assertEqual(p.private, False)
Exemple #11
0
    def test_decoding_no_tags(self):
        p = BlogPost.decode('foo')

        self.assertEqual(p.text, 'foo')
        self.assertEqual(p.tags, [])
        self.assertEqual(p.private, False)
Exemple #12
0
    def test_encoding_no_tags(self):
        p = BlogPost(text='foo')

        self.assertEqual(p.tags, [])

        self.assertEqual(p.encode(), 'foo')
Exemple #13
0
    def test_creation(self):
        p = BlogPost(text='sample text', tags=['tag 1', 'tag 2', 'tag', 'tag'])

        self.assertEqual(p.text, 'sample text')
        self.assertEqual(p.tags, ['tag 1', 'tag 2', 'tag', 'tag'])
        self.assertEqual(p.private, False)
Exemple #14
0
    def test_encode(self):
        p = BlogPost(text='foobar', tags=['tag1', 'tag 2', 'teh 3rd tag'])

        self.assertEqual(p.encode(), '*tag1, tag 2, teh 3rd tag\n'
                         '\n'
                         'foobar')
Exemple #15
0
    def test_decode_only_tags(self):
        p = BlogPost.decode('*tag 1, tag 2, tag 3')

        self.assertEqual(p.tags, ['tag 1', 'tag 2', 'tag 3'])
        self.assertEqual(p.text, '')
        self.assertEqual(p.private, False)