示例#1
0
    def test_name_save(self):
        category = models.Category()
        category.name = ''.join(
            random.choices(string.ascii_letters + string.digits, k=20))
        category.full_clean()
        category.save()

        category_from_db = models.Category.objects.get(pk=category.pk)

        self.assertEqual(category.name, category_from_db.name)
示例#2
0
def _create_sheet_entry(sheet) -> models.SheetEntry:
    category = models.Category(name=_get_random_name())
    category.save()

    entry = models.SheetEntry()
    entry.sheet = sheet
    entry.value = Decimal(random.uniform(-999.99,
                                         999.99)).quantize(Decimal(".01"))
    entry.category = category
    entry.save()

    return entry
示例#3
0
    def test_category_cascade(self):
        category = models.Category(name="Test")
        category.save()

        entry = models.SheetEntry(sheet=self.sheet, category=category, value=0)
        entry.save()

        category.delete()

        actual_count = models.SheetEntry.objects.filter(pk=entry.pk).count()

        self.assertEqual(0, actual_count)
示例#4
0
    def test_category_prevent_deletion(self):
        category = models.Category(name="Expected category")
        category.save()

        transaction = models.Transaction()
        transaction.partner = "a"
        transaction.date = datetime.date.today()
        transaction.value = 0
        transaction.category = category
        transaction.account = self.account
        transaction.full_clean()
        transaction.save()

        with self.assertRaises(ProtectedError):
            category.delete()
示例#5
0
    def test_category(self):
        expected_category = models.Category(name="Expected category")
        expected_category.save()

        transaction = models.Transaction()
        transaction.partner = "a"
        transaction.date = datetime.date.today()
        transaction.value = 0
        transaction.category = expected_category
        transaction.account = self.account
        transaction.full_clean()
        transaction.save()

        transaction_in_db = models.Transaction.objects.get(pk=transaction.pk)

        self.assertEqual(expected_category, transaction_in_db.category)
示例#6
0
    def test_locked_no_change_to_category(self):
        entry = models.SheetEntry(sheet=self.sheet,
                                  category=self.category,
                                  value=Decimal(0))
        entry.locked = True
        entry.full_clean()
        entry.save()

        entry_in_db = models.SheetEntry.objects.get(pk=entry.pk)

        new_category = models.Category(name=_get_random_name())
        new_category.save()

        entry_in_db.category = new_category

        with self.assertRaises(ValidationError):
            entry_in_db.full_clean()
示例#7
0
    def test_locked_no_change_to_category(self):
        transaction = models.Transaction()
        transaction.locked = True
        transaction.partner = "a"
        transaction.date = datetime.date.today()
        transaction.value = 0
        transaction.category = self.category
        transaction.account = self.account
        transaction.full_clean()
        transaction.save()

        category = models.Category(name=_get_random_name())
        category.save()

        transaction_in_db = models.Transaction.objects.get(pk=transaction.pk)

        transaction_in_db.category = category

        with self.assertRaises(ValidationError):
            transaction_in_db.full_clean()
示例#8
0
def _create_transaction(month,
                        year,
                        account=None,
                        locked=False) -> models.Transaction:
    category = models.Category(name=_get_random_name())
    category.save()
    if account is None:
        account = models.Account(name=_get_random_name(), balance=Decimal(0))
        account.save()

    transaction = models.Transaction()
    transaction.category = category
    transaction.account = account
    transaction.value = Decimal(random.uniform(-999.99, 999.99)).quantize(
        Decimal(".01"))
    transaction.partner = "Test partner"
    transaction.locked = locked
    transaction.date = _random_day_in_month(month, year)

    transaction.save()
    return transaction
示例#9
0
 def setUp(self):
     self.category = models.Category(name="Test")
     self.category.save()
     self.account = models.Account(name="Test", balance=Decimal(0))
     self.account.save()
示例#10
0
 def test_str(self):
     expected_name = _get_random_name()
     category = models.Category(name=expected_name)
     self.assertEqual(expected_name, category.__str__())
示例#11
0
 def test_name_max_length_not_ok(self):
     category = models.Category()
     category.name = ''.join(
         random.choices(string.ascii_letters + string.digits, k=201))
     with self.assertRaises(ValidationError):
         category.full_clean()
示例#12
0
    def setUp(self):
        self.sheet = models.Sheet(month=1, year=1)
        self.sheet.save()

        self.category = models.Category(name=_get_random_name())
        self.category.save()
示例#13
0
def _create_category() -> models.Category:
    category = models.Category(name=_get_random_name())
    category.save()
    return category