示例#1
0
文件: cli.py 项目: hackprime/yom
    def _run(self):
        action, data, app_hash, opts = self.prepare_data()

        if action == 'scopes':
            return views.list_scopes()

        view = getattr(views, action)

        kwargs = {}
        if action in ('create', 'edit'):
            validator = AppFormValidator(
                new_item=action == 'create', data=data)
            validator.validate()
            kwargs['data'] = validator.cleaned_data()
        if action in ('edit', 'delete', 'detail'):
            app_hash_validator = HashValidator(app_hash)
            app_hash_validator.validate()
            kwargs['app_hash'] = app_hash_validator.cleaned_data()
        if action == 'delete':
            kwargs['confirm'] = opts['confirm']
        # if action == 'dump':
        #     kwargs['json'] = opts['json']

        kwargs['crawler'] = self.init_crawler()

        prepaired_view = self.prepare_view(view)
        context = prepaired_view(**kwargs)
        return context
示例#2
0
def test_hash_validator():
    app_hash = '70fcd16DD04e4f55b07d30021194b6ac'
    validator = Hash(app_hash)
    data_is_valid = validator.validate()
    assert data_is_valid is True
    assert validator.cleaned_data() == app_hash.lower()

    with pytest.raises(YomValidationError):
        assert Hash(None).validate()

    with pytest.raises(YomValidationError):
        assert Hash('70fcd16').validate()

    with pytest.raises(YomValidationError):
        assert Hash(123).validate()

    with pytest.raises(YomValidationError):
        assert Hash('XYZcd16DD04e4f55b07d30021194b6ac').validate()