Exemplo n.º 1
0
	def setUp(self):
		self.port = Portfolio()	
		self.first_item = Loan()
		self.first_item.balance = 123.321
		self.first_item.minimum_payment = 5
		self.first_item.interest_rate = 2.4
		self.first_item.portfolio = self.port
		self.first_item.save()
		self.second_item = Loan()
		self.second_item.balance = 2345.0
		self.second_item.minimum_payment = 50
		self.second_item.interest_rate = 11.1
		self.second_item.portfolio = self.port
		self.second_item.save()
Exemplo n.º 2
0
def new_portfolio(request):
	balance=request.POST["balance"]
	interest_rate=request.POST["interest_rate"]
	minimum_payment=request.POST["minimum_payment"]
	
	portfolio_ = Portfolio.objects.create()

	chk = Loan(balance=balance, 
				interest_rate=interest_rate, 
				minimum_payment=minimum_payment,
				portfolio = portfolio_)
	chk.save()	
	
	return redirect('/portfolio/%s/'%(portfolio_.id,))
Exemplo n.º 3
0
class LoanCalcTest(TestCase):
	def test_loancalc_url_resolves_to_loancalc_view(self):
		found = resolve('/loancalc/')
		self.assertEqual(found.func, loancalc_page)
		

	def setUp(self):
		self.port = Portfolio()	
		self.first_item = Loan()
		self.first_item.balance = 123.321
		self.first_item.minimum_payment = 5
		self.first_item.interest_rate = 2.4
		self.first_item.portfolio = self.port
		self.first_item.save()
		self.second_item = Loan()
		self.second_item.balance = 2345.0
		self.second_item.minimum_payment = 50
		self.second_item.interest_rate = 11.1
		self.second_item.portfolio = self.port
		self.second_item.save()

	def tearDown(self):
		Loan.objects.all().delete()

	def test_finds_sum_of_loans(self):
		saved_items = Loan.objects.all()
		summary = SummaryStats(saved_items)
		self.assertEqual(summary.total_debt, 123.321 + 2345.0)

	def test_saving_and_retrieving_items(self):
		saved_items = Loan.objects.all()
		self.assertEqual(saved_items.count(), 2)

		first_saved_item = saved_items[0]
		self.assertEqual(first_saved_item.balance, 123.321)
		self.assertEqual(first_saved_item.minimum_payment, 5)
		self.assertEqual(first_saved_item.interest_rate, 2.4)
	

	def test_home_page_returns_correct_html(self):
		request = HttpRequest()
		response = loancalc_page(request)

		self.assertTrue(response.content.strip().startswith(b'<!DOCTYPE html>'),
			"Actual response = %s"%response.content.strip())
		self.assertIn(b'The Loan Calculator', response.content)
		self.assertTrue(response.content.strip().endswith(b'</html>'), 
			"Actual response = %s"%response.content)