'''
phone_communication_backup_coalescer: Test module.

Meant for use with py.test.
Read more here: http://pytest.org/

Copyright 2016, Phillip Green II
Licensed under MIT
'''

import unittest
import os.path
import tempfile
import shutil
import datetime

from phone_communication_backup_coalescer.sms import SmsBackupControl, SMS, MMS, MMSPart, MMSAddress
from phone_communication_backup_coalescer.utils import ParseWarning


class SmsParseFileTestCase(unittest.TestCase):
    def setUp(self):
        self.backup_control = SmsBackupControl()

    def test_contract(self):
        self.assertIsNotNone(self.backup_control.filename_pattern)
        self.assertIsNotNone(self.backup_control.xsl_file_name)
        self.assertIsNotNone(self.backup_control.parse_file)
        self.assertIsNotNone(self.backup_control.tree_seed)
        self.assertIsNotNone(self.backup_control.tree_appender)

    def test_tree_seed_should_initialize_element_tree_with_root_of_smses(self):
        element_tree = self.backup_control.tree_seed()

        self.assertEqual(element_tree.getroot().tag, 'smses')

    def test_tree_seed_should_initialize_element_tree_with_count_of_0(self):
        element_tree = self.backup_control.tree_seed()

        self.assertEqual(element_tree.getroot().get('count'), '0')

    def test_parse_file(self):
        full_file_name = os.path.join('tests', 'data', 'sms-test.xml')
        # warnings are tested in a different test
        smses = filter(lambda x: x['type'] == 'item', self.backup_control.parse_file(full_file_name))

        self.assertEqual(len(smses), 15)
        sms0 = SMS(
            body='Free AT&T msg: Your Authorized user was changed for acct # ending in XXXX. If this was done in error, call 800-331-0500 or 611 from your wireless phone.',
            service_center='+13123149623',
            protocol='0',
            read='1',
            sc_toa='null',
            readable_date='Jul 15, 2013 7:07:22 PM',
            date_sent='1373929642000',
            status='-1',
            address='7535',
            date='1373929642000',
            locked='0',
            contact_name='(Unknown)',
            toa='null',
            type='1',
            subject='null')
        self.assertEqual(smses[0], {'type': 'item', 'value': sms0})
        sms1 = SMS(
            body='Free AT&T msg: Your Authorized user was changed for acct # ending in XXXX. If this was done in error, call 800-331-0500 or 611 from your wireless phone.',
            service_center='+13123149623',
            protocol='0',
            read='1',
            sc_toa='null',
            readable_date='Jul 15, 2013 7:12:55 PM',
            date_sent='1373929975000',
            status='-1',
            address='7535',
            date='1373929975000',
            locked='0',
            contact_name='(Unknown)',
            toa='null',
            type='1',
            subject='null')
        self.assertEqual(smses[1], {'type': 'item', 'value': sms1})
        sms2 = SMS(
            body='This is Phillip',
            service_center='null',
            protocol='0',
            read='1', sc_toa='null',
            readable_date='Jul 15, 2013 10:41:45 PM',
            date_sent='0',
            status='-1',
            address='+15555550000',
            date='1373942505322',
            locked='0',
            contact_name='Jane Smith',
            toa='null',
            type='2',
            subject='null')
        self.assertEqual(smses[2], {'type': 'item', 'value': sms2})
        sms3 = SMS(
            body='G',
            service_center='+13123149619',
            protocol='0',
            read='1',
            sc_toa='null',
            readable_date='Jul 15, 2013 10:42:54 PM',
            date_sent='1373942574000',
            status='-1',
            address='+15555550000',
            date='1373942574000',
            locked='0',
            contact_name='Jane Smith',
            toa='null',
            type='1',
            subject='null')
        self.assertEqual(smses[3], {'type': 'item', 'value': sms3})
        sms4 = SMS(
            body="I'm home",
            service_center='+13123149619',
            protocol='0',
            read='1',
            sc_toa='null',
            readable_date='Jul 15, 2013 11:34:08 PM',
            date_sent='1373945648000',
            status='-1',
            address='+15555550000',
            date='1373945648000',
            locked='0',
            contact_name='Jane Smith',
            toa='null',
            type='1',
            subject='null')
        self.assertEqual(smses[4], {'type': 'item', 'value': sms4})
        sms5 = SMS(
            body='AT&T msg: Your online registration code is: XXXXXXXX. ',
            service_center='+13123149619',
            protocol='0',
            read='1',
            sc_toa='null',
            readable_date='Jul 15, 2013 11:48:19 PM',
            date_sent='1373946499000', status='-1',
            address='7535',
            date='1373946499000',
            locked='0',
            contact_name='(Unknown)',
            toa='null',
            type='1',
            subject='null')
        self.assertEqual(smses[5], {'type': 'item', 'value': sms5})
        sms6 = MMS(
            callback_set='0',
            m_id='103019290470004800008',
            reserved='0',
            creator=None,
            msg_id='0',
            pri='129',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='1',
            contact_name='Ted Turner',
            sub='',
            rr='129',
            text_only='1',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='6',
            resp_st='128',
            msg_box='2',
            readable_date='Oct 30, 2014 3:29:04 PM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report=None,
            deletable='0',
            address='+15555550001',
            date='1414697344000',
            sim_slot=None,
            sim_imsi=None,
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='T14962885023',
            locked='0',
            m_type='128',
            sub_id=None,
            retr_st='null',
            safe_message=None,
            d_tm='null',
            st='null',
            m_cls='personal',
            exp='604800',
            v='18',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='null',
                    seq='-1',
                    cl='smil.xml',
                    text='<smil><head><layout><root-layout width="100px" height="1080px"/><region id="Text" left="0" top="972" width="100px" height="108px" fit="meet"/></layout></head><body><par dur="5000ms"><text src="cid:text_0.txt" region="Text"/></par></body></smil>',
                    cid='<smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='null',
                    seq='0',
                    cl='text_0.txt',
                    text="I'm in",
                    cid='<text_0.txt>',
                    chset='106',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='text/plain')),
            addresses=())
        self.assertEqual(smses[6], {'type': 'item', 'value': sms6})
        sms7 = MMS(
            callback_set='0',
            m_id='69BF9BA8-608D-71E4-AE83-D8D385BFFBCE',
            reserved='0',
            creator=None,
            msg_id='0',
            pri='129',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='0',
            contact_name='Ted Turner',
            sub='null',
            rr='null',
            text_only='1',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='null',
            resp_st='null',
            msg_box='1',
            readable_date='Oct 30, 2014 7:35:24 PM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report=None,
            deletable='0',
            address='+15555550001',
            date='1414712124000',
            sim_slot=None,
            sim_imsi=None,
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='DG1030233524600048000010000',
            locked='0',
            m_type='132',
            sub_id=None,
            retr_st='null',
            safe_message=None,
            d_tm='null',
            st='null',
            m_cls='personal',
            exp='null',
            v='16',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='smil.xml',
                    seq='-1',
                    cl='smil.xml',
                    text='<smil><head><layout><root-layout width="320px" height="480px"/><region id="Image" left="0" top="0" width="320px" height="320px" fit="meet"/><region id="Text" left="0" top="320" width="320px" height="160px" fit="meet"/></layout></head><body><par dur="5000ms"><text src="text_0.txt" region="Text"/></par></body></smil>',
                    cid='<smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='text_0.txt',
                    seq='0',
                    cl='text_0.txt',
                    text="Maybe.  I'm still at work.",
                    cid='<text_0>',
                    chset='106',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='text/plain')),
            addresses=())
        self.assertEqual(smses[7], {'type': 'item', 'value': sms7})
        sms8 = MMS(
            callback_set='0',
            m_id='103122142050001500002',
            reserved='0',
            creator=None,
            msg_id='0',
            pri='129',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='1',
            contact_name='(Unknown)',
            sub='',
            rr='129',
            text_only='1',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='16',
            resp_st='128',
            msg_box='2',
            readable_date='Oct 31, 2014 6:14:13 PM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report=None,
            deletable='0',
            address='lamer000@aol.com',
            date='1414793653000',
            sim_slot=None,
            sim_imsi=None,
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='T1496845e177',
            locked='0',
            m_type='128',
            sub_id=None,
            retr_st='null',
            safe_message=None,
            d_tm='null',
            st='null',
            m_cls='personal',
            exp='604800',
            v='18',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='null',
                    seq='-1',
                    cl='smil.xml',
                    text='<smil><head><layout><root-layout width="100px" height="1080px"/><region id="Text" left="0" top="972" width="100px" height="108px" fit="meet"/></layout></head><body><par dur="5000ms"><text src="cid:text_0.txt" region="Text"/></par></body></smil>',
                    cid='<smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='null',
                    seq='0',
                    cl='text_0.txt',
                    text='Happy Birthday! ',
                    cid='<text_0.txt>',
                    chset='106',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='text/plain')),
            addresses=())
        self.assertEqual(smses[8], {'type': 'item', 'value': sms8})
        sms9 = MMS(
            callback_set='0',
            m_id='F743329A-620A-71E4-BC32-D8D385BCF5CE',
            reserved='0',
            creator=None,
            msg_id='0',
            pri='129',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='1',
            contact_name='Ted Turner',
            sub='null',
            rr='null',
            text_only='0',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='null',
            resp_st='null',
            msg_box='1',
            readable_date='Nov 1, 2014 5:06:43 PM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report=None,
            deletable='0',
            address='+15555550001',
            date='1414876003000',
            sim_slot=None,
            sim_imsi=None,
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='E81101210643700022000000000',
            locked='0',
            m_type='132',
            sub_id=None,
            retr_st='null',
            safe_message=None,
            d_tm='null',
            st='null',
            m_cls='personal',
            exp='null',
            v='16',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='123_1.smil',
                    seq='-1',
                    cl='0.smil',
                    text='<smil>\n<head>\n<layout>\n <root-layout/>\n<region id="Text" top="70%" left="0%" height="30%" width="100%" fit="scroll"/>\n<region id="Image" top="0%" left="0%" height="70%" width="100%" fit="meet"/>\n</layout>\n</head>\n<body>\n<par dur="10s">\n<text src="text_0.txt" region="Text"/>\n</par>\n</body>\n</smil>\n',
                    cid='<0.smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='text_0.txt',
                    seq='0',
                    cl='text_0.txt',
                    text='Mountaineers are making me crazy today. You guys watching? ',
                    cid='<0>',
                    chset='106',
                    cd='attachment',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='text/plain')),
            addresses=())
        self.assertEqual(smses[9], {'type': 'item', 'value': sms9})
        sms10 = MMS(
            callback_set='0',
            m_id='11012127235060700005',
            reserved='0',
            creator=None,
            msg_id='0',
            pri='null',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='1',
            contact_name='Ted Turner',
            sub='null',
            rr='null',
            text_only='0',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='null',
            resp_st='null',
            msg_box='1',
            readable_date='Nov 1, 2014 5:07:28 PM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report=None,
            deletable='0',
            address='+15555550001',
            date='1414876048000',
            sim_slot=None,
            sim_imsi=None,
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='A35101210728200007000050501',
            locked='0',
            m_type='132',
            sub_id=None,
            retr_st='null',
            safe_message=None,
            d_tm='null',
            st='null',
            m_cls='null',
            exp='null',
            v='16',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='null',
                    seq='-1',
                    cl='null',
                    text='<smil>\n<head>\n<layout>\n <root-layout/>\n<region id="Text" top="70%" left="0%" height="30%" width="100%" fit="scroll"/>\n<region id="Image" top="0%" left="0%" height="70%" width="100%" fit="meet"/>\n</layout>\n</head>\n<body>\n<par dur="10s">\n<text src="text_0.txt" region="Text"/>\n</par>\n</body>\n</smil>\n',
                    cid='<0.smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='null',
                    seq='0',
                    cl='text_0.txt',
                    text='Listening ',
                    cid='<0>',
                    chset='3',
                    cd='attachment',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='text/plain')),
            addresses=())
        self.assertEqual(smses[10], {'type': 'item', 'value': sms10})
        sms11 = MMS(
            callback_set='0',
            m_id='110121413160005306005',
            reserved='0',
            creator=None,
            msg_id='0',
            pri='null',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='1',
            contact_name='Ted Turner',
            sub='null',
            rr='null',
            text_only='0',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='null',
            resp_st='null',
            msg_box='1',
            readable_date='Nov 1, 2014 5:41:31 PM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report=None,
            deletable='0',
            address='+15555550001',
            date='1414878091000',
            sim_slot=None,
            sim_imsi=None,
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='D51101214731200053000050001',
            locked='0',
            m_type='132',
            sub_id=None,
            retr_st='null',
            safe_message=None,
            d_tm='null',
            st='null',
            m_cls='null',
            exp='null',
            v='16',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='null',
                    seq='-1',
                    cl='null',
                    text='<smil>\n<head>\n<layout>\n <root-layout/>\n<region id="Text" top="70%" left="0%" height="30%" width="100%" fit="scroll"/>\n<region id="Image" top="0%" left="0%" height="70%" width="100%" fit="meet"/>\n</layout>\n</head>\n<body>\n<par dur="10s">\n<text src="text_0.txt" region="Text"/>\n</par>\n</body>\n</smil>\n',
                    cid='<0.smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='null',
                    seq='0',
                    cl='text_0.txt',
                    text='Remember that warren sapp touchdown dance?',
                    cid='<0>',
                    chset='3',
                    cd='attachment',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='text/plain')),
            addresses=())
        self.assertEqual(smses[11], {'type': 'item', 'value': sms11})
        sms12 = MMS(
            callback_set='0',
            m_id='110121555670002700005',
            reserved='0',
            creator=None,
            msg_id='0',
            pri='null',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='1',
            contact_name='Ted Turner',
            sub='null',
            rr='null',
            text_only='0',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='null',
            resp_st='null',
            msg_box='1',
            readable_date='Nov 1, 2014 5:55:56 PM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report=None,
            deletable='0',
            address='+15555550001',
            date='1414878956000',
            sim_slot=None,
            sim_imsi=None,
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='E91201315556401027000050001',
            locked='0',
            m_type='132',
            sub_id=None,
            retr_st='null',
            safe_message=None,
            d_tm='null',
            st='null',
            m_cls='null',
            exp='null',
            v='16',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='null',
                    seq='-1',
                    cl='null',
                    text='<smil>\n<head>\n<layout>\n <root-layout/>\n<region id="Text" top="70%" left="0%" height="30%" width="100%" fit="scroll"/>\n<region id="Image" top="0%" left="0%" height="70%" width="100%" fit="meet"/>\n</layout>\n</head>\n<body>\n<par dur="10s">\n<text src="text_0.txt" region="Text"/>\n</par>\n</body>\n</smil>\n',
                    cid='<0.smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='null',
                    seq='0',
                    cl='text_0.txt',
                    text='Brad paisley',
                    cid='<0>',
                    chset='3',
                    cd='attachment',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='text/plain')),
            addresses=())
        self.assertEqual(smses[12], {'type': 'item', 'value': sms12})
        # smses[13] through smses[14] handled in separate tests

    def test_parse_file_with_image(self):
        full_file_name = os.path.join('tests', 'data', 'sms-test.xml')
        # warnings are tested in a different test
        smses = filter(lambda x: x['type'] == 'item', self.backup_control.parse_file(full_file_name))

        sms13 = MMS(
            callback_set='0',
            m_id='110213558440201660001',
            reserved='0',
            creator=None,
            msg_id='0',
            pri='129',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='1',
            contact_name='Jane Smith',
            sub='',
            rr='129',
            text_only='0',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='955312',
            resp_st='128',
            msg_box='2',
            readable_date='Nov 2, 2014 8:55:28 AM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report=None,
            deletable='0',
            address='+15555550000',
            date='1414936528000',
            sim_slot=None,
            sim_imsi=None,
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='T14170c8f96c',
            locked='0',
            m_type='128',
            sub_id=None,
            retr_st='null',
            safe_message=None,
            d_tm='null',
            st='null',
            m_cls='personal',
            exp='604800',
            v='18',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='null',
                    seq='-1',
                    cl='smil.xml',
                    text='<smil><head><layout><root-layout width="100px" height="100px"/><region id="Image" left="0" top="0" width="100px" height="100px" fit="meet"/></layout></head><body><par dur="5000ms"><img src="duck.png" region="Image"/></par></body></smil>',
                    cid='<smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='null',
                    seq='0',
                    cl='duck.png',
                    text='null',
                    cid='<duck>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data='iVBORw0KGgoAAAANSUhEUgAAALkAAAB6CAYAAADj0fJGAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABmJLR0QA/wD/AP+gvaeTAAAY3ElEQVR42u2dCXhU1dmAB8G69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OPhTZ3qfobucWO5480epcjofPwpLRcGco72uTNzDtme3HBMv2t+HW5h20vJTuSV3WERTW6rq3JvE9lR6iybyRHX5wDdakZyXtFPyH2n0GTdklFRzimL0+pNLRp3S77M0TwNGjz5rV/67QkkJWoQFw0ip9qDZ1OVkQUshxsdvTUYeOY/GiztyRVkvfd/rjOtyfnsGsVvt83DkP6pwHx/0cHAjQgbD3tevv9DaYfETvSqOFa91hz8gPZX+Wp4LsiBamQsPduYngyXEoF96ZScPzEhhX51lmkt8dsg3E5h1yzms3xlf0erves+rTQujBVIqIvy/ZafUR4qjXQWGtMzd7IXvBK8qoC80TS12O44dgz66BrZnkMhWJ41N9+yrXs7QzdLbMWqe8qpUI5qZLxrDK8f8sJ96FUCo7i+/WLVpgmk14mLdqWrtPfue2Uc16J2JeFV1ex0HinCi4dKJOH8g43eD9Yu938m/4TsnV7rHFfBYZj02F7RsYXlgcP1PjWp+L9dp3zrM1Yb5tKepa0pNrsDN31hSXOjGSFPNro29C76PLKUv2d6/dYl1fEcOPUIa8IaHK5Zps144V5bd8jPURaasKdHPek7aWeFYkKfqTJm5W5yXz/gBBqwie55hl7znvWxDoxxq/bWe5ZtSLf9AQASf+RluL2t9m6W74ssi2t0sSeqcFhzo4y18p3VnXePdz73nkf76ZFGZonVhZYFhzm+j6PFquhkbpa0xUtWsN/Ptzg+WxFvmX+ggzd7yZPlt9AeoO0S5enARiXmW+ZdrTZt3Kkzbt4xC2TBr5Yvc30PA53yJkjjXXt5pvlN7z5seGh1YXWWYUlriVFVe6PDnG9n2wvdS3NKrLMXbrC8PjUqQJSd53i9v9tRRwCGsiViQAAAABJRU5ErkJggg==',
                    fn='duck.png',
                    ct='image/png')),
            addresses=())
        self.assertEqual(smses[13], {'type': 'item', 'value': sms13})

    def test_parse_file_with_multiple_addresses(self):
        full_file_name = os.path.join('tests', 'data', 'sms-test.xml')
        # warnings are tested in a different test
        smses = filter(lambda x: x['type'] == 'item', self.backup_control.parse_file(full_file_name))

        sms14 = MMS(
            callback_set='0',
            m_id='479E1FAE-E4A4-71F4-7B68-A8D385BCA5DE',
            reserved='0',
            creator='null',
            msg_id='0',
            pri='129',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='0',
            contact_name='Ted Turner, Nancy Edgar, Antonio Scott, Max Hall',
            sub='null',
            rr='null',
            text_only='1',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='318',
            resp_st='null',
            msg_box='1',
            readable_date='Apr 16, 2015 9:51:40 PM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report='0',
            deletable='0',
            address='+15555550001~+15555550003~+15555550005~+15555550004',
            date='1429235500000',
            sim_slot='0',
            sim_imsi='null',
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='D90417015140600035000060000',
            locked='0',
            m_type='132',
            sub_id='-1',
            retr_st='null',
            safe_message='0',
            d_tm='null',
            st='null',
            m_cls='personal',
            exp='null',
            v='16',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='123_1.smil',
                    seq='-1',
                    cl='0.smil',
                    text='<smil>\n<head>\n<layout>\n <root-layout/>\n<region id="Text" top="70%" left="0%" height="30%" width="100%" fit="scroll"/>\n<region id="Image" top="0%" left="0%" height="70%" width="100%" fit="meet"/>\n</layout>\n</head>\n<body>\n<par dur="10s">\n<text src="text_0.txt" region="Text"/>\n</par>\n</body>\n</smil>\n',
                    cid='<0.smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='text_0.txt',
                    seq='0',
                    cl='text_0.txt',
                    text='And only let in two.',
                    cid='<0>',
                    chset='106',
                    cd='attachment',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='text/plain')),
            addresses=(
                MMSAddress(
                    charset='106',
                    type='137',
                    address='+15555550005'),
                MMSAddress(
                    charset='106',
                    type='151',
                    address='+15555550004'),
                MMSAddress(
                    charset='106',
                    type='151',
                    address='+15555550003'),
                MMSAddress(
                    charset='106',
                    type='151',
                    address='+15555550002'),
                MMSAddress(
                    charset='106',
                    type='151',
                    address='+15555550001')))
        self.assertEqual(smses[14], {'type': 'item', 'value': sms14})

    def test_parse_file_warnings(self):
        warning0 = ParseWarning.missing_fields(['spam_report', 'sim_slot', 'creator', 'sub_id', 'sim_imsi', 'safe_message'])
        expected_warnings = [{'type': 'warning', 'value': warning0}] * 8

        full_file_name = os.path.join('tests', 'data', 'sms-test.xml')
        # items are tested in a different test
        warnings = filter(lambda x: x['type'] == 'warning', self.backup_control.parse_file(full_file_name))

        self.assertEquals(warnings, expected_warnings)

    def test_tree_appender_should_add_call_element_to_root_with_sms(self):
        element_tree = self.backup_control.tree_seed()
        sms = SMS(
            body='My Message',
            service_center='+13123149623',
            protocol='0',
            read='1',
            sc_toa='null',
            readable_date='Jul 15, 2013 7:07:22 PM',
            date_sent='1373929642000',
            status='-1',
            address='7535',
            date='1373929642000',
            locked='0',
            contact_name='(Unknown)',
            toa='null',
            type='1',
            subject='null')

        subelement = self.backup_control.tree_appender(element_tree, sms)
        self.assertEquals(element_tree.find('sms'), subelement)

    def test_tree_appender_should_create_element_with_correct_attributes_with_sms(self):
        element_tree = self.backup_control.tree_seed()
        sms = SMS(
            body='My Message',
            service_center='+13123149623',
            protocol='0',
            read='1',
            sc_toa='null',
            readable_date='Jul 15, 2013 7:07:22 PM',
            date_sent='1373929642000',
            status='-1',
            address='7535',
            date='1373929642000',
            locked='0',
            contact_name='(Unknown)',
            toa='null',
            type='1',
            subject='null')

        subelement = self.backup_control.tree_appender(element_tree, sms)
        self.assertEquals(subelement.get('body'), 'My Message')
        self.assertEquals(subelement.get('service_center'), '+13123149623')
        self.assertEquals(subelement.get('protocol'), '0')
        self.assertEquals(subelement.get('sc_toa'), 'null')
        self.assertEquals(subelement.get('readable_date'), 'Jul 15, 2013 7:07:22 PM')
        self.assertEquals(subelement.get('date'), '1373929642000')
        self.assertEquals(subelement.get('date_sent'), '1373929642000')
        self.assertEquals(subelement.get('status'), '-1')
        self.assertEquals(subelement.get('address'), '7535')
        self.assertEquals(subelement.get('toa'), 'null')
        self.assertEquals(subelement.get('subject'), 'null')
        self.assertEquals(subelement.get('contact_name'), '(Unknown)')
        self.assertEquals(subelement.get('type'), '1')

    def test_tree_appender_should_increment_count_on_root_with_sms(self):
        element_tree = self.backup_control.tree_seed()
        sms = SMS(
            body='My Message',
            service_center='+13123149623',
            protocol='0',
            read='1',
            sc_toa='null',
            readable_date='Jul 15, 2013 7:07:22 PM',
            date_sent='1373929642000',
            status='-1',
            address='7535',
            date='1373929642000',
            locked='0',
            contact_name='(Unknown)',
            toa='null',
            type='1',
            subject='null')

        subelement = self.backup_control.tree_appender(element_tree, sms)

        self.assertEquals(element_tree.getroot().get('count'), '1')

    def test_tree_appender_should_add_call_element_to_root_with_mms(self):
        element_tree = self.backup_control.tree_seed()
        mms = MMS(
            callback_set='0',
            m_id='103019290470004800008',
            reserved='0',
            creator=None,
            msg_id='0',
            pri='129',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='1',
            contact_name='Ted Turner',
            sub='',
            rr='129',
            text_only='1',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='6',
            resp_st='128',
            msg_box='2',
            readable_date='Oct 30, 2014 3:29:04 PM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report=None,
            deletable='0',
            address='+15555550001',
            date='1414697344000',
            sim_slot=None,
            sim_imsi=None,
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='T14962885023',
            locked='0',
            m_type='128',
            sub_id=None,
            retr_st='null',
            safe_message=None,
            d_tm='null',
            st='null',
            m_cls='personal',
            exp='604800',
            v='18',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='null',
                    seq='-1',
                    cl='smil.xml',
                    text='<smil><head><layout><root-layout width="100px" height="1080px"/><region id="Text" left="0" top="972" width="100px" height="108px" fit="meet"/></layout></head><body><par dur="5000ms"><text src="cid:text_0.txt" region="Text"/></par></body></smil>',
                    cid='<smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='null',
                    seq='0',
                    cl='text_0.txt',
                    text="I'm in",
                    cid='<text_0.txt>',
                    chset='106',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='text/plain')),
            addresses=())

        subelement = self.backup_control.tree_appender(element_tree, mms)
        self.assertEquals(element_tree.find('mms'), subelement)

    def test_tree_appender_should_create_element_with_correct_attributes_with_mms(self):
        element_tree = self.backup_control.tree_seed()
        mms = MMS(
            callback_set='0',
            m_id='103019290470004800008',
            reserved='0',
            creator=None,
            msg_id='0',
            pri='129',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='1',
            contact_name='Ted Turner',
            sub='',
            rr='129',
            text_only='1',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='6',
            resp_st='128',
            msg_box='2',
            readable_date='Oct 30, 2014 3:29:04 PM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report=None,
            deletable='0',
            address='+15555550001',
            date='1414697344000',
            sim_slot=None,
            sim_imsi=None,
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='T14962885023',
            locked='0',
            m_type='128',
            sub_id=None,
            retr_st='null',
            safe_message=None,
            d_tm='null',
            st='null',
            m_cls='personal',
            exp='604800',
            v='18',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='null',
                    seq='-1',
                    cl='smil.xml',
                    text='<smil><head><layout><root-layout width="100px" height="1080px"/><region id="Text" left="0" top="972" width="100px" height="108px" fit="meet"/></layout></head><body><par dur="5000ms"><text src="cid:text_0.txt" region="Text"/></par></body></smil>',
                    cid='<smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='null',
                    seq='0',
                    cl='text_0.txt',
                    text="I'm in",
                    cid='<text_0.txt>',
                    chset='106',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='text/plain')),
            addresses=())

        subelement = self.backup_control.tree_appender(element_tree, mms)
        self.assertEquals(subelement.get('readable_date'), 'Oct 30, 2014 3:29:04 PM')
        self.assertEquals(subelement.get('m_id'), '103019290470004800008')
        self.assertEquals(subelement.get('date'), '1414697344000')
        self.assertEquals(subelement.get('address'), '+15555550001')
        self.assertEquals(subelement.get('contact_name'), 'Ted Turner')
        self.assertEquals(subelement.get('m_type'), '128')
        self.assertEquals(subelement.get('pri'), '129')
        self.assertEquals(subelement.get('rr'), '129')
        self.assertEquals(subelement.get('text_only'), '1')
        self.assertEquals(subelement.get('ct_t'), 'application/vnd.wap.multipart.related')
        self.assertEquals(subelement.get('ct_l'), 'null')
        self.assertEquals(subelement.get('date_sent'), '0')
        self.assertEquals(subelement.get('msg_box'), '2')
        self.assertEquals(subelement.get('resp_st'), '128')
        self.assertEquals(subelement.get('m_size'), '6')
        self.assertEquals(subelement.get('m_cls'), 'personal')
        self.assertEquals(subelement.get('tr_id'), 'T14962885023')

    def test_tree_appender_should_increment_count_on_root_with_mms(self):
        element_tree = self.backup_control.tree_seed()
        mms = MMS(
            callback_set='0',
            m_id='103019290470004800008',
            reserved='0',
            creator=None,
            msg_id='0',
            pri='129',
            app_id='0',
            retr_txt='null',
            sub_cs='null',
            seen='1',
            contact_name='Ted Turner',
            sub='',
            rr='129',
            text_only='1',
            ct_t='application/vnd.wap.multipart.related',
            ct_l='null',
            m_size='6',
            resp_st='128',
            msg_box='2',
            readable_date='Oct 30, 2014 3:29:04 PM',
            rpt_a='null',
            read='1',
            retr_txt_cs='null',
            d_rpt='129',
            spam_report=None,
            deletable='0',
            address='+15555550001',
            date='1414697344000',
            sim_slot=None,
            sim_imsi=None,
            hidden='0',
            resp_txt='null',
            ct_cls='null',
            tr_id='T14962885023',
            locked='0',
            m_type='128',
            sub_id=None,
            retr_st='null',
            safe_message=None,
            d_tm='null',
            st='null',
            m_cls='personal',
            exp='604800',
            v='18',
            date_sent='0',
            read_status='null',
            parts=(
                MMSPart(
                    name='null',
                    seq='-1',
                    cl='smil.xml',
                    text='<smil><head><layout><root-layout width="100px" height="1080px"/><region id="Text" left="0" top="972" width="100px" height="108px" fit="meet"/></layout></head><body><par dur="5000ms"><text src="cid:text_0.txt" region="Text"/></par></body></smil>',
                    cid='<smil>',
                    chset='null',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='application/smil'),
                MMSPart(
                    name='null',
                    seq='0',
                    cl='text_0.txt',
                    text="I'm in",
                    cid='<text_0.txt>',
                    chset='106',
                    cd='null',
                    ctt_t='null',
                    ctt_s='null',
                    data=None,
                    fn='null',
                    ct='text/plain')),
            addresses=())

        subelement = self.backup_control.tree_appender(element_tree, mms)

        self.assertEquals(element_tree.getroot().get('count'), '1')

if __name__ == '__main__':
    unittest.main()
