Example #1
0
    def test_encode_list(self):
        call_log_1 = {
            'Call Date': '01/30/2013 00:00:00',
            'Caller': 'source1 (1001)',
            'Called': '2001',
            'Period': '1',
            'user Field': ''
        }

        call_log_2 = {
            'Call Date': '01/31/2013 00:00:00',
            'Caller': u'soùrce2 (1002)',
            'Called': '2002',
            'Period': '2',
            'user Field': 'userfield'
        }
        call_logs = [call_log_1, call_log_2]
        expected_result = textwrap.dedent('''\
            %s\r
            01/30/2013 00:00:00,source1 (1001),2001,1,\r
            01/31/2013 00:00:00,soùrce2 (1002),2002,2,userfield\r
            ''' % ','.join(CSV_HEADERS))

        result = serializer.encode_list(call_logs)

        assert_that(result, equal_to(expected_result))
Example #2
0
def _list_call_logs(call_logs):
    mapped_call_logs = map(mapper.to_api, call_logs)
    response = serializer.encode_list(mapped_call_logs)
    return make_response(response, 200, {'Content-disposition': 'attachment;filename=xivo-call-logs.csv'})