title: Unit-testing on a database
body: <p>I want to do a unit-testing on a database through overriding or mocking without bringing any changes to the database. Is there any simple way to do it?</p>
  
  <pre><code>import sqlite3
  from customer import Customer
  
  class DataChecker:
      def __init__(self):
          self.conn = sqlite3.connect('pos.db')
          self.cursor = self.conn.cursor()
  
      def customer_has_equipment_attached(self, customerID):
          cursor.execute("""SELECT * FROM Customers WHERE ID == ?;""", (customerID,))
          conn.commit()
          customers = cursor.fetchall()
  
          if len(customers) == 0:
              print("Customer ID not found in DB")
              return False
  
          customer = customers[0]
          tmp_customer = Customer(ID=customer[0], Firstname=customer[1], Lastname=customer[2],        
  
          Age=customer[3], Sex=customer[4], Street=customer[5], Zip=customer[6], City=customer[7],  Nationality=customer[8], IMSIPtr=customer[9], IMEIPtr=customer[10], SubscriptionPtr=customer[11], Email=customer[12], Password=customer[13])
  
          # Fetch equipment
          if tmp_customer.IMEIPtr != None:
              cursor.execute("""SELECT * FROM Equipment WHERE ID = ?;""", (tmp_customer.IMEIPtr,))
              conn.commit()
              equipment = cursor.fetchone()
  
              if len(equipment) == 0:
                  print('Customer has equipment ID but ID cant be found in DB.')
                  return False
  
          else:
              print('Customer has no equipment attached to profile.')
              return False
  </code></pre>