Changeset - 352d16868760
[Not reviewed]
0 2 0
Lance Edgar - 9 years ago 2016-02-27 11:05:34
ledgar@sacfoodcoop.com
Fix some tests.
2 files changed with 19 insertions and 24 deletions:
0 comments (0 inline, 0 general)
rattail/exceptions.py
Show inline comments
 
@@ -26,7 +26,7 @@
 
This module contains all core Rattail exception classes.
 
"""
 

	
 
from __future__ import unicode_literals
 
from __future__ import unicode_literals, absolute_import
 

	
 

	
 
class RattailError(Exception):
 
@@ -34,9 +34,6 @@ class RattailError(Exception):
 
    Base class for all Rattail exceptions.
 
    """
 

	
 
    def __str__(self):
 
        return unicode(self).encode('utf_8')
 

	
 

	
 
class ConfigurationError(RattailError):
 
    """
 
@@ -118,9 +115,6 @@ class PathNotFound(FileOperationError):
 
    def __init__(self, original_error):
 
        self.original_error = original_error
 

	
 
    def __str__(self):
 
        return unicode(self).encode('utf_8')
 

	
 
    def __unicode__(self):
 
        return '{0}: {1}'.format(
 
            self.original_error.__class__.__name__,
 
@@ -138,8 +132,8 @@ class BatchTypeNotFound(BatchError):
 
    def __init__(self, name):
 
        self.name = name
 

	
 
    def __str__(self):
 
        return "Batch type not found: %s" % self.name
 
    def __unicode__(self):
 
        return "Batch type not found: {}".format(self.name)
 

	
 
    
 
class BatchTypeNotSupported(BatchError):
 
@@ -152,8 +146,8 @@ class BatchTypeNotSupported(BatchError):
 
        self.executor = executor
 
        self.batch_type = batch_type
 

	
 
    def __str__(self):
 
        return "Batch type '%s' is not supported by executor: %s" % (
 
    def __unicode__(self):
 
        return "Batch type '{}' is not supported by executor: {}".format(
 
            self.batch_type, repr(self.executor))
 

	
 

	
 
@@ -162,8 +156,8 @@ class BatchExecutorNotFound(BatchError):
 
    def __init__(self, name):
 
        self.name = name
 

	
 
    def __str__(self):
 
        return "Batch executor not found: %s" % self.name
 
    def __unicode__(self):
 
        return "Batch executor not found: {}".format(self.name)
 

	
 
    
 
class LabelPrintingError(Exception):
 
@@ -179,7 +173,7 @@ class PalmError(RattailError):
 

	
 
class PalmClassicDatabaseTypelibNotFound(PalmError):
 

	
 
    def __str__(self):
 
    def __unicode__(self):
 
        return ("The Python module for the Palm Classic Database type library "
 
                "could not be generated.  (Is the HotSync Manager software "
 
                "installed?)")
 
@@ -187,18 +181,18 @@ class PalmClassicDatabaseTypelibNotFound(PalmError):
 

	
 
class PalmConduitManagerNotFound(PalmError):
 

	
 
    def __str__(self):
 
    def __unicode__(self):
 
        return ("The Palm Desktop Conduit Manager could not be instantiated.  "
 
                "(Is the HotSync Manager software installed?)")
 

	
 

	
 
class PalmConduitAlreadyRegistered(PalmError):
 

	
 
    def __str__(self):
 
    def __unicode__(self):
 
        return "The Rattail Palm conduit is already registered."
 

	
 

	
 
class PalmConduitNotRegistered(PalmError):
 

	
 
    def __str__(self):
 
    def __unicode__(self):
 
        return "The Rattail Palm conduit is not registered."
tests/test_commands.py
Show inline comments
 
# -*- 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()
0 comments (0 inline, 0 general)