Esempio n. 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))
Esempio n. 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')))
Esempio n. 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)
Esempio n. 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')))
Esempio n. 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)
Esempio n. 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')))
Esempio n. 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)
Esempio n. 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')))
Esempio n. 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')))
Esempio n. 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)
Esempio n. 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))
Esempio n. 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)))
Esempio n. 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))
Esempio n. 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)
Esempio n. 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')))
Esempio n. 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))
Esempio n. 17
0
 def test_when_object_passed_is_none(self):
     with DB.Connect() as cursor:
         self.assertFalse(DB.insert_one(cursor, []))
Esempio n. 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)
Esempio n. 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))
Esempio n. 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))
Esempio n. 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)))
Esempio n. 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)