def test_create_report(self): now = timezone.now() user = User() user.created = now user.save() category = Category() category.name = 'Test category' category.description = '' category.user = user category.save() subcategory = Subcategory() subcategory.name = '' subcategory.category = category subcategory.save() payment = Payment() payment.value = 10 payment.currency = 'EUR' payment.category = category payment.subcategory = subcategory payment.comment = '' payment.date_time = now payment.user = user payment.save() report = Report() report.user = user report.created = now.strftime('%Y-%m-%d %H:%M:%S') report.report_type = 'today' report.report_date = now.strftime('%Y-%m-%d %H:%M:%S') report.start_date = take_date('today') report.end_date = now.strftime('%Y-%m-%d %H:%M:%S') report.currency = 'BGN' report.is_active = 1 report.save() report.url = 'app_cashtracker/reports/{}.pdf'.format(report) report.save() self.assertEqual(report, get_object_or_404(Report, id=report.id)) self.assertEqual(Report.generate_report_pdf(report), report) self.assertEqual(report.category_names(), 'All') self.assertEqual(report.add_category(category), None) self.assertEqual(report.add_payment(payment), None) self.assertEqual(report.fetch_payments(), [payment]) self.assertEqual(Report.fetch_reports(user), [report]) self.assertEqual( str(report), 'Report_from_today_in_BGN_({})'.format(report.id) )
def test_generate_and_fetch_payments(self): category = Category() category.name = 'Test category' category.description = '' category.user = PaymentTests.USER category.save() subcategory = Subcategory() subcategory.name = '' subcategory.category = category subcategory.save() Payment.generate_fake_payments(PaymentTests.USER, 10) payments = Payment.fetch_payments( 'beginning', '0', 'EUR', PaymentTests.USER ) self.assertEqual(len(payments), 10)
def test__create_new_payment(self): user = User() user.created = PaymentTests.NOW user.save() PaymentTests.USER = user category = Category() category.name = 'Test category' category.description = '' category.user = user category.save() PaymentTests.CATEGORY = category subcategory = Subcategory() subcategory.name = '' subcategory.category = category subcategory.save() PaymentTests.SUBCATEGORY = subcategory payment = Payment() payment.value = 10 payment.currency = 'EUR' payment.category = category payment.subcategory = subcategory payment.comment = '' payment.date_time = PaymentTests.NOW payment.user = user payment.save() payment_from_DB = get_object_or_404(Payment, id=payment.id) PaymentTests.PAYMENT = payment_from_DB self.assertEqual(payment, payment_from_DB) self.assertEqual(payment_from_DB.value, 10) self.assertEqual(payment_from_DB.currency, 'EUR') self.assertEqual(payment_from_DB.category, category) self.assertEqual(payment_from_DB.subcategory, subcategory) self.assertEqual(payment_from_DB.comment, '') self.assertEqual(payment_from_DB.user, user)
def test_create_report(self): now = timezone.now() user = User() user.created = now user.save() category = Category() category.name = 'Test category' category.description = '' category.user = user category.save() subcategory = Subcategory() subcategory.name = '' subcategory.category = category subcategory.save() payment = Payment() payment.value = 10 payment.currency = 'EUR' payment.category = category payment.subcategory = subcategory payment.comment = '' payment.date_time = now payment.user = user payment.save() report = Report() report.user = user report.created = now.strftime('%Y-%m-%d %H:%M:%S') report.report_type = 'today' report.report_date = now.strftime('%Y-%m-%d %H:%M:%S') report.start_date = take_date('today') report.end_date = now.strftime('%Y-%m-%d %H:%M:%S') report.currency = 'BGN' report.is_active = 1 report.save() report.url = 'app_cashtracker/reports/{}.pdf'.format(report) report.save() report_pdf = ReportPDF(report) self.assertEqual(len(report_pdf.elements), 0) report_pdf.generate_header() self.assertEqual(len(report_pdf.elements), 5) report_pdf.generate_statistics_data_and_table() self.assertEqual(len(report_pdf.elements), 8) report_pdf.generate_pie_charts() self.assertEqual(len(report_pdf.elements), 9) if len(report_pdf.lc_data) != 0: report_pdf.generate_line_charts() self.assertEqual(len(report_pdf.elements), 10) report_pdf.build_and_save() self.assertEqual(ReportPDF.payments_table_labels, [ 'Date', 'Name', 'Category', 'Subcategory', 'Comment', 'Value' ])