def test_get_decision_get_returns_requirements(self, mock_get_requirements): create_user('user1', 'pass1', 'acc1') mock_requirements = EXAMPLE_REQUIREMENTS mock_get_requirements.return_value = mock_requirements rv = open_with_auth(self.client, '/get_decision', 'get', b'user1', b'pass1') assert json.loads(rv.data) == {'requirements': mock_requirements}
def test_register_existing_user_fails(self): params = ('existing_user', 'bar', 'abcdef') create_user(*params) payload = { k: v for k, v in zip(['username', 'password', 'bank_account'], params) } rv = post_json(self.client, '/register', data=payload) assert b'existing_user' not in rv.data assert rv.status == '400 BAD REQUEST' assert User.query.filter_by(username='******').count() == 1
def register(): if request.method == 'POST': data = request.get_json() try: username = data['username'] password = data['password'] account = data['bank_account'] except KeyError: raise BadRequest() user = create_user(username, password, account) return json.dumps(user.username)
def test_full_decline(self): test_user = create_user('user4', 'pass4', 'acc4') data = { 'basic_questions': { 'first_name': 'Shady', 'last_name': 'McShadyFace', 'date_of_birth': '1994-12-21', }, 'credit_report': { 'score': 1 }, 'company_report': { 'opinion': 'passable' }, } tstamp = datetime(2018, 7, 3, 4, 3, 1) rv = post_json(self.client, '/get_decision', data=data, username=b'user4', password=b'pass4', timestamp=tstamp) assert rv.status == '200 OK' assert Decision.query.filter_by(user_id=test_user.id).count() == 1 decision = Decision.query.filter_by(user_id=test_user.id)[0] expected_object = { 'decision': DECLINED_STATE_NAME, 'datetime': tstamp, 'interest_daily': None, 'amount': None, 'duration_days': None, 'repayment_frequency_days': None, 'fee_rate': None, 'fee_amount': None } for k, v in expected_object.items(): assert getattr(decision, k) == v, k
def setUp(self): super(TestRequestFunding, self).setUp() self.test_user = create_user('user4', 'pass4', 'acc4') self.timestamp = datetime(2018, 4, 5, 15, 5, 5)
def test_full_approve(self): test_user = create_user('user3', 'pass3', 'acc3') data = { 'basic_questions': { 'first_name': 'Trusty', 'last_name': 'McTrustFace', 'date_of_birth': '1974-12-21', }, 'credit_report': { 'score': 1 }, 'company_report': { 'opinion': 'passable' }, } tstamp = datetime(2018, 7, 3, 4, 3, 1) rv = post_json(self.client, '/get_decision', data=data, username=b'user3', password=b'pass3', timestamp=tstamp) assert rv.status == '200 OK' assert Decision.query.filter_by(user_id=test_user.id).count() == 1 decision = Decision.query.filter_by(user_id=test_user.id)[0] expected_object = { 'decision': APPROVED_STATE_NAME, 'datetime': tstamp, 'interest_daily': 0.0005, 'amount': 5000., 'duration_days': 360, 'repayment_frequency_days': 30, 'fee_rate': 0, 'fee_amount': 0 } for k, v in expected_object.items(): assert getattr(decision, k) == v, k expected_response = { 'requirements': EXAMPLE_REQUIREMENTS, 'decision': { 'status': 'Approved', 'reference': str(decision.id), 'product': PRODUCT_NAME, 'amount_min': MIN_LOAN_AMOUNT, 'amount_max': 5000., 'duration': 360, 'interest_type': 'Compound', 'interest': 0.20016, 'fee_flat': 0, 'fee_rate': 0, 'repayment_type': 'Equal Repayment', 'repayment_frequency': '30d', 'valid_until': datetime(2018, 7, 10).date().isoformat(), } } assert json.loads(rv.data) == expected_response
def setUp(self): super(TestLogin, self).setUp() create_user('foo', 'bar', 'baz')
def setUp(self): super(TestGetDecisionPost, self).setUp() self.test_user = create_user('user2', 'pass2', 'acc2')
def test_create_user_returns(self): user = create_user('foo', 'bar', 'baz') self.assertEqual(user.username, 'foo') self.assertNotEqual(user.hashed_password, 'bar') self.assertEqual(user.account, 'baz')
def test_hased_password_matches(self): _ = create_user('foo', 'bar', 'baz') user = User.query.filter_by(username='******').one() self.assertEqual(user.hashed_password, hash_pw('bar', 'foo'))
def test_create_user_saves(self): _ = create_user('foo', 'bar', 'baz') user = User.query.filter_by(username='******').one() self.assertNotEqual(user.hashed_password, 'bar') self.assertEqual(user.account, 'baz')