Beispiel #1
0
    def test_replace_star(self):
        """Test replace literal with star vars"""
        from aerolito.pattern import replace
        environ = {
            'user_id': 1,
            'globals': {},
            'session': {1: {'stars': ['a', 'b', 'c']}}
        }

        text = 'My name is <star> because <star 1> and <star 2>'
        literal = self.get_stub_literal(text)
        
        result = replace(literal, environ)
        assert result == 'My name is a because b and c'
Beispiel #2
0
    def test_replace_notfound_integer(self):
        """Test replace when key is not found and pattern is an integer"""
        from aerolito.pattern import replace
        environ = {
            'user_id': 1,
            'globals': {},
            'session': {1:{
                'stars': [],
                'locals': {}
            }}
        }

        text = 2
        literal = self.get_stub_literal(text)
        
        result = replace(literal, environ)
        assert result == 2
Beispiel #3
0
    def test_replace_notfound(self):
        """Test replace when key is not found in stars, globals or locals"""
        from aerolito.pattern import replace
        environ = {
            'user_id': 1,
            'globals': {},
            'session': {1:{
                'stars': [],
                'locals': {}
            }}
        }

        text = 'My name is <name>'
        literal = self.get_stub_literal(text)
        
        result = replace(literal, environ)
        assert result == 'My name is '
    def test_replace_star(self):
        """Test replace literal with star vars"""
        from aerolito.pattern import replace
        environ = {
            'user_id': 1,
            'globals': {},
            'session': {
                1: {
                    'stars': ['a', 'b', 'c']
                }
            }
        }

        text = 'My name is <star> because <star 1> and <star 2>'
        literal = self.get_stub_literal(text)

        result = replace(literal, environ)
        assert result == 'My name is a because b and c'
Beispiel #5
0
    def test_replace_globals(self):
        """Test replace literal with globals vars"""
        from aerolito.pattern import replace
        environ = {
            'user_id': 1,
            'globals': {
                'botname': 'chapolin',
                'version': 'v0.1'
            },
            'session': {1:{}}

        }

        text = 'My name is <botname>, <version>'
        literal = self.get_stub_literal(text)
        
        result = replace(literal, environ)
        assert result == 'My name is chapolin, v0.1'
    def test_replace_notfound_integer(self):
        """Test replace when key is not found and pattern is an integer"""
        from aerolito.pattern import replace
        environ = {
            'user_id': 1,
            'globals': {},
            'session': {
                1: {
                    'stars': [],
                    'locals': {}
                }
            }
        }

        text = 2
        literal = self.get_stub_literal(text)

        result = replace(literal, environ)
        assert result == 2
    def test_replace_notfound(self):
        """Test replace when key is not found in stars, globals or locals"""
        from aerolito.pattern import replace
        environ = {
            'user_id': 1,
            'globals': {},
            'session': {
                1: {
                    'stars': [],
                    'locals': {}
                }
            }
        }

        text = 'My name is <name>'
        literal = self.get_stub_literal(text)

        result = replace(literal, environ)
        assert result == 'My name is '
    def test_replace_globals(self):
        """Test replace literal with globals vars"""
        from aerolito.pattern import replace
        environ = {
            'user_id': 1,
            'globals': {
                'botname': 'chapolin',
                'version': 'v0.1'
            },
            'session': {
                1: {}
            }
        }

        text = 'My name is <botname>, <version>'
        literal = self.get_stub_literal(text)

        result = replace(literal, environ)
        assert result == 'My name is chapolin, v0.1'
Beispiel #9
0
    def test_replace_locals(self):
        """Test replace literal with locals vars"""
        from aerolito.pattern import replace
        environ = {
            'user_id': 1,
            'globals': {},
            'session': {1:{
                'stars':[],
                'locals': {
                    'name': 'Renato',
                    'lastname': 'Pereira'
                }
            }}
        }

        text = 'My name is <name> <lastname>'
        literal = self.get_stub_literal(text)
        
        result = replace(literal, environ)
        assert result == 'My name is Renato Pereira'
Beispiel #10
0
    def test_replace_locals(self):
        """Test replace literal with locals vars"""
        from aerolito.pattern import replace
        environ = {
            'user_id': 1,
            'globals': {},
            'session': {
                1: {
                    'stars': [],
                    'locals': {
                        'name': 'Renato',
                        'lastname': 'Pereira'
                    }
                }
            }
        }

        text = 'My name is <name> <lastname>'
        literal = self.get_stub_literal(text)

        result = replace(literal, environ)
        assert result == 'My name is Renato Pereira'