class ModelForwardZoneTestCase(TestCase): """This class defines the test suite for the ForwardZone model.""" # TODO: test this for sub-zones (sub.example.org) def setUp(self): """Define the test client and other test variables.""" self.zone_sample = ForwardZone(name='example.org', primary_ns='ns.example.org', email='*****@*****.**', serialno=1234567890, refresh=400, retry=300, expire=800, ttl=300) def test_model_can_create_a_zone(self): """Test that the model is able to create a zone.""" old_count = ForwardZone.objects.count() clean_and_save(self.zone_sample) new_count = ForwardZone.objects.count() self.assertNotEqual(old_count, new_count) def test_model_can_change_a_zone(self): """Test that the model is able to change a zone.""" clean_and_save(self.zone_sample) old_name = self.zone_sample.name new_name = 'example.com' zone_sample_id = ForwardZone.objects.get(name=old_name).id self.zone_sample.name = new_name clean_and_save(self.zone_sample) updated_name = ForwardZone.objects.get(pk=zone_sample_id).name self.assertEqual(new_name, updated_name) def test_model_can_delete_a_zone(self): """Test that the model is able to delete a zone.""" clean_and_save(self.zone_sample) old_count = ForwardZone.objects.count() self.zone_sample.delete() new_count = ForwardZone.objects.count() self.assertNotEqual(old_count, new_count)
class ModelForwardZoneTestCase(TestCase): """This class defines the test suite for the ForwardZone model.""" # TODO: test this for sub-zones (sub.example.org) def setUp(self): """Define the test client and other test variables.""" self.zone_sample = ForwardZone(name='example.org', primary_ns='ns.example.org', email='*****@*****.**', serialno=1234567890, refresh=400, retry=300, expire=800, ttl=300) def test_model_can_create_a_zone(self): """Test that the model is able to create a zone.""" old_count = ForwardZone.objects.count() clean_and_save(self.zone_sample) new_count = ForwardZone.objects.count() self.assertNotEqual(old_count, new_count) str(self.zone_sample) def test_model_can_change_a_zone(self): """Test that the model is able to change a zone.""" clean_and_save(self.zone_sample) old_name = self.zone_sample.name new_name = 'example.com' zone_sample_id = ForwardZone.objects.get(name=old_name).id self.zone_sample.name = new_name clean_and_save(self.zone_sample) updated_name = ForwardZone.objects.get(pk=zone_sample_id).name self.assertEqual(new_name, updated_name) def test_model_can_delete_a_zone(self): """Test that the model is able to delete a zone.""" clean_and_save(self.zone_sample) old_count = ForwardZone.objects.count() self.zone_sample.delete() new_count = ForwardZone.objects.count() self.assertNotEqual(old_count, new_count) def test_update_serialno(self): # Force update by setting serialno_updated_at in the past zone = ForwardZone(name='example.org', primary_ns='ns.example.org', email='*****@*****.**') zone.save() zone.serialno_updated_at = timezone.now() - timedelta(minutes=10) old_serial = zone.serialno zone.save() zone.update_serialno() self.assertLess(old_serial, zone.serialno) # Will not update serialno just becase updated = True, requires a timedelta old_serial = zone.serialno self.updated = True zone.update_serialno() zone.save() zone.refresh_from_db() self.assertEqual(old_serial, zone.serialno) self.assertFalse(zone.updated) # Make sure the serialno does not wrap, but instead keeps stays the same zone.serialno += 98 self.assertEqual(zone.serialno % 100, 99) self.updated = True zone.serialno_updated_at = timezone.now() - timedelta(minutes=10) old_serial = zone.serialno zone.update_serialno() self.assertEqual(old_serial, zone.serialno)