示例#1
0
class TestDoorConnectionUpdate(unittest.TestCase):
    db_path_local = u'/tmp/test_door_connection_update_local.db'
    db_path_remote = u'/tmp/test_door_connection_update_remote.db'

    def setUp(self):
        self.db_local = sqlite3.connect(self.db_path_local)
        self.member_db_local = MemberDatabase(self.db_local, "?")
        self.member_db_local.create()
        self.db_remote = sqlite3.connect(self.db_path_remote)
        self.member_db_remote = MemberDatabase(self.db_remote, "?")
        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.door_connection = DoorConnection(self.member_db_local,
                                              self.member_db_remote)

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

    def test_update_duplicates(self):
        self.door_connection.update()
        self.assertEqual(len(self.member_db_local.list()), 2)
        self.assertTrue(self.member_db_local.have(b'test_data'))
        self.assertTrue(self.member_db_local.have(b'dope_data'))
示例#2
0
 def test_clear_database(self):
   member_db = MemberDatabase(self.db, "?", "member_table_v")
   member_db.create()
   member_db.add(b'test_data', "John Smith", "*****@*****.**", datetime.now() + timedelta(days = 1))
   member_db.add(b'othe_data', "Crystal Meth", "*****@*****.**", datetime.now() + timedelta(days = 1))
   member_db.clear()
   self.assertEqual(len(member_db.list()), 0)
示例#3
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'))
示例#4
0
 def test_mimic_database(self):
   member_db1 = MemberDatabase(self.db1, "?", "member_table_v")
   member_db1.create()
   member_db1.add(b'test_data', "John Smith", "*****@*****.**", datetime.now() + timedelta(days = 1))
   member_db1.add(b'othe_data', "Crystal Meth", "*****@*****.**", datetime.now() + timedelta(days = 1))
   self.db1.commit()
   #
   member_db2 = MemberDatabase(self.db2, "?", "member_table_v")
   member_db2.create()
   member_db2.mimic(member_db1)
   self.assertEqual(len(member_db2.list()), 2)
示例#5
0
class TestMemberDatabaseAdd(unittest.TestCase):
  db_path = "/tmp/test_member_database_add.db"
  def setUp(self):
    self.db = sqlite3.connect(self.db_path)
    self.member_db = MemberDatabase(self.db, "?", "member_table_v")
    self.member_db.create()
  def tearDown(self):
    # close the connection and delete the object
    self.db.close()
    remove(self.db_path)
  def test_add_member_does_not_fail(self):
    self.member_db.add(b'test_data', "John Smith", "*****@*****.**", datetime.now() + timedelta(days = 1))
示例#6
0
class TestMemberDatabaseList(unittest.TestCase):
  db_path = "/tmp/test_member_database_list.db"
  def setUp(self):
    self.db = sqlite3.connect(self.db_path)
    self.member_db = MemberDatabase(self.db, "?", "member_table_v")
    self.member_db.create()
    self.member_db.add(b'test_data', "John Smith", "*****@*****.**", datetime.now() + timedelta(days = 1))
    self.member_db.add(b'othe_data', "Crystal Meth", "*****@*****.**", datetime.now() + timedelta(days = 1))
  def tearDown(self):
    # close the connection and delete the object
    self.db.close()
    remove(self.db_path)
  def test_list_contains_users(self):
    member_list = self.member_db.list()
    self.assertEqual(len(member_list), 2)
示例#7
0
class TestMemberDatabaseHaveCurrent(unittest.TestCase):
  db_path = "/tmp/test_member_database_add.db"
  def setUp(self):
    self.db = sqlite3.connect(self.db_path)
    self.member_db = MemberDatabase(self.db, "?", "member_table_v")
    self.member_db.create()
    self.member_db.add(b'test_data', "John Smith", "*****@*****.**", datetime.now() + timedelta(days = 1))
  def tearDown(self):
    # close the connection and delete the object
    self.db.close()
    remove(self.db_path)
  def test_checks_member_existence(self):
    self.assertTrue(self.member_db.have_current(b'test_data'))
  def test_checks_member_non_existence(self):
    self.assertFalse(self.member_db.have_current(b'bad_test_data'))
示例#8
0
class TestDoorConnectionCheckRequest(unittest.TestCase):
    db_path_local = u'/tmp/test_door_connection_check_request_local.db'
    db_path_remote = u'/tmp/test_door_connection_check_request_remote.db'

    def setUp(self):
        self.db_local = sqlite3.connect(self.db_path_local)
        self.member_db_local = MemberDatabase(self.db_local, "?")
        self.member_db_local.create()
        self.db_remote = sqlite3.connect(self.db_path_remote)
        self.member_db_remote = MemberDatabase(self.db_remote, u'?')
        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.door_connection = DoorConnection(self.member_db_local,
                                              self.member_db_remote)

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

    def test_remote_verifies(self):
        self.assertTrue(self.door_connection.check_request(b'test_data'))
        self.assertTrue(self.door_connection.check_request(b'dope_data'))

    def test_local_verifies_with_broken_remote(self):
        self.door_connection.update()
        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(self):
        self.assertTrue(self.door_connection.check_request(b'test_data'))
        self.assertTrue(self.door_connection.check_request(b'dope_data'))
        self.db_remote.close()
        self.assertTrue(self.door_connection.check_request(b'test_data'))
        self.assertTrue(self.door_connection.check_request(b'dope_data'))