def test_good_validation(self): tokens = [nupay.Token(), nupay.Token()] with self.session_manager.create_session() as session: session.add_tokens(tokens) with self.session_manager.create_session() as session: credit = session.validate_tokens(tokens) self.assertEqual(credit, Decimal('1'))
def test_create(self): token1 = nupay.Token() token_string = token1.token token2 = nupay.Token(token_string) self.assertEqual(token2, token1) token3 = nupay.Token() self.assertNotEqual(token3, token1)
def test_good_cash(self): tokens = [nupay.Token(), nupay.Token(), nupay.Token(), nupay.Token()] with self.session_manager.create_session() as session: session.add_tokens(tokens) with self.session_manager.create_session() as session: session.validate_tokens(tokens) session.cash(Decimal(2.0)) self.assertEqual(Decimal(2.0), session.total) self.assertEqual(Decimal(0), session.credit)
def test_bad_cash(self): tokens = [nupay.Token(), nupay.Token(), nupay.Token(), nupay.Token()] with self.session_manager.create_session() as session: session.add_tokens(tokens) with self.session_manager.create_session() as session: session.validate_tokens(tokens) self.assertRaises(nupay.NotEnoughCreditError, session.cash, Decimal(2.1)) self.assertEqual(0, session.total) self.assertEqual(Decimal(2), session.credit)
def test_good_cash_split(self): tokens = [nupay.Token(), nupay.Token(), nupay.Token(), nupay.Token()] with self.session_manager.create_session() as session: session.add_tokens(tokens) with self.session_manager.create_session() as session: session.validate_tokens(tokens) session.cash(Decimal(1.0)) session.cash(Decimal(0.25)) self.assertRaises(nupay.NotEnoughCreditError, session.cash, Decimal(1.0)) self.assertEqual(Decimal(1.5), session.total) self.assertEqual(Decimal(0.5), session.credit)
def test_rollback(self): tokens = [nupay.Token(), nupay.Token(), nupay.Token(), nupay.Token()] with self.session_manager.create_session() as session: session.add_tokens(tokens) with self.session_manager.create_session() as session: session.validate_tokens(tokens) session.cash(Decimal(1.0)) session.cash(Decimal(0.25)) session.rollback() self.assertRaises(nupay.RollbackError, session.rollback) session.cash(Decimal(1.0)) self.assertRaises(nupay.NotEnoughCreditError, session.cash, Decimal(1.0)) self.assertEqual(Decimal(2.0), session.total)
def test_hash(self): token = nupay.Token("23fff2f231992957ecf7180d3490ead21b5da8d489b71dd6e59b02a0f563e330%1375901686") self.assertEqual(token.hash, "db891851322ff6b04b993af03fda984f3356f64e34abaf73faf7919cae02c1f38c4cd172f6e71414cc25e7f2c331c2cdc4e176e604a2b16686eb7d528671b513")
def test_validation(self): self.assertRaises(nupay.BadTokenFormatError, nupay.Token, "foobar") nupay.Token("23fff2f231992957ecf7180d3490ead21b5da8d489b71dd6e59b02a0f563e330%1375901686") self.assertRaises(nupay.BadTokenFormatError, nupay.Token, "23fff2f231992957ecf7180d3490ead21b5da8d489b71dd6e59b02a0f563e3300%1375901686") self.assertRaises(nupay.BadTokenFormatError, nupay.Token, "23fff2f231992957ecf7180d3490ead21b5da8d489b71dd6e59b02a0f563e33%1375901686") self.assertRaises(nupay.BadTokenFormatError, nupay.Token, "23fff2f231992957ecf7180d3490ead21b5da8d489b71dd6e59b02a0f563e330%13759016868")
def test_add_token(self): tokens = [nupay.Token(), nupay.Token()] with self.session_manager.create_session() as session: session.add_tokens(tokens)
import ConfigParser import sys import nupay config = ConfigParser.RawConfigParser() config.read(sys.argv[1]) tokens = [] for i in range(int(sys.argv[2])): tokens.append(nupay.Token()) with nupay.SessionManager(config).create_session() as session: session.add_tokens(tokens) for token in tokens: print token