コード例 #1
0
 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))
コード例 #2
0
ファイル: test_schema_field.py プロジェクト: vickyonit/rip
    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"))
コード例 #3
0
ファイル: test_schema_field.py プロジェクト: techiev2/rip
    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'))
コード例 #4
0
    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))
コード例 #5
0
    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)
コード例 #6
0
    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))
コード例 #7
0
    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'))
コード例 #8
0
    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))
コード例 #9
0
ファイル: test_schema_field.py プロジェクト: vickyonit/rip
    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"))
コード例 #10
0
ファイル: test_schema_field.py プロジェクト: techiev2/rip
    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'))
コード例 #11
0
    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
コード例 #12
0
 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))
コード例 #13
0
 def testHasAReadableDescription(self):
     self.assert_description("an instance of int", instance_of(int))
コード例 #14
0
 def testDescribeMismatch(self):
     self.assert_describe_mismatch("was 'bad'", instance_of(int), "bad")
コード例 #15
0
 def testMismatchDescriptionShowsActualArgument(self):
     self.assert_mismatch_description("was 'bad'", instance_of(int), "bad")
コード例 #16
0
 def testSuccessfulMatchDoesNotGenerateMismatchDescription(self):
     self.assert_no_mismatch_description(instance_of(int), 3)
コード例 #17
0
 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)
コード例 #18
0
    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)