# Path: fnapy/utils.py
# def extract_text(element, node_name):
#     """Extract the text from the selected node
# 
#     If no text is found, the empty string is returned.
# 
#     """
#     inner_element = find(element, node_name)
#     return inner_element.text if inner_element is not None else ""
# 
# def findall(element, node_name):
#     """A convenient function to look for nodes in the XML
# 
#     >>> nodes = findall(response.element, node_name)
# 
#     """
#     if "/" in node_name:
#         node_name = "//ns:".join(node_name.split("/"))
#     return element.findall(
#         ".//ns:{0}".format(node_name), namespaces={"ns": XHTML_NAMESPACE}
#     )
# 
# def find(element, node_name):
#     """Look for a node in the XML
# 
#     >>> node = find(response.element, node_name)
# 
#     """
#     if "/" in node_name:
#         node_name = "//ns:".join(node_name.split("/"))
#     return element.find(
#         ".//ns:{0}".format(node_name), namespaces={"ns": XHTML_NAMESPACE}
#     )
# 
# class Response(HttpMessage):
#     """A handy class to handle the response"""
# 
#     def __init__(self, content):
#         super(Response, self).__init__(content)
# 
# Path: fnapy/config.py
# XHTML_NAMESPACE = "http://www.fnac.com/schemas/mp-dialog.xsd"


import os
from lxml import etree
from fnapy.utils import extract_text, findall, find, Response
from fnapy.config import XHTML_NAMESPACE

    # The tag should be empty_content
    assert response.tag == 'empty_content'


def parse_xml_file(filename):
    return etree.parse(os.path.join(os.path.dirname(__file__), 'assets',
                                    filename))


def test_response():
    """Response should not crash with an empty string"""
    response = Response(b'')


def test_extract_text():
    """findall should return a list unique elements"""
    messages = parse_xml_file('messages_sample.xml')
    message_elements = messages.getroot().getchildren()
    # All the messages should have a different message_id
    message_ids = [extract_text(message_element, 'message_id') for
                   message_element in message_elements]
    assert len(set(message_ids)) == len(message_ids)


def test_find():
    """find should return an element"""
    messages = parse_xml_file('messages_sample.xml')
    message_id = find(messages, 'message/message_id').text
    first_message = messages.getroot().getchildren()[0]

# Path: fnapy/utils.py
# def extract_text(element, node_name):
#     """Extract the text from the selected node
# 
#     If no text is found, the empty string is returned.
# 
#     """
#     inner_element = find(element, node_name)
#     return inner_element.text if inner_element is not None else ""
# 
# def findall(element, node_name):
#     """A convenient function to look for nodes in the XML
# 
#     >>> nodes = findall(response.element, node_name)
# 
#     """
#     if "/" in node_name:
#         node_name = "//ns:".join(node_name.split("/"))
#     return element.findall(
#         ".//ns:{0}".format(node_name), namespaces={"ns": XHTML_NAMESPACE}
#     )
# 
# def find(element, node_name):
#     """Look for a node in the XML
# 
#     >>> node = find(response.element, node_name)
# 
#     """
#     if "/" in node_name:
#         node_name = "//ns:".join(node_name.split("/"))
#     return element.find(
#         ".//ns:{0}".format(node_name), namespaces={"ns": XHTML_NAMESPACE}
#     )
# 
# class Response(HttpMessage):
#     """A handy class to handle the response"""
# 
#     def __init__(self, content):
#         super(Response, self).__init__(content)
# 
# Path: fnapy/config.py
# XHTML_NAMESPACE = "http://www.fnac.com/schemas/mp-dialog.xsd"


# Path: tests/test_utils.py
import os
from lxml import etree
from fnapy.utils import extract_text, findall, find, Response
from fnapy.config import XHTML_NAMESPACE


    # The tag should be empty_content
    assert response.tag == 'empty_content'


def parse_xml_file(filename):
    return etree.parse(os.path.join(os.path.dirname(__file__), 'assets',
                                    filename))


def test_response():
    """Response should not crash with an empty string"""
    response = Response(b'')


def test_extract_text():
    """findall should return a list unique elements"""
    messages = parse_xml_file('messages_sample.xml')
    message_elements = messages.getroot().getchildren()
    # All the messages should have a different message_id
    message_ids = [extract_text(message_element, 'message_id') for
                   message_element in message_elements]
    assert len(set(message_ids)) == len(message_ids)


def test_find():
    """find should return an element"""
    messages = parse_xml_file('messages_sample.xml')
    message_id = find(messages, 'message/message_id').text
    first_message = messages.getroot().getchildren()[0]

    first_message_id = first_message.find('.//ns:message_id',