示例#1
0
 def test_if_everything_is_deleted(self):
     with DB.Connect() as cursor:
         DB.delete_entry(cursor, 1)
         e_ids = DB.get_ids(cursor, 'entry')
         c_ids = DB.get_ids(cursor, 'entry_comment')
     self.assertEqual(0, len(e_ids))
     self.assertEqual(0, len(c_ids))
示例#2
0
 def test_if_date_sorting_works(self):
     with DB.Connect() as cursor:
         self.entry.date = '5.06.2017'
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 2
         self.entry.date = '7.06.2017'
         DB.insert_one(cursor, self.entry)
         self.assertEqual([2, 1], list(DB.get_ids('entry')))
示例#3
0
 def test_when_entry_comment_passed(self):
     self.entry.type_ = 'entry_comment'
     self.entry.entry_id = 321
     with DB.Connect() as cursor:
         self.assertTrue(DB.insert_one(cursor, self.entry))
         db_entry = cursor.execute('SELECT * FROM entry_comment').fetchone()
         self.assertEqual(db_entry, tuple(self.entry))
         self.assertEqual(1, settings.COMMENTS_ADDED)
示例#4
0
 def test_if_ids_correctly_returned_from_entry(self):
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 2
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 3
         DB.insert_one(cursor, self.entry)
         self.assertEqual({1, 2, 3}, set(DB.get_ids(cursor, 'entry')))
示例#5
0
 def setUp(self):
     super().setUp()
     DB.create_new('test')
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 2
         self.entry.entry_id = 1
         self.entry.type_ = 'entry_comment'
         DB.insert_one(cursor, self.entry)
示例#6
0
 def test_if_ids_returned_if_tag_is_matched(self):
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 2
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 3
         self.entry.tags = ' testtag2 '
         DB.insert_one(cursor, self.entry)
         self.assertEqual({1, 2}, set(DB.get_ids(cursor, 'entry', tag='testtag1')))
示例#7
0
 def setUp(self):
     super().setUp()
     DB.create_new('test')
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 2
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 3
         self.entry.tags = ' differenttag '
         DB.insert_one(cursor, self.entry)
示例#8
0
 def test_if_ids_correctly_returned_from_entry_comment(self):
     self.entry.type_ = 'entry_comment'
     self.entry.entry_id = 321
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 2
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 3
         DB.insert_one(cursor, self.entry)
         self.assertEqual({1, 2, 3}, set(DB.get_ids(cursor, 'entry_comment')))
示例#9
0
 def test_if_ids_if_nsfw_filtering_on(self):
     settings.NSFW_FILTER = True
     with DB.Connect() as cursor:
         self.entry.is_nsfw = True
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 2
         self.entry.is_nsfw = True
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 3
         self.entry.is_nsfw = False
         DB.insert_one(cursor, self.entry)
         self.assertEqual({3}, set(DB.get_ids(cursor, 'entry')))
示例#10
0
 def setUp(self):
     super().setUp()
     DB.create_new('test')
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 2
         self.entry.tags = ' testtag2 '
         DB.insert_one(cursor, self.entry)
         for e_id in (1, 2):
             for i in range(1, 4):
                 self.entry.id_ = i + e_id * 4  # fix for different ids
                 self.entry.entry_id = e_id
                 self.entry.type_ = 'entry_comment'
                 DB.insert_one(cursor, self.entry)
示例#11
0
 def test_if_comments_returned(self):
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 1
         self.entry.entry_id = 1
         self.entry.type_ = 'entry_comment'
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 2
         self.entry.entry_id = 1
         self.entry.type_ = 'entry_comment'
         DB.insert_one(cursor, self.entry)
         result = list(DB.get_comments_by_entry_id(cursor, 1))
         self.assertEqual(2, len(result))
     result = list(DB.get_comments_by_entry_id(1))  # called without cursor passed
     self.assertEqual(2, len(result))
示例#12
0
 def test_if_entry_with_comments_returned(self):
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 1
         self.entry.entry_id = 1
         self.entry.type_ = 'entry_comment'
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 2
         self.entry.entry_id = 1
         self.entry.type_ = 'entry_comment'
         DB.insert_one(cursor, self.entry)
         entry = DB.get_entry_with_comments(cursor, 1)
         self.assertEqual(1, entry.id_)
         self.assertEqual(2, len(list(entry.comments)))
     entry = DB.get_entry_with_comments(1)
     self.assertEqual(1, entry.id_)
     self.assertEqual(2, len(list(entry.comments)))
示例#13
0
 def test_when_try_add_entry_already_in_db(self):
     with DB.Connect() as cursor:
         self.assertTrue(DB.insert_one(cursor, self.entry))
         self.assertFalse(DB.insert_one(cursor, self.entry))
示例#14
0
 def test_when_entry_passed(self):
     with DB.Connect() as cursor:
         self.assertTrue(DB.insert_one(cursor, self.entry))
         db_entry = cursor.execute('SELECT * FROM entry').fetchone()
         self.assertEqual(db_entry, tuple(self.entry))
         self.assertEqual(1, settings.ENTRIES_ADDED)
示例#15
0
 def test_if_decorator_works_when_cursor_not_passed(self):
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
         self.entry.id_ = 2
         DB.insert_one(cursor, self.entry)
     self.assertEqual({1, 2}, set(DB.get_ids('entry')))
示例#16
0
 def test_if_row_returned(self):
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
         row = DB.get_entry_row(cursor, 1)
     self.assertEqual(row, tuple(self.entry))
示例#17
0
 def test_when_object_passed_is_none(self):
     with DB.Connect() as cursor:
         self.assertFalse(DB.insert_one(cursor, []))
示例#18
0
 def test_when_id_not_in_db(self):
     with DB.Connect() as cursor:
         row = DB.get_entry_row(cursor, 2)
     self.assertIsNone(row)
示例#19
0
 def test_when_cursor_not_passed(self):
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
     row = DB.get_entry_row(1)
     self.assertEqual(row, tuple(self.entry))
示例#20
0
 def test_if_tag_filter_works(self):
     with DB.Connect() as cursor:
         result = list(DB.get_all_entries_with_comments(cursor, tag='testtag2'))
         self.assertEqual(1, len(result))
示例#21
0
 def test_if_return_is_correct(self):
     with DB.Connect() as cursor:
         result = list(DB.get_all_entries_with_comments(cursor))
         self.assertEqual(2, len(result))
         for entry in result:
             self.assertEqual(3, len(list(entry.comments)))
示例#22
0
 def test_if_comments_not_found(self):
     with DB.Connect() as cursor:
         DB.insert_one(cursor, self.entry)
         result = list(DB.get_comments_by_entry_id(cursor, 1))
         self.assertEqual([], result)