<s> import os <EOL> from django . test import SimpleTestCase , TestCase <EOL> from corehq . apps . receiverwrapper import submit_form_locally <EOL> from corehq . util . test_utils import TestFileMixin <EOL> from corehq . form_processor . interfaces . processor import FormProcessorInterface <EOL> from corehq . form_processor . tests . utils import run_with_all_backends <EOL> from corehq . form_processor . utils import convert_xform_to_json <EOL> from phonelog . models import UserEntry , DeviceReportEntry , UserErrorEntry , ForceCloseEntry <EOL> from phonelog . utils import _get_logs <EOL> class DeviceLogTest ( TestCase , TestFileMixin ) : <EOL> file_path = ( '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> root = os . path . dirname ( __file__ ) <EOL> def setUp ( self ) : <EOL> self . interface = FormProcessorInterface ( ) <EOL> def tearDown ( self ) : <EOL> DeviceReportEntry . objects . all ( ) . delete ( ) <EOL> UserEntry . objects . all ( ) . delete ( ) <EOL> UserErrorEntry . objects . all ( ) . delete ( ) <EOL> ForceCloseEntry . objects . all ( ) . delete ( ) <EOL> def assert_properties_equal ( self , obj , expected ) : <EOL> for prop , value in expected : <EOL> actual = getattr ( obj , prop ) <EOL> msg = ( "<STR_LIT>" <EOL> . format ( obj . __class__ . __name__ , prop , value , actual ) ) <EOL> self . assertEqual ( actual , value , msg ) <EOL> @ run_with_all_backends <EOL> def test_basic_devicelog ( self ) : <EOL> xml = self . get_xml ( '<STR_LIT>' ) <EOL> submit_form_locally ( xml , '<STR_LIT>' ) <EOL> self . assert_device_report_entries ( ) <EOL> self . assert_user_entries ( ) <EOL> self . assert_user_error_entries ( ) <EOL> self . assert_force_close_entries ( ) <EOL> def assert_device_report_entries ( self ) : <EOL> self . assertEqual ( DeviceReportEntry . objects . count ( ) , <NUM_LIT:7> ) <EOL> first = DeviceReportEntry . objects . first ( ) <EOL> self . assert_properties_equal ( first , ( <EOL> ( '<STR_LIT:type>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:i>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> ) ) <EOL> self . assertIsNotNone ( first . server_date ) <EOL> self . assertIsNotNone ( first . date ) <EOL> second = DeviceReportEntry . objects . all ( ) [ <NUM_LIT:1> ] <EOL> self . assert_properties_equal ( second , ( <EOL> ( '<STR_LIT:type>' , '<STR_LIT:user>' ) , <EOL> ( '<STR_LIT:username>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) ) <EOL> def assert_user_entries ( self ) : <EOL> self . assertEqual ( UserEntry . objects . count ( ) , <NUM_LIT:1> ) <EOL> user_entry = UserEntry . objects . first ( ) <EOL> self . assertIsNotNone ( user_entry . xform_id ) <EOL> self . assert_properties_equal ( user_entry , ( <EOL> ( '<STR_LIT:i>' , <NUM_LIT:0> ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:username>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) ) <EOL> def assert_user_error_entries ( self ) : <EOL> self . assertEqual ( UserErrorEntry . objects . count ( ) , <NUM_LIT:2> ) <EOL> user_error = UserErrorEntry . objects . all ( ) [ <NUM_LIT:1> ] <EOL> self . assert_properties_equal ( user_error , ( <EOL> ( '<STR_LIT:type>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) ) <EOL> def assert_force_close_entries ( self ) : <EOL> self . assertEqual ( ForceCloseEntry . objects . count ( ) , <NUM_LIT:1> ) <EOL> force_closure = ForceCloseEntry . objects . first ( ) <EOL> self . assert_properties_equal ( force_closure , ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , <NUM_LIT:15> ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:type>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ) ) <EOL> self . assertEqual ( force_closure . date . isoformat ( ) , '<STR_LIT>' ) <EOL> self . assertIsNotNone ( force_closure . xform_id ) <EOL> self . assertIsNotNone ( force_closure . server_date ) <EOL> self . assertIn ( "<STR_LIT>" , force_closure . msg ) <EOL> @ run_with_all_backends <EOL> def test_subreports_that_shouldnt_fail ( self ) : <EOL> xml = self . get_xml ( '<STR_LIT>' ) <EOL> submit_form_locally ( xml , '<STR_LIT>' ) <EOL> class TestDeviceLogUtils ( SimpleTestCase , TestFileMixin ) : <EOL> file_path = ( '<STR_LIT:data>' , '<STR_LIT>' ) <EOL> root = os . path . dirname ( __file__ ) <EOL> def test_single_node ( self ) : <EOL> form_data = convert_xform_to_json ( self . get_xml ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> _get_logs ( form_data , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> [ { u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:type>' : u'<STR_LIT>' } , <EOL> { u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:type>' : u'<STR_LIT:user>' } ] <EOL> ) <EOL> def test_single_entry ( self ) : <EOL> form_data = convert_xform_to_json ( self . get_xml ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> _get_logs ( form_data , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> [ { "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:version>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:type>" : "<STR_LIT>" } ] <EOL> ) <EOL> def test_multiple_nodes ( self ) : <EOL> form_data = convert_xform_to_json ( self . get_xml ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> _get_logs ( form_data , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> [ { u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:type>' : u'<STR_LIT>' } , <EOL> { u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:type>' : u'<STR_LIT:user>' } , <EOL> { u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT>' : u'<STR_LIT>' , <EOL> u'<STR_LIT:type>' : u'<STR_LIT>' } ] <EOL> ) </s>
