File: sqlite_temp_db_test.py

package info (click to toggle)
golang-github-google-certificate-transparency 0.0~git20160709.0.0f6e3d1~ds1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 5,676 kB
  • sloc: cpp: 35,278; python: 11,838; java: 1,911; sh: 1,885; makefile: 950; xml: 520; ansic: 225
file content (52 lines) | stat: -rwxr-xr-x 1,718 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python

import unittest

import os
import tempfile

from ct.client.db import sqlite_connection as sqlitecon
from ct.client.db import sqlite_temp_db
from ct.client.db import temp_db_test

class SQLiteTempDBTest(unittest.TestCase, temp_db_test.TempDBTest):
    def setUp(self):
        self.database = sqlite_temp_db.SQLiteTempDB(
            sqlitecon.SQLiteConnectionManager(":memory:", keepalive=True))
    def db(self):
        return self.database

class SQLiteTempDBFactoryTest(unittest.TestCase):
    def setUp(self):
        self.database_dir = tempfile.mkdtemp()
        self.factory = sqlite_temp_db.SQLiteTempDBFactory(
            sqlitecon.SQLiteConnectionManager(":memory:", keepalive=True),
            self.database_dir)
        self.temp_stores = set()

    def create_storage(self, name):
        storage = self.factory.create_storage(name)
        self.temp_stores.add(storage.db_name())
        return storage

    def tearDown(self):
        for temp_store in self.temp_stores:
            os.remove(temp_store)
        os.rmdir(self.database_dir)

    def test_create_storage(self):
        temp = self.create_storage("log_server")
        self.assertEqual(self.database_dir, os.path.dirname(temp.db_name()))

    def test_create_storage_creates_unique(self):
        temp1 = self.create_storage("log_server1")
        temp2 = self.create_storage("log_server2")
        self.assertNotEqual(temp1.db_name(), temp2.db_name())

    def test_create_storage_remembers_mapping(self):
        temp = self.create_storage("log_server")
        temp2 = self.create_storage("log_server")
        self.assertEqual(temp.db_name(), temp2.db_name())

if __name__ == '__main__':
    unittest.main()