class BlueChipUser(RequestPermission):
def check(self, app, environ, start_response):
if 'REMOTE_USER' not in environ:
- raise NotAuthenticatedError('Not Authenticated')
+ raise NotAuthenticatedError('Not Authenticated') # pragma: nocover
environ['user'] = meta.Session.query(model.User).\
filter_by(username=unicode(environ['REMOTE_USER'])).\
first()
if environ['user'] == None:
- raise NotAuthorizedError('You are not allowed access.')
+ raise NotAuthorizedError('You are not allowed access.') # pragma: nocover
return app(environ, start_response)
class DummyAuthenticate(AddDictToEnviron):
from unittest import TestCase
-from bluechips.tests import *
-from bluechips.model.types import Currency
-from decimal import Decimal
+from bluechips.model import types
class TestCurrency(TestCase):
- def test_initInt(self):
- """
- Make sure the constructor for Currency works
- """
- self.assert_(Currency(1) is Currency(1),
- "Currency objects not interned")
- def test_initString(self):
- """
- Make sure the constructor for Currency works with strings
- """
- self.assertEqual(Currency("0.01"), Currency(1))
- self.assert_(Currency("0.01") is Currency(1),
- "string and int constructors return different values")
-
- def test_string(self):
- """
- Test converting a Currency to a string
- """
- self.assertEqual(str(Currency(1)), "$0.01")
- self.assertEqual(str(Currency(100)), "$1.00")
- self.assertEqual(str(Currency(101)), "$1.01")
- self.assertEqual(str(Currency(-1)), "-$0.01")
- self.assertEqual(str(Currency(-100)), "-$1.00")
- self.assertEqual(str(Currency(-101)), "-$1.01")
-
- def test_stringNoDollar(self):
- """
- Test that Currency values can be retrieved without the dollar sign
- """
- self.assertEqual(Currency(1).__str_no_dollar__(), "0.01")
- self.assertEqual(Currency(100).__str_no_dollar__(), "1.00")
- self.assertEqual(Currency(101).__str_no_dollar__(), "1.01")
- self.assertEqual(Currency(-1).__str_no_dollar__(), "-0.01")
- self.assertEqual(Currency(-100).__str_no_dollar__(), "-1.00")
- self.assertEqual(Currency(-101).__str_no_dollar__(), "-1.01")
-
- def test_additionMath(self):
- """
- Confirm that addition works over currency types and ints
- """
- self.assertEqual(Currency(2) + 2, Currency(4))
- self.assertEqual(2 + Currency(2), Currency(4))
- self.assertEqual(Currency(2) + Currency(2), Currency(4))
-
- def test_additionType(self):
- """
- Adding Currencies or a Currency and an int should yield a
- Currency
- """
- self.assertEqual(type(Currency(2) + 2), Currency)
- self.assertEqual(type(2 + Currency(2)), Currency)
- self.assertEqual(type(Currency(2) + Currency(2)), Currency)
-
- def test_multMath(self):
- """
- This test tests the same 3 things as ``test_addition``, but
- for multiplication
- """
- self.assertEqual(Currency(100) * Decimal("0.25"), Currency(25))
- self.assertEqual(Decimal("0.25") * Currency(100), Currency(25))
- self.assertEqual(Currency(10) * Currency(10), Currency(100))
-
- def test_multType(self):
- """
- The result of multiplying a Currency with something else
- should be a currency
- """
- self.assertEqual(type(Currency(100) * Decimal("0.25")), Currency)
- self.assertEqual(type(Decimal("0.25") * Currency(100)), Currency)
- self.assertEqual(type(Currency(100) * Currency(100)), Currency)
+ def setUp(self):
+ self.c = types.Currency('12.34')
+
+ def test_currency_float(self):
+ assert float(self.c) == 1234.
+
+ def test_currency_int(self):
+ val = int(self.c)
+ assert val == 1234
+ assert type(val) == int
+
+ def test_currency_long(self):
+ val = long(self.c)
+ assert val == 1234
+ assert type(val) == long
from unittest import TestCase
from bluechips import model
+from bluechips.model import meta
from bluechips.model.types import Currency
class TestExpenditure(TestCase):
def setUp(self):
- self.u = model.User('chaz', u'Charles Root', False)
- self.e = model.Expenditure(self.u, Currency('445.27'),
+ self.u = model.User(u'chaz', u'Charles Root', False)
+ self.e = model.Expenditure(self.u, Currency('444.88'),
u'chaz buys lunch')
def test_constructor(self):
assert self.e.spender == self.u
- assert self.e.amount == Currency('445.27')
+ assert self.e.amount == Currency('444.88')
assert self.e.description == u'chaz buys lunch'
def test_repr(self):
assert (repr(self.e) ==
- '<Expenditure: spender: Charles Root spent: $445.27>')
+ '<Expenditure: spender: Charles Root spent: $444.88>')
--- /dev/null
+from unittest import TestCase
+from bluechips import model
+from bluechips.model.types import Currency
+
+class TestSplit(TestCase):
+ def setUp(self):
+ self.u = model.User('chaz', u'Charles Root', False)
+ self.e = model.Expenditure(self.u, Currency('12.34'),
+ u'A test expenditure')
+ self.sp = model.Split(self.e, self.u, Currency('5.55'))
+
+ def test_constructor(self):
+ assert self.sp.expenditure == self.e
+ assert self.sp.user == self.u
+ assert self.sp.share == Currency('5.55')
+
+ def test_repr(self):
+ assert (repr(self.sp) == '<Split: expense: %s user: %s share: %s>' %
+ (self.sp.expenditure, self.sp.user, self.sp.share))