-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
72 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,55 @@ | ||
import unittest | ||
#!/usr/bin/python | ||
# -*- coding: UTF-8 -*- | ||
|
||
import pytest | ||
|
||
from stacosys.db import dao | ||
from stacosys.db import database | ||
|
||
@pytest.fixture | ||
def setup_db(): | ||
database.setup(":memory:") | ||
|
||
|
||
|
||
def test_dao_published(setup_db): | ||
|
||
# test count published | ||
assert 0 == dao.count_published_comments("") | ||
c1 = dao.create_comment("/post1", "Yax", "", "", "Comment 1") | ||
assert 0 == dao.count_published_comments("") | ||
dao.publish_comment(c1) | ||
assert 1 == dao.count_published_comments("") | ||
c2 = dao.create_comment("/post2", "Yax", "", "", "Comment 2") | ||
dao.publish_comment(c2) | ||
assert 2 == dao.count_published_comments("") | ||
c3 = dao.create_comment("/post2", "Yax", "", "", "Comment 3") | ||
dao.publish_comment(c3) | ||
assert 1 == dao.count_published_comments("/post1") | ||
assert 2 == dao.count_published_comments("/post2") | ||
|
||
# test find published | ||
assert 0 == len(dao.find_published_comments_by_url("/")) | ||
assert 1 == len(dao.find_published_comments_by_url("/post1")) | ||
assert 2 == len(dao.find_published_comments_by_url("/post2")) | ||
|
||
dao.delete_comment(c1) | ||
assert 0 == len(dao.find_published_comments_by_url("/post1")) | ||
|
||
def test_dao_notified(setup_db): | ||
|
||
# test count notified | ||
assert 0 == len(dao.find_not_notified_comments()) | ||
c1 = dao.create_comment("/post1", "Yax", "", "", "Comment 1") | ||
assert 1 == len(dao.find_not_notified_comments()) | ||
c2 = dao.create_comment("/post2", "Yax", "", "", "Comment 2") | ||
assert 2 == len(dao.find_not_notified_comments()) | ||
dao.notify_comment(c1) | ||
dao.notify_comment(c2) | ||
assert 0 == len(dao.find_not_notified_comments()) | ||
c3 = dao.create_comment("/post2", "Yax", "", "", "Comment 3") | ||
assert 1 == len(dao.find_not_notified_comments()) | ||
dao.notify_comment(c3) | ||
assert 0 == len(dao.find_not_notified_comments()) | ||
|
||
|
||
class DbTestCase(unittest.TestCase): | ||
def setUp(self): | ||
database.setup(":memory:") | ||
|
||
def test_dao_published(self): | ||
|
||
# test count published | ||
self.assertEqual(0, dao.count_published_comments("")) | ||
c1 = dao.create_comment("/post1", "Yax", "", "", "Comment 1") | ||
self.assertEqual(0, dao.count_published_comments("")) | ||
dao.publish_comment(c1) | ||
self.assertEqual(1, dao.count_published_comments("")) | ||
c2 = dao.create_comment("/post2", "Yax", "", "", "Comment 2") | ||
dao.publish_comment(c2) | ||
self.assertEqual(2, dao.count_published_comments("")) | ||
c3 = dao.create_comment("/post2", "Yax", "", "", "Comment 3") | ||
dao.publish_comment(c3) | ||
self.assertEqual(1, dao.count_published_comments("/post1")) | ||
self.assertEqual(2, dao.count_published_comments("/post2")) | ||
|
||
# test find published | ||
self.assertEqual(0, len(dao.find_published_comments_by_url("/"))) | ||
self.assertEqual(1, len(dao.find_published_comments_by_url("/post1"))) | ||
self.assertEqual(2, len(dao.find_published_comments_by_url("/post2"))) | ||
|
||
dao.delete_comment(c1) | ||
self.assertEqual(0, len(dao.find_published_comments_by_url("/post1"))) | ||
|
||
def test_dao_notified(self): | ||
|
||
# test count notified | ||
self.assertEqual(0, len(dao.find_not_notified_comments())) | ||
c1 = dao.create_comment("/post1", "Yax", "", "", "Comment 1") | ||
self.assertEqual(1, len(dao.find_not_notified_comments())) | ||
c2 = dao.create_comment("/post2", "Yax", "", "", "Comment 2") | ||
self.assertEqual(2, len(dao.find_not_notified_comments())) | ||
dao.notify_comment(c1) | ||
dao.notify_comment(c2) | ||
self.assertEqual(0, len(dao.find_not_notified_comments())) | ||
c3 = dao.create_comment("/post2", "Yax", "", "", "Comment 3") | ||
self.assertEqual(1, len(dao.find_not_notified_comments())) | ||
dao.notify_comment(c3) | ||
self.assertEqual(0, len(dao.find_not_notified_comments())) | ||
|
||
|
||
if __name__ == "__main__": | ||
unittest.main() |