# Path: wirecurly/dialplan/context.py
# class Context(object):
#     """A dialplan context"""
#     def __init__(self, name):
#         super(Context, self).__init__()
#         self.name = name
#         self.extensions = []
# 
#     def todict(self):
#         '''
#             Serialize context and its extensions to dicts.
#         '''
#         children = []
#         if self.extensions:
#             for c in self.extensions:
#                 children.append(c.todict())
# 
#         return {'tag': 'context', 'children': children, 'attrs': {'name': self.name}}
#         
#     def addExtension(self, name, continue_=False):
#         '''
#             Add a new extension to the context
#         '''
#         extension = Extension(name, continue_)
#         self.extensions.append(extension)
#         return extension
# 
#     def addAbsExtension(self, name, continue_=False):
#         '''
#             Add a new extension with an absolute condition and return that condition so actions can be added
#         '''
#         extension = Extension(name, continue_)
#         self.extensions.append(extension)
#         c = Condition()
#         extension.addCondition(c)
#         return c


from wirecurly.dialplan.context import Context

def test_context_serialization():
    '''
        Context needs to be properly serialized.
    '''
    ctx = Context(name="test")
    d = ctx.todict()
    assert d['tag'] == 'context', 'Dict is all wrong %s' % d
    assert isinstance(d['children'], list), 'Dict is all wrong %s' % d
    assert len(d['children']) == 0, 'Dict is all wrong %s' % d

def test_context_extension_creation():
    '''
    Test adding extensions to the context.
    '''

# Path: wirecurly/dialplan/context.py
# class Context(object):
#     """A dialplan context"""
#     def __init__(self, name):
#         super(Context, self).__init__()
#         self.name = name
#         self.extensions = []
# 
#     def todict(self):
#         '''
#             Serialize context and its extensions to dicts.
#         '''
#         children = []
#         if self.extensions:
#             for c in self.extensions:
#                 children.append(c.todict())
# 
#         return {'tag': 'context', 'children': children, 'attrs': {'name': self.name}}
#         
#     def addExtension(self, name, continue_=False):
#         '''
#             Add a new extension to the context
#         '''
#         extension = Extension(name, continue_)
#         self.extensions.append(extension)
#         return extension
# 
#     def addAbsExtension(self, name, continue_=False):
#         '''
#             Add a new extension with an absolute condition and return that condition so actions can be added
#         '''
#         extension = Extension(name, continue_)
#         self.extensions.append(extension)
#         c = Condition()
#         extension.addCondition(c)
#         return c


# Path: tests/test_dialplan/test_context.py
from wirecurly.dialplan.context import Context


def test_context_serialization():
    '''
        Context needs to be properly serialized.
    '''
    ctx = Context(name="test")
    d = ctx.todict()
    assert d['tag'] == 'context', 'Dict is all wrong %s' % d
    assert isinstance(d['children'], list), 'Dict is all wrong %s' % d
    assert len(d['children']) == 0, 'Dict is all wrong %s' % d

def test_context_extension_creation():
    '''
    Test adding extensions to the context.
    '''

    ctx = Context(name="test")