Skip to content

Commit

Permalink
fix tests to run without the MySQLdb driver installed
Browse files Browse the repository at this point in the history
  • Loading branch information
wandenberg committed Jan 3, 2017
1 parent 5648dca commit b8ad2c1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion tests/run_test.py
Expand Up @@ -3,7 +3,7 @@
import os
import sys
from StringIO import StringIO
from mock import patch, Mock
from mock import patch, Mock, MagicMock

class RunTest(unittest.TestCase):

Expand Down Expand Up @@ -233,6 +233,7 @@ def test_it_should_check_if_has_a_default_configuration_file(self, main_mock, ex
self.assertTrue(isinstance(config_used, simple_db_migrate.config.FileConfig))
self.assertEqual('host_on_sample_configuration_filename', config_used.get('database_host'))

@patch.dict('sys.modules', MySQLdb=MagicMock())
@patch.object(simple_db_migrate.main.Main, 'labels', return_value=["v1", "foo", "v3"])
def test_it_should_print_labels_on_database_and_exit(self, labels_mock):
try:
Expand All @@ -242,6 +243,7 @@ def test_it_should_print_labels_on_database_and_exit(self, labels_mock):

self.assertEqual('v1\nfoo\nv3\n\n', sys.stdout.getvalue())

@patch.dict('sys.modules', MySQLdb=MagicMock())
@patch.object(simple_db_migrate.main.Main, 'labels', return_value=[])
def test_it_should_print_none_when_there_are_no_labels_on_database_and_exit(self, labels_mock):
try:
Expand All @@ -251,6 +253,7 @@ def test_it_should_print_none_when_there_are_no_labels_on_database_and_exit(self

self.assertEqual('NONE\n\n', sys.stdout.getvalue())

@patch.dict('sys.modules', MySQLdb=MagicMock())
@patch.object(simple_db_migrate.main.Main, 'last_label', return_value="v3")
def test_it_should_print_last_label_on_database_and_exit(self, last_label_mock):
try:
Expand All @@ -260,6 +263,7 @@ def test_it_should_print_last_label_on_database_and_exit(self, last_label_mock):

self.assertEqual('v3\n\n', sys.stdout.getvalue())

@patch.dict('sys.modules', MySQLdb=MagicMock())
@patch.object(simple_db_migrate.main.Main, 'last_label', return_value=None)
def test_it_should_print_none_as_last_label_when_there_are_no_labels_on_database_and_exit(self, last_label_mock):
try:
Expand All @@ -269,6 +273,7 @@ def test_it_should_print_none_as_last_label_when_there_are_no_labels_on_database

self.assertEqual('NONE\n\n', sys.stdout.getvalue())

@patch.dict('sys.modules', MySQLdb=MagicMock())
def test_it_should_print_error_message_and_exit_when_required_info_is_not_valid(self):
try:
simple_db_migrate.run_from_argv(["--info", "not_valid", "-c", os.path.abspath('sample.conf')])
Expand Down

0 comments on commit b8ad2c1

Please sign in to comment.