1#!/usr/bin/env python2 2import unittest 3from common.unittests import ConfigTest 4from common.dcfile import * 5from database.postgres import setup_postgres, teardown_postgres 6 7class TestConfigDBPostgres(ConfigTest): 8 @classmethod 9 def setUpClass(cls): 10 setup_postgres(cls) 11 super(TestConfigDBPostgres, cls).setUpClass() 12 13 @classmethod 14 def tearDownClass(cls): 15 super(TestConfigDBPostgres, cls).tearDownClass() 16 teardown_postgres(cls) 17 18 def test_postgres_good(self): 19 config = """\ 20 messagedirector: 21 bind: 127.0.0.1:57123 22 23 general: 24 dc_files: 25 - %r 26 27 roles: 28 - type: database 29 control: 75757 30 broadcast: true 31 generate: 32 min: 1000000 33 max: 1000010 34 backend: 35 type: soci 36 driver: postgresql 37 server: 127.0.0.1:57023 38 username: astron 39 database: astron 40 """ % test_dc 41 self.assertEquals(self.checkConfig(config), 'Valid') 42 43 def test_postgres_reserved_control(self): 44 config = """\ 45 messagedirector: 46 bind: 127.0.0.1:57123 47 general: 48 dc_files: 49 - %r 50 roles: 51 - type: database 52 control: 777 53 generate: 54 min: 1000000 55 max: 1000010 56 backend: 57 type: soci 58 driver: postgresql 59 host: 127.0.0.1 60 port: 57023 61 username: astron 62 database: astron 63 """ % test_dc 64 self.assertEquals(self.checkConfig(config), 'Invalid') 65 66 def test_postgres_invalid_generate(self): 67 config = """\ 68 messagedirector: 69 bind: 127.0.0.1:57123 70 general: 71 dc_files: 72 - %r 73 roles: 74 - type: database 75 control: 75757 76 generate: 77 min: 0 78 max: 1000010 79 backend: 80 type: soci 81 driver: postgresql 82 server: 127.0.0.1:57023 83 username: astron 84 database: astron 85 """ % test_dc 86 self.assertEquals(self.checkConfig(config), 'Invalid') 87 88 config = """\ 89 messagedirector: 90 bind: 127.0.0.1:57123 91 general: 92 dc_files: 93 - %r 94 roles: 95 - type: database 96 control: 75757 97 generate: 98 min: 1000000 99 max: 0 100 backend: 101 type: soci 102 driver: postgresql 103 server: 127.0.0.1:57023 104 username: astron 105 database: astron 106 """ % test_dc 107 self.assertEquals(self.checkConfig(config), 'Invalid') 108 109 def test_postgres_reserved_generate(self): 110 config = """\ 111 messagedirector: 112 bind: 127.0.0.1:57123 113 general: 114 dc_files: 115 - %r 116 roles: 117 - type: database 118 control: 75757 119 generate: 120 min: 444 121 max: 1000010 122 backend: 123 type: soci 124 driver: postgresql 125 server: 127.0.0.1:57023 126 username: astron 127 database: astron 128 """ % test_dc 129 self.assertEquals(self.checkConfig(config), 'Invalid') 130 131 config = """\ 132 messagedirector: 133 bind: 127.0.0.1:57123 134 general: 135 dc_files: 136 - %r 137 roles: 138 - type: database 139 control: 75757 140 generate: 141 min: 1000000 142 max: 555 143 backend: 144 type: soci 145 driver: postgresql 146 server: 127.0.0.1:57023 147 username: astron 148 database: astron 149 """ % test_dc 150 self.assertEquals(self.checkConfig(config), 'Invalid') 151 152 def test_postgres_boolean_broadcast(self): 153 config = """\ 154 messagedirector: 155 bind: 127.0.0.1:57123 156 157 general: 158 dc_files: 159 - %r 160 161 roles: 162 - type: database 163 control: 75757 164 broadcast: TRUE 165 generate: 166 min: 1000000 167 max: 1000010 168 backend: 169 type: soci 170 driver: postgresql 171 server: 127.0.0.1:57023 172 username: astron 173 database: astron 174 """ % test_dc 175 self.assertEquals(self.checkConfig(config), 'Valid') 176 177 config = """\ 178 messagedirector: 179 bind: 127.0.0.1:57123 180 181 general: 182 dc_files: 183 - %r 184 185 roles: 186 - type: database 187 control: 75757 188 broadcast: False 189 generate: 190 min: 1000000 191 max: 1000010 192 backend: 193 type: soci 194 driver: postgresql 195 server: 127.0.0.1:57023 196 username: astron 197 database: astron 198 """ % test_dc 199 self.assertEquals(self.checkConfig(config), 'Valid') 200 201 config = """\ 202 messagedirector: 203 bind: 127.0.0.1:57123 204 205 general: 206 dc_files: 207 - %r 208 209 roles: 210 - type: database 211 control: 75757 212 broadcast: 15012 213 generate: 214 min: 1000000 215 max: 1000010 216 backend: 217 type: soci 218 driver: postgresql 219 server: 127.0.0.1:57023 220 username: astron 221 database: astron 222 """ % test_dc 223 self.assertEquals(self.checkConfig(config), 'Invalid') 224 225if __name__ == '__main__': 226 unittest.main() 227