예제 #1
0
 def test_saved_name(self):
     user = User()
     user.created = timezone.now().strftime('%Y-%m-%d %H:%M:%S')
     user.save()
     category = Category()
     category.name = 'Test category'
     category.user = user
     category.save()
     category_from_DB = get_object_or_404(Category, id=category.id)
     self.assertEqual(category.name, category_from_DB.name)
예제 #2
0
 def test_get_category_name_not_all(self):
     user = User()
     user.created = timezone.now().strftime('%Y-%m-%d %H:%M:%S')
     user.save()
     category = Category()
     category.name = 'Test category'
     category.user = user
     category.save()
     self.assertEqual(
         Category.get_category_name(category.id),
         'Test category'
     )
예제 #3
0
    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)
        )
예제 #4
0
    def test_save_subcategory_name(self):
        user = User()
        user.created = timezone.now().strftime('%Y-%m-%d %H:%M:%S')
        user.save()
        category = Category()
        category.name = 'Test category'
        category.description = ''
        category.user = user
        category.save()
        subcategory = Subcategory()
        subcategory.category = category
        subcategory.name = 'Test subcategory'
        subcategory.save()

        category_from_DB = get_object_or_404(Subcategory, id=subcategory.id)
        self.assertEqual(subcategory.name, 'Test subcategory')
예제 #5
0
    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)
예제 #6
0
    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)
예제 #7
0
    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'
        ])