Beispiel #1
0
 def test_use_resource(self):
   cur = self.db1.cursor()
   cur.execute("""
     CREATE TABLE member_table_v (
       hash CHAR(24),
       name TEXT,
       email VARCHAR(254),
       expiration_date DATE,
       resource VARCHAR(255));
   """)
   cur.execute("""
     INSERT INTO member_table_v (hash, name, email, expiration_date, resource) VALUES 
       (
         ?,
         'John Smith',
         '*****@*****.**',
         ?,
         'door'
       ),
       (
         ?,
         'John Smith',
         '*****@*****.**',
         ?,
         'laser'
       ),
       (
         ?,
         'Crystal Meth',
         '*****@*****.**',
         ?,
         'door'
       );
   """,
     (
       MemberDatabase.hash(b'test_data'), 
       datetime.now() + timedelta(days = 1),
       MemberDatabase.hash(b'test_data'), 
       datetime.now() + timedelta(days = 1),
       MemberDatabase.hash(b'othe_data'), 
       datetime.now() + timedelta(days = 1),
     ))
   self.db1.commit()
   # Use laser resource
   member_db1a = MemberDatabase(self.db1, "?", "member_table_v")
   member_db1a.use_resource('laser')
   member_db2 = MemberDatabase(self.db2, "?", "member_table_v")
   member_db2.create()
   member_db2.mimic(member_db1a)
   self.assertTrue(member_db2.have_current(b'test_data'))
   self.assertFalse(member_db2.have_current(b'othe_data'))
   # Use door resource
   member_db1b = MemberDatabase(self.db1, "?", "member_table_v")
   member_db1b.use_resource('door')
   member_db3 = MemberDatabase(self.db3, "?", "member_table_v")
   member_db3.create()
   member_db3.mimic(member_db1b)
   self.assertTrue(member_db3.have_current(b'test_data'))
   self.assertTrue(member_db3.have_current(b'othe_data'))
Beispiel #2
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'))
Beispiel #3
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.assertTrue(member_db2.have_current(b'test_data'))
   self.assertTrue(member_db2.have_current(b'othe_data'))