<commit_before># -*- encoding: utf-8 -*-
from __future__ import unicode_literals

from datetime import date
from decimal import Decimal

from django.core.exceptions import ValidationError
from django.test import TestCase

from .factories import (
    InvoiceFactory,
    InvoiceLineFactory,
    InvoiceSettingsFactory,
)
from invoice.service import (
    InvoiceCreate,
    InvoicePrint,
    InvoiceError,
)


class TestCreditNote(TestCase):

    def _credit_note(self):
        InvoiceSettingsFactory()
        credit_note = InvoiceFactory()
        credit_note.full_clean()
        line = InvoiceLineFactory(
            invoice=credit_note,
            price=Decimal('1.01'),
            quantity=Decimal('-1'),
        )
        line.full_clean()
        return credit_note

    def test_factory(self):
        """ Create a simple credit note."""
        credit_note = InvoiceFactory()
        credit_note.full_clean()
        InvoiceLineFactory(invoice=credit_note, price=Decimal('10.01'))
        line = InvoiceLineFactory(invoice=credit_note, price=Decimal('0.99'))
        line.full_clean()
        self.assertEqual(Decimal('11.00'), credit_note.net)

    def test_no_negative_price(self):
        invoice = InvoiceFactory()
        line = InvoiceLineFactory(invoice=invoice, price=Decimal('-10.01'))
        self.assertRaises(
            ValidationError,
            line.full_clean,
        )

    def test_allow_negative_quantity(self):
        credit_note = self._credit_note()
        self.assertEqual(Decimal('-1.01'), credit_note.net)

    def test_description(self):
        credit_note = self._credit_note()
        self.assertEqual('Credit note', credit_note.description)

    def test_credit_note(self):
        credit = self._credit_note()
        InvoiceCreate().create(credit.user, credit.contact, date.today())

    def test_line_is_credit(self):
        credit = self._credit_note()
        line = InvoiceLineFactory(
            invoice=credit,
            price=Decimal('0.02'),
            quantity=Decimal('-1'),
        )
        self.assertTrue(line.is_credit)

    def test_print_only_negative(self):
        credit = self._credit_note()
        InvoicePrint().create_pdf(credit, None)

    def test_print_only_negative(self):
        credit = self._credit_note()
        line = InvoiceLineFactory(<commit_msg>invoice - all positive, credit - all negative<commit_after># -*- encoding: utf-8 -*-
from __future__ import unicode_literals

from datetime import date
from decimal import Decimal

from django.core.exceptions import ValidationError
from django.test import TestCase

from .factories import (
    InvoiceFactory,
    InvoiceLineFactory,
    InvoiceSettingsFactory,
)
from invoice.service import (
    InvoiceCreate,
    InvoicePrint,
    InvoiceError,
)


class TestCreditNote(TestCase):

    def _credit_note(self):
        InvoiceSettingsFactory()
        credit_note = InvoiceFactory()
        credit_note.full_clean()
        line = InvoiceLineFactory(
            invoice=credit_note,
            price=Decimal('1.01'),
            quantity=Decimal('-1'),
        )
        line.full_clean()
        return credit_note

    def test_factory(self):
        """ Create a simple credit note."""
        credit_note = InvoiceFactory()
        credit_note.full_clean()
        InvoiceLineFactory(invoice=credit_note, price=Decimal('10.01'))
        line = InvoiceLineFactory(invoice=credit_note, price=Decimal('0.99'))
        line.full_clean()
        self.assertEqual(Decimal('11.00'), credit_note.net)

    def test_no_negative_price(self):
        invoice = InvoiceFactory()
        line = InvoiceLineFactory(invoice=invoice, price=Decimal('-10.01'))
        self.assertRaises(
            ValidationError,
            line.full_clean,
        )

    def test_allow_negative_quantity(self):
        credit_note = self._credit_note()
        self.assertEqual(Decimal('-1.01'), credit_note.net)

    def test_description(self):
        credit_note = self._credit_note()
        self.assertEqual('Credit note', credit_note.description)

    def test_credit_note(self):
        credit = self._credit_note()
        InvoiceCreate().create(credit.user, credit.contact, date.today())

    def test_line_is_credit(self):
        credit = self._credit_note()
        line = InvoiceLineFactory(
            invoice=credit,
            price=Decimal('0.02'),
            quantity=Decimal('-1'),
        )
        self.assertTrue(line.is_credit)

    def test_print_only_negative(self):
        credit = self._credit_note()
        InvoicePrint().create_pdf(credit, None)

    def test_print_not_negative_and_positive(self):
        credit = self._credit_note()
        line = InvoiceLineFactory(
{'fraction_non_alphanumeric': 0.10215736040609137, 'fraction_numerical': 0.011421319796954314, 'mean_word_length': 2.8014469453376205, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3083152', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1314, 'n_words': 246}