import os.path
import unittest
import test_base

from BackupItemDb import *

class BackupItemDbTest(unittest.TestCase):
	"""
	These tests require a machine to be set up with test databases named test for both mysql and pgsql and to have the correct owners etc
	[[TODO: setup init function where this can all be configured]]
	"""
	
	# WARNING: for this test to work you will need to execute as root
	def testBackupDbPostgres(self):
		if os.name == "posix":
			dbName = "test"
			username = "postgres"
			archiveName = dbName
			outFileName = test_base.getTmpFilePath(dbName + ".sql.gz")
			
			bb = BackupItemDbPgsql(test_base.tmpDirPath, archiveName)
			bb.setDbName(dbName)
			bb.setUserName(username)
			bb.doBackup()
		else:
			pass
	
	def testBackupDbMysql(self):
		if os.name == "posix":
			dbName = "test"
			archiveName  = "mysql_" + dbName
			outFileName = test_base.getTmpFilePath(archiveName + ".sql.gz")
			
			bb = BackupItemDbMysql(test_base.tmpDirPath, archiveName)
			bb.setDbName("test")
			bb.setUserName("root")
			bb.setPassword("penci12")
			bb.doBackup()
		else:
			pass

