def test_verify_exist_marks_exist_failed_if_field_mismatch_exception(self): self.mox.StubOutWithMock(datetime, 'datetime') datetime.datetime.utcnow().AndReturn('2014-01-01 01:01:01') self.mox.ReplayAll() exist1 = self.mox.CreateMockAnything() exist2 = self.mox.CreateMockAnything() self.mox.StubOutWithMock(glance_verifier, '_verify_for_usage') self.mox.StubOutWithMock(glance_verifier, '_verify_for_delete') self.mox.StubOutWithMock(glance_verifier, '_verify_validity') field_mismatch_exc = FieldMismatch('field', 'expected', 'actual', 'uuid') glance_verifier._verify_for_usage(exist1).AndRaise( exception=field_mismatch_exc) exist1.mark_failed( reason="Failed at 2014-01-01 01:01:01 UTC for uuid: Expected " "field to be 'expected' got 'actual'") glance_verifier._verify_for_usage(exist2) glance_verifier._verify_for_delete(exist2) glance_verifier._verify_validity(exist2) exist2.mark_verified() self.mox.ReplayAll() verified, exist = glance_verifier._verify([exist1, exist2]) self.mox.VerifyAll() self.assertFalse(verified)
def test_verify_exist_marks_exist_failed_if_field_mismatch_exception(self): utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05') exist1 = self.mox.CreateMockAnything() exist2 = self.mox.CreateMockAnything() self.mox.StubOutWithMock(glance_verifier, '_verify_for_usage') self.mox.StubOutWithMock(glance_verifier, '_verify_for_delete') self.mox.StubOutWithMock(glance_verifier, '_verify_validity') entity_1 = {'name': 'exists', 'value': 'expected'} entity_2 = {'name': 'launches', 'value': 'actual'} field_mismatch_exc = FieldMismatch('field', entity_1, entity_2, 'uuid') glance_verifier._verify_for_usage(exist1).AndRaise( exception=field_mismatch_exc) exist1.mark_failed( reason="Failed at 2014-01-02 03:04:05 UTC for uuid: Data mismatch " "for 'field' - 'exists' contains 'expected' but 'launches' " "contains 'actual'") glance_verifier._verify_for_usage(exist2) glance_verifier._verify_for_delete(exist2) glance_verifier._verify_validity(exist2) exist2.mark_verified() self.mox.ReplayAll() verified, exist = glance_verifier._verify([exist1, exist2]) self.mox.VerifyAll() self.assertFalse(verified)
def test_should_verify_owner_is_of_type_hex(self): self.mox.StubOutWithMock(datetime, 'datetime') datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05') self.mox.ReplayAll() exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 1234L exist.created_at = decimal.Decimal('5.1') exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a" exist.owner = "3762854cd6f6435998188d5120e4c271,kl" self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except WrongTypeException as wt: self.assertEqual(wt.field_name, 'owner') self.assertEqual( wt.reason, "Failed at 2014-01-02 03:04:05 UTC for " "58fb036d-5ef8-47a8-b503-7571276c400a: " "{owner: 3762854cd6f6435998188d5120e4c271,kl} was of " "incorrect type for exist id 23") self.mox.VerifyAll()
def test_verify_exist_marks_exist_failed_if_field_mismatch_exception(self): utils.mock_datetime_utcnow(self.mox, "2014-01-02 03:04:05") exist1 = self.mox.CreateMockAnything() exist2 = self.mox.CreateMockAnything() self.mox.StubOutWithMock(glance_verifier, "_verify_for_usage") self.mox.StubOutWithMock(glance_verifier, "_verify_for_delete") self.mox.StubOutWithMock(glance_verifier, "_verify_validity") entity_1 = {"name": "exists", "value": "expected"} entity_2 = {"name": "launches", "value": "actual"} field_mismatch_exc = FieldMismatch("field", entity_1, entity_2, "uuid") glance_verifier._verify_for_usage(exist1).AndRaise(exception=field_mismatch_exc) exist1.mark_failed( reason="Failed at 2014-01-02 03:04:05 UTC for uuid: Data mismatch " "for 'field' - 'exists' contains 'expected' but 'launches' " "contains 'actual'" ) glance_verifier._verify_for_usage(exist2) glance_verifier._verify_for_delete(exist2) glance_verifier._verify_validity(exist2) exist2.mark_verified() self.mox.ReplayAll() verified, exist = glance_verifier._verify([exist1, exist2]) self.mox.VerifyAll() self.assertFalse(verified)
def test_verify_exist_marks_exist_failed_if_field_mismatch_exception(self): mock_logger = self._setup_mock_logger() self.mox.StubOutWithMock(mock_logger, 'info') mock_logger.exception("glance: Expected field to be 'expected' " "got 'actual'") exist1 = self.mox.CreateMockAnything() exist2 = self.mox.CreateMockAnything() self.mox.StubOutWithMock(glance_verifier, '_verify_for_usage') self.mox.StubOutWithMock(glance_verifier, '_verify_for_delete') self.mox.StubOutWithMock(glance_verifier, '_verify_validity') field_mismatch_exc = FieldMismatch('field', 'expected', 'actual') glance_verifier._verify_for_usage(exist1).AndRaise( exception=field_mismatch_exc) exist1.mark_failed(reason='FieldMismatch') glance_verifier._verify_for_usage(exist2) glance_verifier._verify_for_delete(exist2) glance_verifier._verify_validity(exist2) exist2.mark_verified() self.mox.ReplayAll() verified, exist = glance_verifier._verify([exist1, exist2]) self.mox.VerifyAll() self.assertFalse(verified)
def test_should_verify_correctly_for_all_non_null_and_valid_types(self): exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 983040L exist.created_at = decimal.Decimal("5.1") exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a" exist.owner = "3762854cd6f6435998188d5120e4c271" self.mox.ReplayAll() glance_verifier._verify_validity(exist) self.mox.VerifyAll()
def test_should_verify_correctly_for_all_non_null_and_valid_types(self): exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 983040L exist.created_at = decimal.Decimal('5.1') exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a" exist.owner = "3762854cd6f6435998188d5120e4c271" self.mox.ReplayAll() glance_verifier._verify_validity(exist) self.mox.VerifyAll()
def test_should_verify_image_size_is_of_type_decimal(self): exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 'size' exist.created_at = decimal.Decimal('5.1') exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a" self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except WrongTypeException as wt: self.assertEqual(wt.field_name, 'size') self.assertEqual(wt.reason, "{ size : size } of incorrect type for exist id 23") self.mox.VerifyAll()
def test_should_verify_that_uuid_value_is_uuid_like(self): exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 'size' exist.created_at = decimal.Decimal('5.1') exist.uuid = "asdfe-fgh" self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except WrongTypeException as wt: self.assertEqual(wt.field_name, 'uuid') self.assertEqual(wt.reason, "{ uuid : asdfe-fgh } of incorrect type for exist id 23") self.mox.VerifyAll()
def test_should_verify_that_uuid_in_exist_is_not_null(self): exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 'size' exist.created_at = decimal.Decimal('5.1') exist.uuid = None self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except NullFieldException as nf: self.assertEqual(nf.field_name, 'uuid') self.assertEqual(nf.reason, "uuid field was null for exist id 23") self.mox.VerifyAll()
def test_verify_should_verify_exists_for_usage_and_delete(self): exist = self.mox.CreateMockAnything() self.mox.StubOutWithMock(glance_verifier, '_verify_for_usage') glance_verifier._verify_for_usage(exist) self.mox.StubOutWithMock(glance_verifier, '_verify_for_delete') glance_verifier._verify_for_delete(exist) self.mox.StubOutWithMock(glance_verifier, '_verify_validity') glance_verifier._verify_validity(exist) exist.mark_verified() self.mox.ReplayAll() verified, exist = glance_verifier._verify(exist) self.mox.VerifyAll() self.assertTrue(verified)
def test_should_verify_owner_is_of_type_hex(self): exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 1234L exist.created_at = decimal.Decimal('5.1') exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a" exist.owner = "3762854cd6f6435998188d5120e4c271,kl" self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except WrongTypeException as wt: self.assertEqual(wt.field_name, 'owner') self.assertEqual(wt.reason, "{ owner : 3762854cd6f6435998188d5120e4c271,kl } of incorrect type for exist id 23") self.mox.VerifyAll()
def test_verify_should_verify_exists_for_usage_and_delete(self): exist1 = self.mox.CreateMockAnything() exist2 = self.mox.CreateMockAnything() self.mox.StubOutWithMock(glance_verifier, '_verify_for_usage') self.mox.StubOutWithMock(glance_verifier, '_verify_for_delete') self.mox.StubOutWithMock(glance_verifier, '_verify_validity') for exist in [exist1, exist2]: glance_verifier._verify_for_usage(exist) glance_verifier._verify_for_delete(exist) glance_verifier._verify_validity(exist) exist.mark_verified() self.mox.ReplayAll() verified, exist = glance_verifier._verify([exist1, exist2]) self.mox.VerifyAll() self.assertTrue(verified)
def test_verify_should_verify_exists_for_usage_and_delete(self): exist1 = self.mox.CreateMockAnything() exist2 = self.mox.CreateMockAnything() self.mox.StubOutWithMock(glance_verifier, "_verify_for_usage") self.mox.StubOutWithMock(glance_verifier, "_verify_for_delete") self.mox.StubOutWithMock(glance_verifier, "_verify_validity") for exist in [exist1, exist2]: glance_verifier._verify_for_usage(exist) glance_verifier._verify_for_delete(exist) glance_verifier._verify_validity(exist) exist.mark_verified() self.mox.ReplayAll() verified, exist = glance_verifier._verify([exist1, exist2]) self.mox.VerifyAll() self.assertTrue(verified)
def test_should_verify_that_uuid_in_exist_is_not_null(self): utils.mock_datetime_utcnow(self.mox, '2014-01-01 01:02:03') exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 'size' exist.created_at = decimal.Decimal('5.1') exist.uuid = None self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except NullFieldException as nf: self.assertEqual(nf.field_name, 'uuid') self.assertEqual( nf.reason, "Failed at 2014-01-01 01:02:03 UTC for None: " "uuid field was null for exist id 23") self.mox.VerifyAll()
def test_should_verify_that_uuid_in_exist_is_not_null(self): utils.mock_datetime_utcnow(self.mox, "2014-01-01 01:02:03") exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = "size" exist.created_at = decimal.Decimal("5.1") exist.uuid = None self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except NullFieldException as nf: self.assertEqual(nf.field_name, "uuid") self.assertEqual( nf.reason, "Failed at 2014-01-01 01:02:03 UTC for None: " "uuid field was null for exist id 23" ) self.mox.VerifyAll()
def test_should_verify_that_image_size_in_exist_is_not_null(self): utils.mock_datetime_utcnow(self.mox, '2014-01-02 03:04:05') exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = None exist.created_at = decimal.Decimal('5.1') exist.uuid = IMAGE_UUID_1 self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except NullFieldException as nf: self.assertEqual(nf.field_name, 'image_size') self.assertEqual( nf.reason, "Failed at 2014-01-02 03:04:05 UTC for " "%s: image_size field was " "null for exist id 23" % IMAGE_UUID_1) self.mox.VerifyAll()
def test_should_verify_that_created_at_in_exist_is_not_null(self): utils.mock_datetime_utcnow(self.mox, '2014-01-01 01:02:03') exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 'size' exist.created_at = None exist.uuid = IMAGE_UUID_1 self.mox.ReplayAll() with self.assertRaises(NullFieldException) as nfe: glance_verifier._verify_validity(exist) exception = nfe.exception self.assertEqual(exception.field_name, 'created_at') self.assertEqual(exception.reason, "Failed at 2014-01-01 01:02:03 UTC for " "%s: created_at " "field was null for exist id 23" % IMAGE_UUID_1) self.mox.VerifyAll()
def test_should_verify_that_owner_in_exist_is_not_null(self): utils.mock_datetime_utcnow(self.mox, '2014-01-01 01:02:03') exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 1234 exist.created_at = decimal.Decimal('5.1') exist.uuid = IMAGE_UUID_1 exist.owner = None self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except NullFieldException as nf: self.assertEqual(nf.field_name, 'owner') self.assertEqual( nf.reason, "Failed at 2014-01-01 01:02:03 UTC for " "12345678-6352-4dbc-8271-96cc54bf14cd: owner field was null " "for exist id 23") self.mox.VerifyAll()
def test_should_verify_that_uuid_value_is_uuid_like(self): self.mox.StubOutWithMock(datetime, 'datetime') datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05') self.mox.ReplayAll() exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 'size' exist.created_at = decimal.Decimal('5.1') exist.uuid = "asdfe-fgh" self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except WrongTypeException as wt: self.assertEqual(wt.field_name, 'uuid') self.assertEqual( wt.reason, "Failed at 2014-01-02 03:04:05 UTC for None: " "{uuid: asdfe-fgh} was of incorrect type for exist id 23") self.mox.VerifyAll()
def test_should_verify_that_uuid_in_exist_is_not_null(self): self.mox.StubOutWithMock(datetime, 'datetime') datetime.datetime.utcnow().AndReturn('2014-01-01 01:02:03') self.mox.ReplayAll() exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 'size' exist.created_at = decimal.Decimal('5.1') exist.uuid = None self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except NullFieldException as nf: self.assertEqual(nf.field_name, 'uuid') self.assertEqual( nf.reason, "Failed at 2014-01-01 01:02:03 UTC for None: " "uuid field was null for exist id 23") self.mox.VerifyAll()
def test_should_verify_that_created_at_in_exist_is_not_null(self): utils.mock_datetime_utcnow(self.mox, "2014-01-01 01:02:03") exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = "size" exist.created_at = None exist.uuid = IMAGE_UUID_1 self.mox.ReplayAll() with self.assertRaises(NullFieldException) as nfe: glance_verifier._verify_validity(exist) exception = nfe.exception self.assertEqual(exception.field_name, "created_at") self.assertEqual( exception.reason, "Failed at 2014-01-01 01:02:03 UTC for " "12345678-6352-4dbc-8271-96cc54bf14cd: created_at " "field was null for exist id 23", ) self.mox.VerifyAll()
def test_should_verify_that_owner_in_exist_is_not_null(self): self.mox.StubOutWithMock(datetime, 'datetime') datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05') self.mox.ReplayAll() exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 1234 exist.created_at = decimal.Decimal('5.1') exist.uuid = '1234-5678-9012-3456' exist.owner = None self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except NullFieldException as nf: self.assertEqual(nf.field_name, 'owner') self.assertEqual( nf.reason, "Failed at 2014-01-02 03:04:05 UTC for " "1234-5678-9012-3456: owner field was null for exist id 23") self.mox.VerifyAll()
def test_should_verify_that_created_at_in_exist_is_not_null(self): self.mox.StubOutWithMock(datetime, 'datetime') datetime.datetime.utcnow().AndReturn('2014-01-01 01:02:03') self.mox.ReplayAll() exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 'size' exist.created_at = None exist.uuid = '1234-5678-9012-3456' self.mox.ReplayAll() with self.assertRaises(NullFieldException) as nfe: glance_verifier._verify_validity(exist) exception = nfe.exception self.assertEqual(exception.field_name, 'created_at') self.assertEqual( exception.reason, "Failed at 2014-01-01 01:02:03 UTC for " "1234-5678-9012-3456: created_at field was " "null for exist id 23") self.mox.VerifyAll()
def test_should_verify_that_created_at_in_exist_is_not_null(self): self.mox.StubOutWithMock(datetime, 'datetime') datetime.datetime.utcnow().AndReturn('2014-01-01 01:02:03') self.mox.ReplayAll() exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 'size' exist.created_at = None exist.uuid = '1234-5678-9012-3456' self.mox.ReplayAll() with self.assertRaises(NullFieldException) as nfe: glance_verifier._verify_validity(exist) exception = nfe.exception self.assertEqual(exception.field_name, 'created_at') self.assertEqual(exception.reason, "Failed at 2014-01-01 01:02:03 UTC for " "1234-5678-9012-3456: created_at field was " "null for exist id 23") self.mox.VerifyAll()
def test_should_verify_that_owner_in_exist_is_not_null(self): utils.mock_datetime_utcnow(self.mox, '2014-01-01 01:02:03') exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 1234 exist.created_at = decimal.Decimal('5.1') exist.uuid = IMAGE_UUID_1 exist.owner = None self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except NullFieldException as nf: self.assertEqual(nf.field_name, 'owner') self.assertEqual( nf.reason, "Failed at 2014-01-01 01:02:03 UTC for " "%s: owner field was null " "for exist id 23" % IMAGE_UUID_1) self.mox.VerifyAll()
def test_should_verify_that_image_size_in_exist_is_not_null(self): utils.mock_datetime_utcnow(self.mox, "2014-01-02 03:04:05") exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = None exist.created_at = decimal.Decimal("5.1") exist.uuid = IMAGE_UUID_1 self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except NullFieldException as nf: self.assertEqual(nf.field_name, "image_size") self.assertEqual( nf.reason, "Failed at 2014-01-02 03:04:05 UTC for " "12345678-6352-4dbc-8271-96cc54bf14cd: image_size field was " "null for exist id 23", ) self.mox.VerifyAll()
def test_should_verify_image_size_is_of_type_decimal(self): self.mox.StubOutWithMock(datetime, 'datetime') datetime.datetime.utcnow().AndReturn('2014-01-02 03:04:05') self.mox.ReplayAll() exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = 'random' exist.created_at = decimal.Decimal('5.1') exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a" self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except WrongTypeException as wt: self.assertEqual(wt.field_name, 'size') self.assertEqual( wt.reason, "Failed at 2014-01-02 03:04:05 UTC for " "58fb036d-5ef8-47a8-b503-7571276c400a: {size: random} was " "of incorrect type for exist id 23") self.mox.VerifyAll()
def test_should_verify_created_at_is_decimal(self): self.mox.StubOutWithMock(datetime, "datetime") datetime.datetime.utcnow().AndReturn("2014-01-02 03:04:05") self.mox.ReplayAll() exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = "size" exist.created_at = "123.a" exist.uuid = "58fb036d-5ef8-47a8-b503-7571276c400a" self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except WrongTypeException as wt: self.assertEqual(wt.field_name, "created_at") self.assertEqual( wt.reason, "Failed at 2014-01-02 03:04:05 UTC for " "58fb036d-5ef8-47a8-b503-7571276c400a: {created_at: 123.a} was " "of incorrect type for exist id 23", ) self.mox.VerifyAll()
def test_should_verify_that_image_size_in_exist_is_not_null(self): self.mox.StubOutWithMock(datetime, "datetime") datetime.datetime.utcnow().AndReturn("2014-01-02 03:04:05") self.mox.ReplayAll() exist = self.mox.CreateMockAnything() exist.id = 23 exist.size = None exist.created_at = decimal.Decimal("5.1") exist.uuid = "1234-5678-9012-3456" self.mox.ReplayAll() try: glance_verifier._verify_validity(exist) self.fail() except NullFieldException as nf: self.assertEqual(nf.field_name, "image_size") self.assertEqual( nf.reason, "Failed at 2014-01-02 03:04:05 UTC for " "1234-5678-9012-3456: image_size field was null for " "exist id 23", ) self.mox.VerifyAll()