|
| 1 | +from django.db.backends.mysql.client import DatabaseClient |
| 2 | +from django.test import SimpleTestCase |
| 3 | + |
| 4 | + |
| 5 | +class MySqlDbshellCommandTestCase(SimpleTestCase): |
| 6 | + |
| 7 | + def test_fails_with_keyerror_on_incomplete_config(self): |
| 8 | + with self.assertRaises(KeyError): |
| 9 | + self.get_command_line_arguments({}) |
| 10 | + |
| 11 | + def test_basic_params_specified_in_settings(self): |
| 12 | + self.assertEqual( |
| 13 | + ['mysql', '--user=someuser', '--password=somepassword', |
| 14 | + '--host=somehost', '--port=444', 'somedbname'], |
| 15 | + self.get_command_line_arguments({ |
| 16 | + 'NAME': 'somedbname', |
| 17 | + 'USER': 'someuser', |
| 18 | + 'PASSWORD': 'somepassword', |
| 19 | + 'HOST': 'somehost', |
| 20 | + 'PORT': 444, |
| 21 | + 'OPTIONS': {}, |
| 22 | + })) |
| 23 | + |
| 24 | + def test_options_override_settings_proper_values(self): |
| 25 | + settings_port = 444 |
| 26 | + options_port = 555 |
| 27 | + self.assertNotEqual(settings_port, options_port, 'test pre-req') |
| 28 | + self.assertEqual( |
| 29 | + ['mysql', '--user=optionuser', '--password=optionpassword', |
| 30 | + '--host=optionhost', '--port={}'.format(options_port), 'optiondbname'], |
| 31 | + self.get_command_line_arguments({ |
| 32 | + 'NAME': 'settingdbname', |
| 33 | + 'USER': 'settinguser', |
| 34 | + 'PASSWORD': 'settingpassword', |
| 35 | + 'HOST': 'settinghost', |
| 36 | + 'PORT': settings_port, |
| 37 | + 'OPTIONS': { |
| 38 | + 'db': 'optiondbname', |
| 39 | + 'user': 'optionuser', |
| 40 | + 'passwd': 'optionpassword', |
| 41 | + 'host': 'optionhost', |
| 42 | + 'port': options_port, |
| 43 | + }, |
| 44 | + })) |
| 45 | + |
| 46 | + def test_can_connect_using_sockets(self): |
| 47 | + self.assertEqual( |
| 48 | + ['mysql', '--user=someuser', '--password=somepassword', |
| 49 | + '--socket=/path/to/mysql.socket.file', 'somedbname'], |
| 50 | + self.get_command_line_arguments({ |
| 51 | + 'NAME': 'somedbname', |
| 52 | + 'USER': 'someuser', |
| 53 | + 'PASSWORD': 'somepassword', |
| 54 | + 'HOST': '/path/to/mysql.socket.file', |
| 55 | + 'PORT': None, |
| 56 | + 'OPTIONS': {}, |
| 57 | + })) |
| 58 | + |
| 59 | + def test_ssl_certificate_is_added(self): |
| 60 | + self.assertEqual( |
| 61 | + ['mysql', '--user=someuser', '--password=somepassword', |
| 62 | + '--host=somehost', '--port=444', '--ssl-ca=sslca', 'somedbname'], |
| 63 | + self.get_command_line_arguments({ |
| 64 | + 'NAME': 'somedbname', |
| 65 | + 'USER': 'someuser', |
| 66 | + 'PASSWORD': 'somepassword', |
| 67 | + 'HOST': 'somehost', |
| 68 | + 'PORT': 444, |
| 69 | + 'OPTIONS': {'ssl': {'ca': 'sslca'}}, |
| 70 | + })) |
| 71 | + |
| 72 | + def get_command_line_arguments(self, connection_settings): |
| 73 | + return DatabaseClient.settings_to_cmd_args(connection_settings) |
0 commit comments