def test_verify_for_delete_non_delete_found_deletes(self): exist = self.mox.CreateMockAnything() exist.delete = None exist.instance = INSTANCE_ID_1 exist.launched_at = decimal.Decimal('1.1') exist.deleted_at = None exist.audit_period_ending = decimal.Decimal('1.3') filters = { 'instance': INSTANCE_ID_1, 'launched_at__gte': decimal.Decimal('1.0'), 'launched_at__lte': decimal.Decimal('1.999999'), 'deleted_at__lte': decimal.Decimal('1.3') } results = self.mox.CreateMockAnything() models.InstanceDeletes.objects.filter(**filters).AndReturn(results) results.count().AndReturn(1) self.mox.ReplayAll() try: dbverifier._verify_for_delete(exist) self.fail() except VerificationException, ve: msg = 'Found InstanceDeletes for non-delete exist' self.assertEqual(ve.reason, msg)
def test_verify_for_delete(self): exist = self.mox.CreateMockAnything() exist.delete = self.mox.CreateMockAnything() exist.launched_at = decimal.Decimal('1.1') exist.deleted_at = decimal.Decimal('5.1') exist.delete.launched_at = decimal.Decimal('1.1') exist.delete.deleted_at = decimal.Decimal('5.1') self.mox.ReplayAll() dbverifier._verify_for_delete(exist) self.mox.VerifyAll()
def test_verify_exception_during_delete(self): exist = self.mox.CreateMockAnything() exist.launched_at = decimal.Decimal('1.1') self.mox.StubOutWithMock(dbverifier, '_verify_for_launch') self.mox.StubOutWithMock(dbverifier, '_verify_for_delete') self.mox.StubOutWithMock(dbverifier, '_mark_exist_failed') self.mox.StubOutWithMock(dbverifier, '_mark_exist_verified') dbverifier._verify_for_launch(exist) dbverifier._verify_for_delete(exist).AndRaise(Exception()) dbverifier._mark_exist_failed(exist, reason='Exception') self.mox.ReplayAll() dbverifier._verify(exist) self.mox.VerifyAll()
def test_verify_pass(self): exist = self.mox.CreateMockAnything() exist.launched_at = decimal.Decimal('1.1') self.mox.StubOutWithMock(dbverifier, '_verify_for_launch') self.mox.StubOutWithMock(dbverifier, '_verify_for_delete') self.mox.StubOutWithMock(dbverifier, '_mark_exist_failed') self.mox.StubOutWithMock(dbverifier, '_mark_exist_verified') dbverifier._verify_for_launch(exist) dbverifier._verify_for_delete(exist) dbverifier._mark_exist_verified(exist) self.mox.ReplayAll() dbverifier._verify(exist) self.mox.VerifyAll()
def test_verify_delete_fail(self): exist = self.mox.CreateMockAnything() exist.launched_at = decimal.Decimal('1.1') self.mox.StubOutWithMock(dbverifier, '_verify_for_launch') self.mox.StubOutWithMock(dbverifier, '_verify_for_delete') self.mox.StubOutWithMock(dbverifier, '_mark_exists_failed') self.mox.StubOutWithMock(dbverifier, '_mark_exist_verified') verify_exception = VerificationException('test') dbverifier._verify_for_launch(exist) dbverifier._verify_for_delete(exist).AndRaise(verify_exception) dbverifier._mark_exists_failed(exist) self.mox.ReplayAll() dbverifier._verify(exist) self.mox.VerifyAll()
def test_verify_for_delete_deleted_at_mismatch(self): exist = self.mox.CreateMockAnything() exist.delete = self.mox.CreateMockAnything() exist.launched_at = decimal.Decimal('1.1') exist.deleted_at = decimal.Decimal('5.1') exist.delete.launched_at = decimal.Decimal('1.1') exist.delete.deleted_at = decimal.Decimal('6.1') self.mox.ReplayAll() try: dbverifier._verify_for_delete(exist) self.fail() except FieldMismatch, fm: self.assertEqual(fm.field_name, 'deleted_at') self.assertEqual(fm.expected, decimal.Decimal('5.1')) self.assertEqual(fm.actual, decimal.Decimal('6.1'))
def test_verify_delete_fail(self): exist = self.mox.CreateMockAnything() exist.launched_at = decimal.Decimal('1.1') self.mox.StubOutWithMock(dbverifier, '_verify_for_launch') self.mox.StubOutWithMock(dbverifier, '_verify_for_delete') self.mox.StubOutWithMock(dbverifier, '_mark_exist_failed') self.mox.StubOutWithMock(dbverifier, '_mark_exist_verified') verify_exception = VerificationException('test') dbverifier._verify_for_launch(exist) dbverifier._verify_for_delete(exist).AndRaise(verify_exception) self.mox.StubOutWithMock(dbverifier, '_verify_with_reconciled_data') dbverifier._verify_with_reconciled_data(exist, verify_exception)\ .AndRaise(NotFound('InstanceReconcile', {})) dbverifier._mark_exist_failed(exist, reason='test') self.mox.ReplayAll() result, exists = dbverifier._verify(exist) self.assertFalse(result) self.mox.VerifyAll()
def test_verify_for_delete_non_delete(self): exist = self.mox.CreateMockAnything() exist.delete = None exist.instance = INSTANCE_ID_1 exist.launched_at = decimal.Decimal('1.1') exist.deleted_at = None exist.audit_period_ending = decimal.Decimal('1.1') filters = { 'instance': INSTANCE_ID_1, 'launched_at__gte': decimal.Decimal('1.0'), 'launched_at__lte': decimal.Decimal('1.999999'), 'deleted_at__lte': decimal.Decimal('1.1') } results = self.mox.CreateMockAnything() models.InstanceDeletes.objects.filter(**filters).AndReturn(results) results.count().AndReturn(0) self.mox.ReplayAll() dbverifier._verify_for_delete(exist) self.mox.VerifyAll()
def test_verify_for_delete_found_delete(self): exist = self.mox.CreateMockAnything() exist.delete = None exist.instance = INSTANCE_ID_1 exist.launched_at = decimal.Decimal('1.1') exist.deleted_at = decimal.Decimal('5.1') filters = { 'instance': INSTANCE_ID_1, 'launched_at__gte': decimal.Decimal('1.0'), 'launched_at__lte': decimal.Decimal('1.999999'), } results = self.mox.CreateMockAnything() models.InstanceDeletes.objects.filter(**filters).AndReturn(results) results.count().AndReturn(1) delete = self.mox.CreateMockAnything() delete.launched_at = decimal.Decimal('1.1') delete.deleted_at = decimal.Decimal('5.1') results.__getitem__(0).AndReturn(delete) self.mox.ReplayAll() dbverifier._verify_for_delete(exist) self.mox.VerifyAll()