예제 #1
0
 def test_str(self):
     value = Decimal(random.uniform(-999.99, 999.99))
     expected_name = f"[{str(self.sheet)}] {str(self.category)}: {str(value)}"
     sheet_entry = models.SheetEntry(sheet=self.sheet,
                                     category=self.category,
                                     value=value)
     self.assertEqual(expected_name, sheet_entry.__str__())
예제 #2
0
    def test_value_decimal_places(self):
        expected_value = Decimal('123456789.123')

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

        with self.assertRaises(ValidationError):
            entry.full_clean()
예제 #3
0
    def test_foreign_key_category(self):
        entry = models.SheetEntry(sheet=self.sheet,
                                  category=self.category,
                                  value=0)
        entry.save()

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

        self.assertEqual(self.category, entry_in_db.category)
예제 #4
0
    def test_locked_default_false(self):
        entry = models.SheetEntry(sheet=self.sheet,
                                  category=self.category,
                                  value=Decimal(0))
        entry.full_clean()
        entry.save()

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

        self.assertFalse(entry_in_db.locked)
예제 #5
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
예제 #6
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)
예제 #7
0
    def test_sheet_cascade(self):
        sheet = models.Sheet(month=2, year=1)
        sheet.save()

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

        sheet.delete()

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

        self.assertEqual(0, actual_count)
예제 #8
0
    def test_locked(self):
        expected_lock = bool(random.getrandbits(1))

        entry = models.SheetEntry(sheet=self.sheet,
                                  category=self.category,
                                  value=Decimal(0))
        entry.locked = expected_lock
        entry.full_clean()
        entry.save()

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

        self.assertEqual(expected_lock, entry_in_db.locked)
예제 #9
0
    def test_value_save(self):
        expected_value = (Decimal(random.uniform(-999999999.99,
                                                 999999999.99)).quantize(
                                                     Decimal('.01')))

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

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

        self.assertEqual(expected_value, entry_in_db.value)
예제 #10
0
    def test_locked_no_change_to_value(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)

        entry_in_db.value = Decimal(1)

        with self.assertRaises(ValidationError):
            entry_in_db.full_clean()
예제 #11
0
    def test_locked_no_change_to_sheet(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_sheet = models.Sheet(month=1, year=self.sheet.year + 1)
        new_sheet.save()

        entry_in_db.sheet = new_sheet

        with self.assertRaises(ValidationError):
            entry_in_db.full_clean()