示例#1
0
class TestMemberDatabaseDestroy(unittest.TestCase):
  db_path = "/tmp/test_member_database_destroy.db"
  def setUp(self):
    self.db = sqlite3.connect(self.db_path)
    self.member_db = MemberDatabase(self.db, "?", "member_table_v")
  def tearDown(self):
    # close the connection and delete the object
    self.db.close()
    remove(self.db_path)
  def test_creation_destruction_cycles_work(self):
    # Check that database creation doesn't cause an error
    self.member_db.create()
    self.member_db.destroy()
    self.member_db.create()
    self.member_db.destroy()
示例#2
0
class TestDoorConnectionRecover(unittest.TestCase):
    db_path_local = u'/tmp/test_door_connection_check_recover_local.db'

    def setUp(self):
        config = {}
        with open(u'test_db.json') as config_file:
            config = json.load(config_file)
        self.db_local = sqlite3.connect(self.db_path_local)
        self.member_db_local = None
        self.has_mysql = True
        self.db_remote = None
        self.member_db_remote = None
        self.door_connection = None
        try:
            self.db_remote = mysql.connector.connect(**config)
        except:
            self.has_mysql = False
            print(u'MySQL DB Connection Failure')
        self.member_db_remote = MemberDatabase(self.db_remote, u'%s')
        if self.has_mysql:
            self.member_db_remote.create()
            self.member_db_remote.add(b'test_data', u'John Smith',
                                      u'*****@*****.**',
                                      datetime.now() + timedelta(days=1))
            self.member_db_remote.add(b'dope_data', u'Crystal Meth',
                                      u'*****@*****.**',
                                      datetime.now() + timedelta(days=1))
        self.member_db_local = MemberDatabase(self.db_local, u'?')
        self.member_db_local.create()
        self.door_connection = DoorConnection(self.member_db_local,
                                              self.member_db_remote)

    def tearDown(self):
        self.db_local.close()
        remove(self.db_path_local)

    def test_mysql_remote_verifies(self):
        if self.has_mysql:
            self.assertTrue(self.door_connection.check_request(b'test_data'))
            self.assertTrue(self.door_connection.check_request(b'dope_data'))
            self.member_db_remote.destroy()
            self.db_remote.close()

    def test_local_verifies_with_broken_mysql_remote(self):
        if self.has_mysql:
            self.door_connection.update()
            self.member_db_remote.destroy()
            self.db_remote.close()
            self.assertTrue(self.door_connection.check_request(b'test_data'))
            self.assertTrue(self.door_connection.check_request(b'dope_data'))

    def test_checking_syncs_mysql(self):
        if self.has_mysql:
            self.assertTrue(self.door_connection.check_request(b'test_data'))
            self.assertTrue(self.door_connection.check_request(b'dope_data'))
            self.member_db_remote.destroy()
            self.db_remote.close()
            self.assertTrue(self.door_connection.check_request(b'test_data'))
            self.assertTrue(self.door_connection.check_request(b'dope_data'))