def _assert_valid_default_entity(result, identifier="hbp/core/testschema/v0.0.1"): assert_that(result, instance_of(Schema)) assert_that(result.data, not_none()) assert_that(result.get_revision(), greater_than(0)) assert_that(result.id, equal_to(identifier)) assert_that(result.path, equal_to("/schemas/" + identifier))
def test_should_validate(self): field = SchemaField(self.test_schema_cls) request = request_factory.get_request(context_params={"crud_action": CrudActions.UPDATE_DETAIL}) result = field.validate(request, {"name": 1}) assert_that(result, instance_of(ValidationResult)) assert_that(result.is_success, equal_to(False)) assert_that(result.reason, has_entry("name", "Expected type string"))
def test_should_validate(self): field = SchemaField(self.test_schema_cls) request = request_factory.get_request( context_params={'crud_action': CrudActions.UPDATE_DETAIL}) result = field.validate(request, {'name': 1}) assert_that(result, instance_of(ValidationResult)) assert_that(result.is_success, equal_to(False)) assert_that(result.reason, has_entry('name', 'Expected type string'))
def test_get_current_user_settings(self): expected_user_settings = \ UserSettings( magento_store_url='http://localhost/magento/', product_csv_mtime=datetime.utcnow() ) self.__user_settings_service.put_current_user_settings(expected_user_settings) user_settings = self.__user_settings_service.get_current_user_settings() assert_that(user_settings, instance_of(UserSettings))
def test_list_and_resolve_all(self): search = self.repository.list() self._assert_valid_search_list_result(search) assert_that(len(search.results), greater_than(0)) result = self.repository.resolve_all(search) assert_that(result, not_none()) assert_that(result, instance_of(list)) assert_that(len(result), greater_than(0)) self._assert_valid_default_entity(result[0], result[0].id)
def test_get_current_user_settings(self): expected_user_settings = \ UserSettings( magento_store_url='http://localhost/magento/', product_csv_mtime=datetime.utcnow() ) self.__user_settings_service.put_current_user_settings( expected_user_settings) user_settings = self.__user_settings_service.get_current_user_settings( ) assert_that(user_settings, instance_of(UserSettings))
def test_head_product_by_sku(self): if self.__catalog_service is None: return if not self.__read_only: self.__put_products() product_skus = self.__catalog_service.get_product_skus() assert_that(product_skus, has_length(greater_than(0))) for product_sku in product_skus: head = self.__catalog_service.head_product_by_sku(product_sku) assert_that(head, instance_of(bool)) self.assertTrue(head) self.assertFalse(self.__catalog_service.head_product_by_sku('nonextantsku'))
def test_get_product_skus(self): if self.__catalog_service is None: return if not self.__read_only: self.__put_products() product_skus = self.__catalog_service.get_product_skus() assert_that(product_skus, has_length(greater_than(0))) for product_sku in product_skus: assert_that(product_sku, instance_of(basestring)) if not self.__read_only: assert_that(product_skus, equal_to(self.__product_skus))
def test_should_validate_with_overridden_validator(self): class TestValidator(DefaultSchemaValidation): def __init__(self, schema_cls): super(TestValidator, self).__init__(schema_cls) def validate_data(self, data, fields_to_validate=None): return {"name": "Custom Validation Failed"} field = SchemaField(of_type=self.test_schema_cls, validator_cls=TestValidator) result = field.validate(None, {"name": 1}) assert_that(result, instance_of(ValidationResult)) assert_that(result.is_success, equal_to(False)) assert_that(result.reason, has_entry("name", "Custom Validation Failed"))
def test_should_validate_with_overridden_validator(self): class TestValidator(DefaultSchemaValidation): def __init__(self, schema_cls): super(TestValidator, self).__init__(schema_cls) def validate_data(self, data, fields_to_validate=None): return {'name': 'Custom Validation Failed'} field = SchemaField(of_type=self.test_schema_cls, validator_cls=TestValidator) result = field.validate(None, {'name': 1}) assert_that(result, instance_of(ValidationResult)) assert_that(result.is_success, equal_to(False)) assert_that(result.reason, has_entry('name', 'Custom Validation Failed'))
def test_get_product_by_sku(self): if self.__catalog_service is None: return if not self.__read_only: self.__put_products() product_skus = self.__catalog_service.get_product_skus() assert_that(product_skus, has_length(greater_than(0))) for product_sku in product_skus: product = self.__catalog_service.get_product_by_sku(product_sku) assert_that(product, instance_of(Product)) try: self.__catalog_service.get_product_by_sku('nonexitantsku') self.fail() except NoSuchProductException: pass
def _assert_valid_default_entity(result, identifier): assert_that(result, instance_of(Instance)) assert_that(result.data, not_none()) assert_that(result.get_revision(), greater_than(0)) assert_that(result.id, equal_to(identifier)) assert_that(result.path, equal_to("/data/" + identifier))
def testHasAReadableDescription(self): self.assert_description("an instance of int", instance_of(int))
def testDescribeMismatch(self): self.assert_describe_mismatch("was 'bad'", instance_of(int), "bad")
def testMismatchDescriptionShowsActualArgument(self): self.assert_mismatch_description("was 'bad'", instance_of(int), "bad")
def testSuccessfulMatchDoesNotGenerateMismatchDescription(self): self.assert_no_mismatch_description(instance_of(int), 3)
def _assert_valid_search_list_result(search, expected_length=None): assert_that(search, not_none()) assert_that(search, instance_of(SearchResultList)) assert_that(search.results, not_none()) if expected_length is not None: assert_that(len(search.results), expected_length)
def testEvaluatesToTrueIfArgumentIsInstanceOfASpecificClass(self): self.assert_matches("same class", instance_of(int), 1) self.assert_does_not_match("different class", instance_of(int), "hi") self.assert_does_not_match("None", instance_of(int), None)