diff --git a/tests/test_commands.py b/tests/test_commands.py index 73371a27eca81d35fc0e5893bf89c6c7a72c1a70..d1f363566a0fbb3a4fff6a4349bc4df48dd8b8bb 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from __future__ import unicode_literals +from __future__ import unicode_literals, absolute_import import csv import datetime @@ -17,6 +17,7 @@ from sqlalchemy import func from . import DataTestCase from rattail import commands +from rattail.commands.core import ArgumentParser, date_argument from rattail.db import Session from rattail.db import model from rattail.db.auth import authenticate_user @@ -25,7 +26,7 @@ from rattail.db.auth import authenticate_user class TestArgumentParser(TestCase): def test_parse_args_preserves_extra_argv(self): - parser = commands.ArgumentParser() + parser = ArgumentParser() parser.add_argument('--some-optional-arg') parser.add_argument('some_required_arg') args = parser.parse_args([ @@ -39,11 +40,11 @@ class TestArgumentParser(TestCase): class TestDateArgument(TestCase): def test_valid_date_string_returns_date_object(self): - date = commands.date_argument('2014-01-01') + date = date_argument('2014-01-01') self.assertEqual(date, datetime.date(2014, 1, 1)) def test_invalid_date_string_raises_error(self): - self.assertRaises(argparse.ArgumentTypeError, commands.date_argument, 'invalid-date') + self.assertRaises(argparse.ArgumentTypeError, date_argument, 'invalid-date') class TestCommand(TestCase): @@ -184,7 +185,7 @@ class TestAddUser(DataTestCase): def test_no_user_created_if_password_prompt_is_canceled(self): self.assertEqual(self.session.query(model.User).count(), 0) - with patch('rattail.commands.getpass') as getpass: + with patch('rattail.commands.core.getpass') as getpass: getpass.side_effect = KeyboardInterrupt commands.main('adduser', '--no-init', '--stderr', self.stderr_path, 'fred') with open(self.stderr_path) as f: @@ -193,7 +194,7 @@ class TestAddUser(DataTestCase): def test_normal_user_created_with_correct_password_but_no_admin_role(self): self.assertEqual(self.session.query(model.User).count(), 0) - with patch('rattail.commands.getpass') as getpass: + with patch('rattail.commands.core.getpass') as getpass: getpass.return_value = 'fredpass' commands.main('adduser', '--no-init', '--stdout', self.stdout_path, 'fred') with open(self.stdout_path) as f: @@ -206,7 +207,7 @@ class TestAddUser(DataTestCase): def test_admin_user_created_with_administrator_role(self): self.assertEqual(self.session.query(model.User).count(), 0) - with patch('rattail.commands.getpass') as getpass: + with patch('rattail.commands.core.getpass') as getpass: getpass.return_value = 'fredpass' commands.main('adduser', '--no-init', '--stdout', self.stdout_path, 'fred', '--administrator') fred = self.session.query(model.User).one()