def test_create_test_in_blog(self):
        b = Blog("Test", "Test Author")
        b.create_post("Test Post", "Test Content")

        self.assertEqual(len(b.posts), 1)
        self.assertEqual(b.posts[0].title, "Test Post")
        self.assertEqual(b.posts[0].content, "Test Content")
    def test_json_no_posts(self):
        b = Blog('Test', 'Test author')

        self.assertDictEqual(b.json(), {
            'title': b.title,
            'author': b.author,
            'posts': [],
        })
    def test_json_with_posts(self):
        b = Blog('Test', 'Test author')
        b.create_post('Test Post', 'Test Content')

        self.assertDictEqual(b.json(), {
            'title': b.title,
            'author': b.author,
            'posts': [{'title': 'Test Post', 'content': 'Test Content'}],
        })
Esempio n. 4
0
def main():
    header = u"Content-Type: text/html\n"
    content = []
    blog = Blog()
    field_storage = FieldStorage()
    post_datas = {}
    for k in ("author", "password", "hash", "title", "content", "post"):
        post_datas[k] = get_value(field_storage, k)
    mode = get_value(field_storage, "mode", "add")
    captcha_code = get_value(field_storage, "captcha_content")
    captcha_path = get_value(field_storage, "captcha_path")
    post_id = get_value(field_storage, "post")
    user, power = blog.is_user(post_datas["author"], post_datas["password"],
            post_datas["hash"])
    if (blog.get_captcha_code(captcha_path) != captcha_code.strip(" ") and
            not user):
        content.append(protocol.error(_(u"Invalid captcha")))
    elif mode in ("edit", "del", "retrieve") and not (post_id and
            raw_post_id.isdigit()):
        content.append(protocol.error(_(u"Need an id")))
    elif mode == "add":
        if not (post_datas["author"] and post_datas["content"]):
            content.append(protocol.error(_(u"You have to write as least your"
                                            " name and a comment.")))
        elif not post_datas["post"]:
            content.append(protocol.error(_(u"Internal : no post ??")))
        else:
            post_datas["date"] = time()
            post_datas["moderated"] = True if blog.config.getboolean("comment",
                    "auto_moderated") else False
            new_id = blog.add_comment(Comment(**post_datas))
            content.append(protocol.success(_(u"Comment added")))
            blog.clean_captchas(captcha_path)
    elif mode == "del":
        if user:
            blog.del_comment(int(post_id))
            content.append(protocol.succes(_(u"Comment deleted")))
        else:
            content.append(protocol.error(_(u"You don't have the permission for"
                                             " doing this.")))
    elif mode == "edit":
        content.append(error(_("Not implemented")))
    elif mode == "retrieve":
        comment = blog.get_comment_by_id(int(post_id))
        if comment:
            content.append(protocol.succes(protocol.format_comment(comment)))
        else:
            content.append(protocol.error(_(u"No id %s") % post_id))
    else:
        content.append(protocol.error(_(u"You're doing it wrong.")))
        
    if post_datas["post"]:
        content.append(XHTML.tags.A(blog.rewrite(post=post_datas["post"]),
                _("Back to the post")).tostr())
    print header
    print u"\n".join(content).encode("utf-8", "replace")
Esempio n. 5
0
def create_blog(cfg):
    blogname = cfg["blog.title"]
    templatedir = config.get_path(cfg, "templates.path")
    templates = read_templates(templatedir)
    articledir = config.get_path(cfg, "articles.path")
    articles = read_articles(articledir)
    mmd = create_mmd(cfg)
    blog = Blog(blogname, templates, mmd)
    for article in articles.values():
        blog.load_post(article)
    return blog
    def test_json(self):
        b = Blog("Test", "Test Author")
        b.create_post("Test Post", "Test Content")

        expected = {
            "title": "Test",
            "author": "Test Author",
            "posts": [ {"title": "Test Post",
                        "content": "Test Content"}] }

        self.assertDictEqual(expected, b.json())
Esempio n. 7
0
	def post(self):
		subject = self.request.get("subject")
		blog_content = self.request.get("content")
		if subject and blog_content:
			a_blog = Blog(subject = subject, blog_content = blog_content)
			a_blog.put()
			#db.allocate_ids(a_blog.key(), 1000)
			time.sleep(1)
			self.redirect('/' + str(a_blog.key().id()))
		else:
			self.render_newpost(subject = subject, 
					blog_content = blog_content, 
					error = POSTNEW_ERROR)
Esempio n. 8
0
def reports_by_group_id(group_id):
    edges = []
    nodes = []
    index = {}
    _in = defaultdict(int)
    _out = defaultdict(int)
    ids =  user_id_by_group_id(group_id)
    for n,i in enumerate(ids):
        index[i] = n
    for user_id in ids:
        user = get_user(user_id)
        if Blog.get(user_id=user_id):
            #blog_id = Blog.get(user_id=user_id).id
            author_id = get_author_id_by_user_id(user_id)
            comments = Comment.where(author_id=author_id)
            counts = count_in(comments, user_id, ids, _in, _out)
            for i, j in counts.iteritems():
                target = get_user(i)
                edge = {'source': index[user_id],
                        'target': index[i],
                        'value': j,
                        }
                edges.append(edge)

    nodes = [
            {   'name': get_user(i).name,
                'in': _in[i],
                'out': _out[i],
                'weight': _in[i]+_out[i],
                'index': n,
                'id':i,
                 }
            for n,i in enumerate(ids)
            ] 
    return {'nodes': nodes, 'links': edges}
Esempio n. 9
0
def main():
    try:
        opts, args = getopt.getopt(
            sys.argv[1:], "ht:d:s:p:", ["title", "help", "publish="])
    except getopt.GetoptError:
        usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ('-h', '--help'):
            usage()
            sys.exit()
        elif opt in ('-p', '--publish'):
            p = Post(arg)
            p.write()
            print('Post/page published, you might want to update now.')

        elif opt in ('-t', '--title'):
            # one-time modification of the template
            f = codecs.open(templatedir+'base.html', 'r', encoding)
            soup = BeautifulSoup(f.read(), 'html.parser')
            f.close()

            tag = soup.find('title')
            tag.contents[0].replaceWith(arg + '${self.title()}')

            tag = soup.find('a', 'title')
            tag.contents[0].replaceWith(arg)

            f = codecs.open(templatedir+'base.html', 'w', encoding)
            f.write(str(soup).decode(encoding))
            f.close()

            print('Title was set to:' + arg)
            sys.exit()
        else:
            assert False, "unhandled option"

    blog = Blog()

    for a in args:
        if a == 'index':
            blog.index()
        elif a == 'archive':
            blog.archive()
    if args == []:
        if site_type == 'blog':
            print("--> Updating your blog")
            blog.update_blog()
        else:
            print("--> Updating your site")
            blog.update_site()
Esempio n. 10
0
def main():
    header = u"Content-Type: text/html\n"
    content = []
    blog = Blog()
    post_datas = FieldStorage()
    mode = get_value(post_datas, "mode", "add")
    user = get_value(post_datas, "user")
    password = get_value(post_datas, "password")
    hash = get_value(post_datas, "hash")
    user, power = blog.is_user(user, password, hash)
    post_id = get_value(post_datas, "post")
    target = get_value(post_datas, "target")
    target_password = get_value(post_datas, "target_password")
    power = get_value(post_datas, "power")
    power_exists = (power and power.isdigit() and int(power) < VOICE)
    if not user:
        content.append(protocol.error(_(u"Wrong username/password")))
    elif not (blog.has_power(user, OP if mode == "add" else ROOT) or
            user == post[0]["author"]):
        content.append(protocol.error(_(u"You don't have the permission to do"
                                         " that.")))
    elif not (target and (power_exists and password and mode == "add") or 
             ((power_exists or password) and mode == "edit") or mode == "del"):
        content.append(protocol.error(_(u"Post datas are not set")))
    # It's ok.
    elif mode == "add":
        if not (target_password and power):
            content.append(protocol.error(_(u"Please set a password and"
                                             " permissions.")))
        else:
            ret = blog.add_user(target, target_password, power)
            content.append(protocol.success(ret) if ret else
                    protocol.error(_(u"User exists")))
    elif mode == "edit":
        blog.set_user(target, target_password if target_password else None,
                power if power else None)
        content.append(protocol.success())
    elif mode == "del":
        blog.del_user(target)
        content.append(protocol.success())
    else:
        content.append(protocol.error(_(u"Wrong mode.")))
    print header
    print u"\n".join(content).encode("utf-8", "replace")
Esempio n. 11
0
def generate():
    from blog import Blog
    b = Blog(SOURCE_DIR)
    b.render()
Esempio n. 12
0
 def test_repr(self):
     blog = Blog("Orange", "Mauli")
     self.assertEqual("Orange  by Mauli and 0 posts",blog.__repr__())
Esempio n. 13
0
	def test_create_blog(self):
		b = Blog('Test Title', 'Test Author')

		self.assertEqual('Test Title', b.title)
		self.assertEqual('Test Author', b.author)
		self.assertListEqual([], b.posts)
    def test_repr(self):
        b = Blog("Test", "Test Author")
        b2 = Blog("My Day", "Rolf")

        self.assertEqual(b.__repr__(), "Test by Test Author (0 posts)")
        self.assertEqual(b2.__repr__(), "My Day by Rolf (0 posts)")
Esempio n. 15
0
 def _prompt_user_for_account(self):
     title = input("Enter blog title: ")
     description = input("Enter blog description: ")
     blog = Blog(author=self.user, title=title, description=description)
     blog.save_to_mongo()
     self.user_blog = blog
Esempio n. 16
0
def main():
    header = u"Content-Type: text/html\n"
    content = []
    blog = Blog()
    post_datas = FieldStorage()
    mode = get_value(post_datas, "mode", "retrieve")
    user = get_value(post_datas, "user")
    password = get_value(post_datas, "password")
    hash = get_value(post_datas, "hash")
    user, power = blog.is_user(user, password, hash)
    post_id = get_value(post_datas, "post", "")
    if mode in ("retrieve", "edit", "del") and not (post_id and
            post_id.isdigit()):
        content.append(protocol.error(_(u"Variable 'post' is not set.")))

    elif mode == "retrieve":
        post = blog.get_posts(post_id=int(post_id))
        if post:
            content.append(protocol.success(protocol.format_post(post)))
        else:
            content.append(protocol.error(_(u"No id %s." % post_id)))

    elif mode == "add":
        if user and blog.has_power(user, VOICE):
            datas = {"author": user, "date": time()}
            for k, d in (("title", u"No title"), ("tags", u""),
                    ("content", u"")):
                datas[k] = get_value(post_datas, k, d)
            new_id = blog.add_post(Post(**datas))
            content.append(protocol.success(unicode(new_id)))
        else:
            content.append(protocol.error(_(u"Wrong username/password.")))

    elif mode == "edit":
        post_id = get_value(post_datas, "post", "")
        datas = {"author": user, "date": time(), "id": int(post_id)}
        for k, d in (("title", u"No title"), ("tags", u""),
                ("content", u"")):
            datas[k] = get_value(post_datas, k, d)
        post = blog.get_posts(post_id=int(post_id))
        if post:
            if user == post["author"] or blog.has_power(user, HOP):
                blog.edit_post(Post(**datas))
                content.append(protocol.success(unicode(datas["id"])))
            else:
                content.append(protocol.error(_(u"You don't have the permission"
                                                 " to do that.")))
        else:
            content.append(protocol.error(_(u"No id %s.")) % post_id)

    elif mode == "del":
        post_id = get_value(post_datas, "post", "")
        post = blog.get_posts(post_id=int(post_id))
        if user == post["author"] or blog.has_power(user, HOP):
            if blog.del_post(post_id):
                content.append(protocol.error(_(u"(internal)")))
            else:
                content.append(protocol.success())
        else:
            content.append(protocol.error(_(u"You don't have the permission to"
                                             " do that.")))

    else:
        content.append(protocol.error(_(u"Wrong mode.")))

    print header
    print u"\n".join(content).encode("utf-8", "replace")
Esempio n. 17
0
class TestBlog:

    def setup(self):
        self.blog = Blog(engine='sqlite://')
        self.savedstdout = sys.stdout
        sys.stdout = io.StringIO()

    def teardown(self):
        self.blog.metadata.drop_all()
        sys.stdout = self.savedstdout

    def test_post_add(self):
        self.blog.post_add('test post', 'test content')
        expected_result = [(1, 'test post', 'test content')]
        real_result = list(sql.select([self.blog.posts_table]).execute())
        assert_equals(expected_result, real_result)

    def test_post_add_category(self):
        self.blog.post_add('test post', 'test content',
                           category_name='test category')
        expected_posts = [(1, 'test post', 'test content')]
        expected_categories = [(1, 'test category',)]
        expected_categories_posts = [(1, 1, 1)]
        real_posts = list(sql.select([self.blog.posts_table]).execute())
        real_categories = \
            list(sql.select([self.blog.categories_table]).execute())
        real_categories_posts = list(
            sql.select([self.blog.categories_posts_table]).execute())
        assert_equals(expected_posts, real_posts)
        assert_equals(expected_categories, real_categories)
        assert_equals(expected_categories_posts, real_categories_posts)

    def test_post_list(self):
        self.blog.posts_table.insert().execute(
            title='test title', content='test content')
        self.blog.post_list()
        assert_equals(
            sys.stdout.getvalue().strip(), '1 | test title | test content')

    def test_post_search(self):
        self.blog.posts_table.insert().execute(
            title='test title', content='test content')
        self.blog.posts_table.insert().execute(
            title='second', content='2nd post')
        self.blog.posts_table.insert().execute(title='third', content='3rd')
        self.blog.post_search('second')
        assert_equals(sys.stdout.getvalue().strip(), '2 | second | 2nd post')

    def test_category_add(self):
        self.blog.category_add('my category')
        expected_result = [(1, 'my category')]
        real_result = list(sql.select([self.blog.categories_table]).execute())
        assert_equals(expected_result, real_result)

    def test_category_list(self):
        self.blog.categories_table.insert().execute(name='test category')
        self.blog.category_list()
        expected_result = '1 test category'
        real_result = sys.stdout.getvalue().strip()
        assert_equals(expected_result, real_result)

    def test_category_assign(self):
        self.blog.posts_table.insert().execute(
            title='test title', content='test content')
        self.blog.categories_table.insert().execute(name='test category')
        self.blog.category_assign(1, 1)
        expected_result = [(1, 1, 1)]
        real_result = list(
            sql.select([self.blog.categories_posts_table]).execute())
        assert_equals(expected_result, real_result)
        self.blog.category_assign(1, 2)
        assert_equals(sys.stdout.getvalue().strip(),
                      'post or category with given id does not exist')
Esempio n. 18
0
def ask_create_blog():
    title = input('Enter your blog title: ')
    author = input('What is your name: ')

    blogs[title] = Blog(title, author)
    def test_json_no_posts(self):
        b = Blog("Test", "Test author")
        expected = {"title": "Test", "author": "Test author", "posts": []}

        self.assertDictEqual(expected, b.json(),
                             "blog with no posts dict not as expected")
Esempio n. 20
0
if __name__ == '__main__':
  lObj = Login()
  cookie = lObj.login(USERNAME,PASSWORD)
  cookie = re.sub('domain.*?[;,]','',cookie)
  cookie = re.sub('[Hh]ttponly,','',cookie)
  cookie = re.sub('path=/;','',cookie)
  cookie +=';'
  

  #print unicode('0x53F6').encode('UTF-8')
  #print unicode('作')
  #sys.exit()
  cObj = CrawlerData()
  mObj = Mongo(CONF)
  wObj = Weibo(APP_KEY , APP_SECRET , TOKEN)
  bObj = Blog(cObj,cookie,wObj)
  print cookie

  #a = wObj.client.short_url.shorten.post(url_long = 'http://www.youku.com/')
  #print a['urls'][0]['url_short']
  #sys.exit()
  #items = cObj.getParseData(HACKER_NEWS_RSS_URL)
  items = cObj.getParseData(STARTUP_NEWS_RSS_URL)
  ss = 1
  
  for item in items:
    ss +=1
    if ss !=6:
      continue
    print item['title']
    print ss
 def setup(self):
     """ setup is function inside a test case ,the setup   will run before each test """
     blog = Blog("Test", "Test Author")
     app.blogs = {"Test": blog}
Esempio n. 22
0
 def setUp(self):
     blog = Blog("Test", "Test Author")
     app.blogs = {"Test": blog}
Esempio n. 23
0
 def setUp(self):
     blog = Blog('Konza City', 'Allan')
     app.blogs = {'Konza City': blog}
    def test_create_blog(self):
        my_blog = Blog('BlogName', 'BlogAuthor')

        self.assertEqual('BlogName', my_blog.title)
        self.assertEqual('BlogAuthor', my_blog.author)
        self.assertListEqual([], my_blog.posts)
Esempio n. 25
0
    def test_create_post_in_blog(self):
        b = Blog('Test', 'Test author')
        b.create_post('Test Post', 'Test Content')

        self.assertEqual(b.posts[0].title, 'Test Post')
        self.assertEqual(b.posts[0].content, 'Test Content')
Esempio n. 26
0
blogtest = BlogTest()
print "test ing"
urlpatterns = patterns('blog.views',
	url(r'^ajax/add/$', 'view.add_todo'),
	url(r'^ajax/more/$', 'view.more_todo'),

	#url(r'^page/$', 'index'),
	#url(r'^page/(?P<page>\d+)/$', 'index'),
	url(r'^entry/(?P<entry_id>[0-9]*)$', 'read'),
	url(r'^write/$', blogtest.write_form),

    url(r'^add/post/$', 'add_post'),
	url(r'^add/comment$', 'add_comment'),
	url(r'^del/comment$', 'del_comment'),
	url(r'^get/comments/(?P<entry_id>\d+)/$', 'get_comments'),

	url(r'^test/$', 'write_test'),
	url(r'^testresult/$', 'write_test_result'),

	url(r'^readtest/$', 'readtest'),
	
	url(r'^tt/$', 'blog'),

    url(r'', Blog.as_view(), name='Blog'),
	
	url(r'^page/(?P<page>\d+)/$', Blog.as_view(), name='Blog'),
	url(r'', Blog.as_view(), name='Blog'),
	#url(r'^$', 'index'),
	#url(r'', TemplateView.as_view(template_name='main/index.html')),
)
Esempio n. 27
0
    def test_json_no_post(self):
        b = Blog('Test', "Test Author")

        expected = {'title': 'Test', 'author': "Test Author", 'posts': []}

        self.assertDictEqual(expected, b.json())
Esempio n. 28
0
 def __init__(self, admin_url, username, password):
     Blog.__init__(self, admin_url, username, password)
Esempio n. 29
0
	def setUp(self):
		blog = Blog('Test blog title', 'Test blog author')
		app.blogs = {'Test': blog}
    def test_repr_multiple_posts(self):
        my_blog = Blog('BlogName', 'BlogAuthor')
        my_blog.posts = ['siema', 'elo', 'co tam', 'yo-man', 'nowy post']

        self.assertEqual(my_blog.__repr__(), 'BlogName by BlogAuthor (5 posts)')
Esempio n. 31
0
 def setUp(self) -> None:
     self.blog = Blog('Test', 'Test Author')
Esempio n. 32
0
    def test_repr(self):
        b = Blog('Test', 'Test Author')
        b2 = Blog('My day', 'Athenkosi')

        self.assertEqual(b.__repr__(), 'Test by Test Author (0 posts)')
        self.assertEqual(b2.__repr__(), 'My day by Athenkosi (0 posts)')
Esempio n. 33
0
 def test_repr(self):
     blog2 = Blog('My day', 'Rolf')
     self.assertEqual(self.blog.__repr__(), 'Test by Test Author (0 posts)')
     self.assertEqual(blog2.__repr__(), 'My day by Rolf (0 posts)')
Esempio n. 34
0
	def test_repr(self):
		b = Blog('Test Title', 'Test Author')
		b2 = Blog('My day', 'Susan')

		self.assertEqual(b.__repr__(), 'Test Title by Test Author (0 posts)')
		self.assertEqual(b2.__repr__(), 'My day by Susan (0 posts)')
Esempio n. 35
0
 def test_repr(self):
     b = Blog("Test_blog", "Test_blog_author")
     b2 = Blog("Pierwszy post", "Kuba")
     b2.post = ["testowy", "drugi testowy"]
     self.assertEqual(b.__repr__(), "Test_blog by Test_blog_author (0 post)")
     self.assertEqual(b2.__repr__(), "Pierwszy post by Kuba (2 posts)")
Esempio n. 36
0
 def test_json(self):
     blog = Blog("Orange", "Mauli")
     p = Post("First Post", "Best Content")
     blog.add_post(p,"")
     expected = {"author": "Mauli","name": "Orange", "posts":[{"title":"First Post","content":"Best Content"}]}
     self.assertDictEqual(expected, blog.json())
Esempio n. 37
0
    def test_create_blog(self):
        b = Blog("Test_blog", "Test_blog_author")

        self.assertEqual("Test_blog", b.title)
        self.assertEqual("Test_blog_author", b.author)
        self.assertListEqual([], b.post)
Esempio n. 38
0
 def test_json_no_posts(self):
     b = Blog("Test", "Test Author")
     expected = {"title": "Test", "author": "Test Author", "posts": []}
     
     self.assertDictEqual(expected, b.json())
Esempio n. 39
0
    def test_repr(self):
        b = Blog('Test', 'Test Author')
        b2 = Blog('My Day', 'Rolf')

        self.assertEqual(b.__repr__(), 'Test by Test Author (0 posts)')
        self.assertEqual(b2.__repr__(), 'My Day by Rolf (0 posts)')
    def test_repr(self):
        my_blog = Blog('BlogName', 'BlogAuthor')

        self.assertEqual(my_blog.__repr__(), 'BlogName by BlogAuthor (0 posts)')
    def test_json_no_posts(self):
        b = Blog("Test", "Test Author")
        expected = {"title": "Test", "author": "Test Author", "posts": []}

        self.assertDictEqual(expected, b.json())
Esempio n. 42
0
 def setup(self):
     self.blog = Blog(engine='sqlite://')
     self.savedstdout = sys.stdout
     sys.stdout = io.StringIO()
Esempio n. 43
0
def ask_create_blog():
    title = input("Enter your blog title: ")
    author = input("Enter your name: ")

    blogs[title] = Blog(title, author)
Esempio n. 44
0
	def render_blog(self, page_id):
		a_blog = Blog.get_by_id(ids = int(page_id))
		self.render("pages.html", a_blog = a_blog)
Esempio n. 45
0
 def setUp(
     self
 ):  #zazenemo pred zacetkom vsakega testa da ne ponavljamo kode ker te dve vrstici rabimo velikokrat
     blog = Blog('Test', 'Test Author')
     app.blogs = {'Test': blog}
Esempio n. 46
0
 def setup(self):
     self.blog = Blog(engine='sqlite://')
     self.savedstdout = sys.stdout
     sys.stdout = io.StringIO()
Esempio n. 47
0
def ask_create_blog():
    # title, author
    title = input('Enter a title for the blog:')
    author = input('Enter your name:')
    blogs[title] = Blog(title, author)
Esempio n. 48
0
 def __init__(self, admin_url, username, password):
     Blog.__init__(self, admin_url, username, password)
     self.api = gdata.blogger.client.BloggerClient()
Esempio n. 49
0
 def setUp(self):
     blog = Blog('Test', 'Test Author')
     app.blogs = {'Test': blog}
Esempio n. 50
0
class TestBlog:
    def setup(self):
        self.blog = Blog(engine='sqlite://')
        self.savedstdout = sys.stdout
        sys.stdout = io.StringIO()

    def teardown(self):
        self.blog.metadata.drop_all()
        sys.stdout = self.savedstdout

    def test_post_add(self):
        self.blog.post_add('test post', 'test content')
        expected_result = [(1, 'test post', 'test content')]
        real_result = list(sql.select([self.blog.posts_table]).execute())
        assert_equals(expected_result, real_result)

    def test_post_add_category(self):
        self.blog.post_add('test post',
                           'test content',
                           category_name='test category')
        expected_posts = [(1, 'test post', 'test content')]
        expected_categories = [(
            1,
            'test category',
        )]
        expected_categories_posts = [(1, 1, 1)]
        real_posts = list(sql.select([self.blog.posts_table]).execute())
        real_categories = \
            list(sql.select([self.blog.categories_table]).execute())
        real_categories_posts = list(
            sql.select([self.blog.categories_posts_table]).execute())
        assert_equals(expected_posts, real_posts)
        assert_equals(expected_categories, real_categories)
        assert_equals(expected_categories_posts, real_categories_posts)

    def test_post_list(self):
        self.blog.posts_table.insert().execute(title='test title',
                                               content='test content')
        self.blog.post_list()
        assert_equals(sys.stdout.getvalue().strip(),
                      '1 | test title | test content')

    def test_post_search(self):
        self.blog.posts_table.insert().execute(title='test title',
                                               content='test content')
        self.blog.posts_table.insert().execute(title='second',
                                               content='2nd post')
        self.blog.posts_table.insert().execute(title='third', content='3rd')
        self.blog.post_search('second')
        assert_equals(sys.stdout.getvalue().strip(), '2 | second | 2nd post')

    def test_category_add(self):
        self.blog.category_add('my category')
        expected_result = [(1, 'my category')]
        real_result = list(sql.select([self.blog.categories_table]).execute())
        assert_equals(expected_result, real_result)

    def test_category_list(self):
        self.blog.categories_table.insert().execute(name='test category')
        self.blog.category_list()
        expected_result = '1 test category'
        real_result = sys.stdout.getvalue().strip()
        assert_equals(expected_result, real_result)

    def test_category_assign(self):
        self.blog.posts_table.insert().execute(title='test title',
                                               content='test content')
        self.blog.categories_table.insert().execute(name='test category')
        self.blog.category_assign(1, 1)
        expected_result = [(1, 1, 1)]
        real_result = list(
            sql.select([self.blog.categories_posts_table]).execute())
        assert_equals(expected_result, real_result)
        self.blog.category_assign(1, 2)
        assert_equals(sys.stdout.getvalue().strip(),
                      'post or category with given id does not exist')
    def test_repr_one_post(self):
        my_blog = Blog('BlogName', 'BlogAuthor')
        my_blog.posts = ['jeden wesoły post']

        self.assertEqual(my_blog.__repr__(), 'BlogName by BlogAuthor (1 post)')