コード例 #1
0
ファイル: user_tests.py プロジェクト: slavi104/cashtracker
    def test_create_user(self):
        now = timezone.now()
        user = User()
        user.created = now
        user.save()

        self.assertEqual(user, get_object_or_404(User, id=user.id))
コード例 #2
0
ファイル: user_tests.py プロジェクト: slavi104/cashtracker
    def test_register(self):
        user = User()
        params = {'email': '*****@*****.**', 'password_1': 'TESTPASSWORD'}
        user.register(params)

        self.assertEqual(user, get_object_or_404(User, id=user.id))
        self.assertEqual(user.email, '*****@*****.**')
        self.assertNotEqual(user.password, 'TESTPASSWORD')
コード例 #3
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)
コード例 #4
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'
     )
コード例 #5
0
ファイル: report_tests.py プロジェクト: slavi104/cashtracker
    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)
        )
コード例 #6
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')
コード例 #7
0
ファイル: user_tests.py プロジェクト: slavi104/cashtracker
    def test_to_str_for_user(self):
        user = User()
        params = {'email': '*****@*****.**', 'password_1': 'TESTPASSWORD'}
        user.register(params)
        user.first_name = 'John'
        user.last_name = 'John'
        user.save()

        self.assertEqual(str(user), user.first_name + ' ' + user.last_name)
コード例 #8
0
ファイル: payment_tests.py プロジェクト: slavi104/cashtracker
    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)
コード例 #9
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'
        ])