test_limit.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from django.core import management
  2. from django.db.models import Min
  3. from desecapi.models import Domain, RRset
  4. from desecapi.tests.base import DomainOwnerTestCase
  5. class LimitCommandTest(DomainOwnerTestCase):
  6. def test_update_domains(self):
  7. management.call_command("limit", "domains", self.owner.email, "123")
  8. self.owner.refresh_from_db()
  9. self.assertEqual(self.owner.limit_domains, 123)
  10. management.call_command("limit", "domains", self.owner.email, 567)
  11. self.owner.refresh_from_db()
  12. self.assertEqual(self.owner.limit_domains, 567)
  13. management.call_command(
  14. "limit", "domains", self.owner.email, "1"
  15. ) # below the actual number of domains
  16. self.owner.refresh_from_db()
  17. self.assertEqual(self.owner.limit_domains, 1)
  18. # did not delete domains below limit:
  19. self.assertEqual(Domain.objects.filter(owner_id=self.owner.id).count(), 2)
  20. def test_update_minimum_ttl(self):
  21. management.call_command("limit", "ttl", self.my_domain.name, "123")
  22. self.my_domain.refresh_from_db()
  23. self.assertEqual(self.my_domain.minimum_ttl, 123)
  24. management.call_command("limit", "ttl", self.my_domain.name, 567)
  25. self.my_domain.refresh_from_db()
  26. self.assertEqual(self.my_domain.minimum_ttl, 567)
  27. management.call_command(
  28. "limit", "ttl", self.my_domain.name, "10000"
  29. ) # above the currently used ttl
  30. self.my_domain.refresh_from_db()
  31. self.assertEqual(self.my_domain.minimum_ttl, 10000)
  32. # did not change existing TTLs in violation of minimum TTL:
  33. self.assertLess(
  34. RRset.objects.filter(domain_id=self.my_domain.id).aggregate(Min("ttl"))[
  35. "ttl__min"
  36. ],
  37. 10000,
  38. )