Factor out plugin running into the Plugin module (along with the includers() handling).
[mailshears.git] / test / rm_account_test.rb
1 require 'pg'
2 require 'test/unit'
3 require 'common/configuration'
4
5 class RmAccountTest < Test::Unit::TestCase
6
7 TESTCONF_PATH = 'test/mailshears.test.conf.yml'
8
9 def connect_superuser()
10 db_host = 'localhost'
11 db_port = 5432
12 db_opts = nil
13 db_tty = nil
14 db_name = 'postgres'
15 db_user = 'postgres'
16 db_pass = nil
17
18 connection = PGconn.connect(db_host,
19 db_port,
20 db_opts,
21 db_tty,
22 db_name,
23 db_user,
24 db_pass)
25
26 return connection
27 end
28
29
30 def test_dummy
31 assert(true)
32 end
33
34 def setup
35 # Create databases using from the test configuration file.
36 cfg = Configuration.new(TESTCONF_PATH)
37 connection = connect_superuser()
38
39 cfg.plugins.each do |plugin|
40 plugin_dbname = cfg.send("#{plugin}_dbname")
41 query = "CREATE DATABASE #{plugin_dbname};"
42 connection.query(query)
43
44 plugin_dbhost = cfg.send("#{plugin}_dbhost")
45 plugin_dbport = cfg.send("#{plugin}_dbport")
46 plugin_dbopts = cfg.send("#{plugin}_dbopts")
47 plugin_dbtty = cfg.send("#{plugin}_dbtty")
48 plugin_dbuser = cfg.send("#{plugin}_dbuser")
49 plugin_dbpass = cfg.send("#{plugin}_dbpass")
50
51 plugin_conn = PGconn.connect(plugin_dbhost,
52 plugin_dbport,
53 plugin_dbopts,
54 plugin_dbtty,
55 plugin_dbname,
56 plugin_dbuser,
57 plugin_dbpass)
58
59 sql = File.open("test/sql/#{plugin}.sql").read()
60 plugin_conn.query(sql)
61 sql = File.open("test/sql/#{plugin}-fixtures.sql").read()
62 plugin_conn.query(sql)
63 plugin_conn.close()
64 end
65
66 connection.close()
67 end
68
69
70 def teardown
71 # Destroy databases using from the test configuration file.
72 cfg = Configuration.new(TESTCONF_PATH)
73 connection = connect_superuser()
74
75 cfg.plugins.each do |plugin|
76 plugin_dbname = cfg.send("#{plugin}_dbname")
77 query = "DROP DATABASE #{plugin_dbname};"
78 connection.query(query)
79 end
80
81 connection.close()
82 end
83
84 end