Beispiel #1
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')))
Beispiel #2
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)
Beispiel #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)
Beispiel #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')))
Beispiel #5
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')))
Beispiel #6
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)
Beispiel #7
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')))
Beispiel #8
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')))
Beispiel #9
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)
Beispiel #10
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))
Beispiel #11
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)))
Beispiel #12
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)
Beispiel #13
0
 def test_when_object_passed_is_none(self):
     with DB.Connect() as cursor:
         self.assertFalse(DB.insert_one(cursor, []))
Beispiel #14
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))
Beispiel #15
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))
Beispiel #16
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')))
Beispiel #17
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))
Beispiel #18
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)