def test_vif_init_transaction_response_1():
    response_content = ('{p30}{3}Cinema 02{4}Cinema Two{5}MOANA{6}Moana{7}20170110100000{8}15{9}2{10}37'
                        '{1001}A 12{1002}A 11{100001}2'
                        '{100101}BOUNT00{100103}10{100105}A 12{100106}Tkt Bounty Web{100108}1'
                        '{100201}BOUNT00{100203}10{100205}A 11{100206}Tkt Bounty Web{100208}1')
    p30_record = VIFRecord(raw_content=response_content)
    expected = {
        3: 'Cinema 02',
        4: 'Cinema Two',
        5: 'MOANA',
        6: 'Moana',
        7: '20170110100000',
        8: 15.0,
        9: 2.0,
        10: 37.0,
        1001: 'A 12',
        1002: 'A 11',
        100001: 2,
        100101: 'BOUNT00',
        100103: 10.0,
        100105: 'A 12',
        100106: 'Tkt Bounty Web',
        100108: 1.0,
        100201: 'BOUNT00',
        100203: 10.0,
        100205: 'A 11',
        100206: 'Tkt Bounty Web',
        100208: 1.0,
    }
    assert p30_record.data() == expected
def test_vif_init_transaction_response_2():
    response_content = ('{p30}{3}Cinema 02{4}Cinema Two{5}MOANA{6}Moana{7}20170110100000{8}15{9}2{10}37'
                        '{1001}A 12{1002}A 11{100001}2'
                        '{100101}BOUNT00{100103}10{100105}A 12{100106}Tkt Bounty Web{100108}1'
                        '{100201}BOUNT00{100203}10{100205}A 11{100206}Tkt Bounty Web{100208}1')
    p30_record = VIFRecord(raw_content=response_content)
    expected = {
        'venue_code': 'Cinema 02',
        'venue_name': 'Cinema Two',
        'movie_code': 'MOANA',
        'movie_name': 'Moana',
        'session_start_time': '20170110100000',
        'transaction_fee': 15.0,
        'total_ticket_fees': 2.0,
        'total_transaction_price': 37.0,
        'reserved_seats': ['A 12', 'A 11'],
        'ticket_count': 2,
        'tickets': [
            {
                'ticket_code': 'BOUNT00',
                'ticket_price': 10.0,
                'seat_name': 'A 12',
                'ticket_name': 'Tkt Bounty Web',
                'ticket_service_fee': 1.0
            },
            {
                'ticket_code': 'BOUNT00',
                'ticket_price': 10.0,
                'seat_name': 'A 11',
                'ticket_name': 'Tkt Bounty Web',
                'ticket_service_fee': 1.0
            }
        ]
    }
    assert expected == p30_record.friendly_data()
def test_vif_init_transaction_request_1():
    record_data = {
        'workstation_id': 123,
        'user_code': 'TKTBTY',
        'session_number': 999,
        'transaction_type': 1,
        'customer_reference': 'CUSTNO123',
        'total_ticket_prices': 15.0,
        'total_ticket_fees': 3.0,
        'total_transaction_price': 18.0,
        'ticket_count': 3,
        'tickets': [
            {
                'ticket_code': 'BOUNT00',
                'ticket_price': 5.0,
                'ticket_service_fee': 1.0
            },
            {
                'ticket_code': 'BOUNT00',
                'ticket_price': 5.0,
                'ticket_service_fee': 1.0
            },
            {
                'ticket_code': 'BOUNT00',
                'ticket_price': 5.0,
                'ticket_service_fee': 1.0
            }
        ]
    }
    q30_record = VIFRecord(record_code='q30', data=record_data)
    assert q30_record.data() == {
        1: 123,               # workstation id
        2: 'TKTBTY',          # user code
        3: 999,               # session number
        4: 1,                 # transaction type
        5: 'CUSTNO123',       # customer reference
        10: 15.0,             # total ticket prices
        11: 3.0,              # total ticket fees
        13: 18.0,             # total transaction price
        100001: 3,            # elements in ticket array
        100101: 'BOUNT00',    # ticket code (1)
        100102: 5.0,          # ticket price (1)
        100103: 1.0,          # ticket service fee (1)
        100201: 'BOUNT00',    # ticket code (2)
        100202: 5.0,          # ticket price (2)
        100203: 1.0,          # ticket service fee (3)
        100301: 'BOUNT00',    # ticket code (3)
        100302: 5.0,          # ticket price (2)
        100303: 1.0           # ticket service fee (3)
    }
    assert q30_record.content() == (
        '{q30}{1}123{2}TKTBTY{3}999{4}1{5}CUSTNO123{10}15.0{11}3.0{13}18.0'
        '{100001}3'
        '{100101}BOUNT00{100102}5.0{100103}1.0'
        '{100201}BOUNT00{100202}5.0{100203}1.0'
        '{100301}BOUNT00{100302}5.0{100303}1.0'
    )
def test_raw_content_converts_to_data():
    raw_content = '{vrq}{1}BARKER{2}ABCD{3}1{4}Test{8}108193016648'
    message = VIFRecord(raw_content=raw_content)
    assert message.data() == {
        1: 'BARKER',
        2: 'ABCD',
        3: 1,
        4: 'Test',
        8: '108193016648'
    }
def test_data_fields_not_parsed_if_keys_already_integers():
    data = {1: 'BARKER', 2: 'ABCD', 3: 1, 4: 'Test', 8: '108193016648'}
    message = VIFRecord(data=data)
    assert message.data() == {
        1: 'BARKER',
        2: 'ABCD',
        3: 1,
        4: 'Test',
        8: '108193016648'
    }
def test_mapping_of_data_to_field_names_3():
    raw_content = '{vrq}{1}BARKER{2}ABCD{3}1{4}Test{8}108193016648'
    message = VIFRecord(raw_content=raw_content)
    assert message.friendly_data() == {
        'site_name': 'BARKER',
        'packet_id': 'ABCD',
        'request_code': 1,
        'comment': 'Test',
        'auth_info': '108193016648'
    }
def test_mapping_of_data_to_field_names_2():
    data = {1: 'BARKER', 2: 'ABCD', 3: 1, 4: 'Test', 8: '108193016648'}
    message = VIFRecord(record_code='vrq', data=data)
    assert message.friendly_data() == {
        'site_name': 'BARKER',
        'packet_id': 'ABCD',
        'request_code': 1,
        'comment': 'Test',
        'auth_info': '108193016648'
    }
def test_mapping_of_data_to_field_names_including_tickets_2():
    data = {
        1: 123,  # workstation id
        2: 'TKTBTY',  # user code
        3: 999,  # session number
        4: 1,  # transaction type
        5: 'CUSTNO123',  # customer reference
        10: 15.0,  # total ticket prices
        11: 3.0,  # total ticket fees
        13: 18.0,  # total transaction price
        100001: 3,  # elements in ticket array
        100101: 'BOUNT00',  # ticket code (1)
        100102: 5,  # ticket price (1)
        100103: 1,  # ticket service fee (1)
        100201: 'BOUNT00',  # ticket code (2)
        100202: 5,  # ticket price (2)
        100203: 1,  # ticket service fee (3)
        100301: 'BOUNT00',  # ticket code (3)
        100302: 5,  # ticket price (2)
        100303: 1  # ticket service fee (3)
    }
    message = VIFRecord(record_code='q30', data=data)
    assert message.friendly_data() == {
        'workstation_id':
        123,
        'user_code':
        'TKTBTY',
        'session_number':
        999,
        'transaction_type':
        1,
        'customer_reference':
        'CUSTNO123',
        'total_ticket_prices':
        15.0,
        'total_ticket_fees':
        3.0,
        'total_transaction_price':
        18.0,
        'ticket_count':
        3,
        'tickets': [{
            'ticket_code': 'BOUNT00',
            'ticket_price': 5.0,
            'ticket_service_fee': 1.0
        }, {
            'ticket_code': 'BOUNT00',
            'ticket_price': 5.0,
            'ticket_service_fee': 1.0
        }, {
            'ticket_code': 'BOUNT00',
            'ticket_price': 5.0,
            'ticket_service_fee': 1.0
        }]
    }
def test_formatted_content_1():
    data = {
        'site_name': 'BARKER',
        'packet_id': 'ABCD',
        'request_code': 1,
        'comment': 'Test',
        'auth_info': '108193016648'
    }
    message = VIFRecord(record_code='vrq', data=data)
    assert message.content(
    ) == '{vrq}{1}BARKER{2}ABCD{3}1{4}Test{8}108193016648'
def test_vif_init_transaction_request_3():
    header_data = {
        'site_name': 'BARKER',
        'packet_id': '6A86',
        'comment': 'VIFGateway Test',
        'auth_info': '108193016648',
        'gateway_type': 0  # 0=Ticketing, 1=Concessions, 2=Voucher
    }
    body_data = {
        'workstation_id': 123,
        'user_code': 'TKTBTY',
        'session_number': 999,
        'transaction_type': 1,
        'customer_reference': 'CUSTNO123',
        'total_ticket_prices': 15.0,
        'total_ticket_fees': 3.0,
        'total_transaction_price': 18.0,
        'ticket_count': 3,
        'tickets': [
            {
                'ticket_code': 'BOUNT00',
                'ticket_price': 5.0,
                'ticket_service_fee': 1.0
            },
            {
                'ticket_code': 'BOUNT00',
                'ticket_price': 5.0,
                'ticket_service_fee': 1.0
            },
            {
                'ticket_code': 'BOUNT00',
                'ticket_price': 5.0,
                'ticket_service_fee': 1.0
            }
        ]
    }
    body_record = VIFRecord(record_code='q30', data=body_data)
    header_record = VIFRecord(record_code='vrq', data=header_data)

    # Construct message
    message = VIFMessage()
    message.set_request_header(request_code=30, **header_data)
    message.add_body_record(body_record)

    assert message.content() == (
        '{vrq}{1}BARKER{2}6A86{3}30{4}VIFGateway Test{8}108193016648{9}0!'
        '{q30}{1}123{2}TKTBTY{3}999{4}1{5}CUSTNO123{10}15.0{11}3.0{13}18.0'
        '{100001}3'
        '{100101}BOUNT00{100102}5.0{100103}1.0'
        '{100201}BOUNT00{100202}5.0{100203}1.0'
        '{100301}BOUNT00{100302}5.0{100303}1.0'
    )
def test_named_data_fields_convert_to_integer_keys():
    data = {
        'site_name': 'BARKER',
        'packet_id': 'ABCD',
        'request_code': 1,
        'comment': 'Test',
        'auth_info': '108193016648'
    }
    message = VIFRecord(record_code='vrq', data=data)
    assert message.data() == {
        1: 'BARKER',
        2: 'ABCD',
        3: 1,
        4: 'Test',
        8: '108193016648'
    }
Ejemplo n.º 12
0
def test_can_convert_payment_array_from_text_1():
    commit_request_content = (
        '{q31}{2}1769{4}44.80{5}42424XXXXXXX4242{7}0419925750{11}WWW{1001}1'
        '{1101}4{1102}NAB{1103}44.80{1104}42424XXXXXXX4242{1105}'
        '{1106}Test at 2017-01-10 20:01:00 by Ticketbounty{1107}VISA'
        '{1108}{1109}47R839373V998061D{1111}1')
    commit_record = VIFRecord(raw_content=commit_request_content)
    payment_array = commit_record._payments
    assert payment_array.count() == 1
def test_unable_to_format_content_if_record_code_not_provided():
    data = {
        'site_name': 'BARKER',
        'packet_id': 'ABCD',
        'request_code': 1,
        'comment': 'Test',
        'auth_info': '108193016648'
    }
    with pytest.raises(Exception):
        VIFRecord(data=data)
Ejemplo n.º 14
0
def test_parse_named_payment_data_to_record():
    commit_transaction_data = {
        'workstation_id':
        123,
        'booking_key':
        'ST-BOOKING-KEY',
        'customer_phone_number':
        '0417070155',
        'origin_label':
        'WWW',
        'payments': [{
            'payment_category': 14,  # microtransaction
            'payment_provider': 'Stripe',
            'amount_paid': 15.0,
        }]
    }
    record = VIFRecord(record_code='q31', data=commit_transaction_data)
    assert record.content() == (
        '{q31}{2}123{4}15.0{5}ST-BOOKING-KEY{7}0417070155{11}WWW{1001}1'
        '{1101}14{1102}Stripe{1103}15.0')
def test_parsing_of_transaction_data():
    transaction_data = {
        'workstation_id':
        123,
        'user_code':
        'TKTBTY',
        'session_number':
        999,
        'transaction_type':
        1,
        'customer_reference':
        'CUSTNO123',
        'total_ticket_prices':
        15.0,
        'total_ticket_fees':
        3.0,
        'total_transaction_price':
        18.0,
        'ticket_count':
        3,
        'tickets': [{
            'ticket_code': 'BOUNT00',
            'ticket_price': 5.0,
            'ticket_service_fee': 1.0
        }, {
            'ticket_code': 'BOUNT00',
            'ticket_price': 5.0,
            'ticket_service_fee': 1.0
        }, {
            'ticket_code': 'BOUNT00',
            'ticket_price': 5.0,
            'ticket_service_fee': 1.0
        }]
    }
    message = VIFRecord(record_code='q30', data=transaction_data)
    raw_content = ('{q30}{1}123{2}TKTBTY{3}999{4}1{5}CUSTNO123'
                   '{10}15.0{11}3.0{13}18.0{100001}3'
                   '{100101}BOUNT00{100102}5.0{100103}1.0'
                   '{100201}BOUNT00{100202}5.0{100203}1.0'
                   '{100301}BOUNT00{100302}5.0{100303}1.0')
    assert message.content() == raw_content
def test_mapping_of_data_to_field_names_including_tickets_3():
    raw_content = ('{q30}{1}123{2}TKTBTY{3}999{4}1{5}CUSTNO123'
                   '{10}15.0{11}3.0{13}18.0{100001}3'
                   '{100101}BOUNT00{100102}5{100103}1'
                   '{100201}BOUNT00{100202}5{100203}1'
                   '{100301}BOUNT00{100302}5{100303}1')
    message = VIFRecord(raw_content=raw_content)
    assert message.friendly_data() == {
        'workstation_id':
        123,
        'user_code':
        'TKTBTY',
        'session_number':
        999,
        'transaction_type':
        1,
        'customer_reference':
        'CUSTNO123',
        'total_ticket_prices':
        15.0,
        'total_ticket_fees':
        3.0,
        'total_transaction_price':
        18.0,
        'ticket_count':
        3,
        'tickets': [{
            'ticket_code': 'BOUNT00',
            'ticket_price': 5.0,
            'ticket_service_fee': 1.0
        }, {
            'ticket_code': 'BOUNT00',
            'ticket_price': 5.0,
            'ticket_service_fee': 1.0
        }, {
            'ticket_code': 'BOUNT00',
            'ticket_price': 5.0,
            'ticket_service_fee': 1.0
        }]
    }
def test_formatted_content_excludes_record_code_when_not_available_1():
    data = {1: 'BARKER', 2: 'ABCD', 3: 1, 4: 'Test', 8: '108193016648'}
    message = VIFRecord(data=data)
    assert message.content() == '{1}BARKER{2}ABCD{3}1{4}Test{8}108193016648'
def test_formatted_content_2():
    raw_content = '{vrq}{1}BARKER{2}ABCD{3}1{4}Test{8}108193016648'
    message = VIFRecord(raw_content=raw_content)
    assert raw_content == message.content()
def test_extract_record_code_from_raw_content():
    raw_content = '{vrq}{1}BARKER{2}ABCD{3}1{4}Test{8}108193016648'
    message = VIFRecord(raw_content=raw_content)
    assert message.record_code == 'vrq'
def test_formatted_content_includes_record_code_when_available():
    data = {1: 'BARKER', 2: 'ABCD', 3: '1', 4: 'Test', 8: '108193016648'}
    message = VIFRecord(record_code='vrq', data=data)
    assert message.content(
    ) == '{vrq}{1}BARKER{2}ABCD{3}1{4}Test{8}108193016648'
def test_formatted_content_excludes_record_code_when_not_available_2():
    raw_content = '{1}BARKER{2}ABCD{3}1{4}Test{8}108193016648'
    message = VIFRecord(raw_content=raw_content)
    assert message.content() == '{1}BARKER{2}ABCD{3}1{4}Test{8}108193016648'