Example #1
0
	def executequery (self, query, params = None):
		''' This method executes a given
		query with the passed parameters. If an
		error occurs it is stored as an attribute
		which is accessible from the instance. A successfull
		query is always followed by a database commit and 
		any failures cause an immidiate rollback ''' 

		# Get connection singleton
		connection = CLWConnection()
		# Create a new cursor object.
		cursor = connection.cursor()
		# Reset error
		self.error = None
		# Excute said query
		try:
			if params:
				cursor.execute(query,params)
			else:
				cursor.execute(query)
		except (psycopg2.ProgrammingError, psycopg2.InternalError, psycopg2.DataError), err:
			# An error causes a rollback
			cursor.connection.rollback()
			# Set the error
			self.error = str(err)
Example #2
0
	def setUp(self):
		# Get connection singleton
		connection = CLWConnection(test_db_host, test_db_name, test_db_user,
								   test_db_pass)
		# Create a new cursor object.
		cursor = connection.cursor()

		params = {'mode': 1,
				  'domainname': 'example.co.uk',
				  'newdomainname': None,
				  }
		self.adminmodel = AdminModel()
		self.authmodel = AuthModel()
		self.mailmodel = MailModel()
		self.eximmodel = EximModel()

		domainadded = self.adminmodel.managedomain(params)

		# Create a user		
		params = {'mode': 1,
				  'userid': 'test.a',
				  'password': '******',
				  'home': '/home/mailstore/',
				  'domain': 'example.co.uk',
				  'uid': 1001,
				  'gid': 1001,
				  'status': 1,
				  'typer':'Person',
				  'role':"",
				  'fullname':'Test User', 
				  'notes':None
				  }
		# add the user
		useradded = self.adminmodel.manageuser(params)
		# Check user added
		self.assertNotEqual(useradded, False)