|
| 1 | +import datetime |
| 2 | +import pytest |
| 3 | +from macadamia import parse_cookie |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.parametrize( |
| 7 | + ("cookie", "expected"), |
| 8 | + [ |
| 9 | + ( |
| 10 | + "44858868.462535200.44.2.fiztmcsr=localhost:9000|fiztmccn=(referral)|fiztmcmd=referral|fiztmcct=/", |
| 11 | + { |
| 12 | + "domain_hash": "44858868", |
| 13 | + "timestamp": datetime.datetime(year=1984, month=8, day=28, hour=10), |
| 14 | + "session_counter": "44", |
| 15 | + "campaign_number": "2", |
| 16 | + "campaign_data": { |
| 17 | + "campaign_content": "/", |
| 18 | + "campaign_name": "(referral)", |
| 19 | + "medium": "referral", |
| 20 | + "source": "localhost:9000", |
| 21 | + }, |
| 22 | + }, |
| 23 | + ), |
| 24 | + ( |
| 25 | + "208940939.1365186784.1.1.fiztmcsr=(direct)|fiztmccn=(direct)|fiztmcmd=(none)", |
| 26 | + { |
| 27 | + "campaign_number": "1", |
| 28 | + "domain_hash": "208940939", |
| 29 | + "session_counter": "1", |
| 30 | + "timestamp": datetime.datetime(2013, 4, 5, 18, 33, 4), |
| 31 | + "campaign_data": { |
| 32 | + "campaign_name": "(direct)", |
| 33 | + "medium": "(none)", |
| 34 | + "source": "(direct)", |
| 35 | + }, |
| 36 | + }, |
| 37 | + ), |
| 38 | + ( |
| 39 | + "48016369.462535200.1.1.fiztmcsr=realgeeks.com|fiztmccn=(referral)|fiztmcmd=referral|fiztmcct=/clients/lee-cunningham/", |
| 40 | + { |
| 41 | + "campaign_number": "1", |
| 42 | + "domain_hash": "48016369", |
| 43 | + "session_counter": "1", |
| 44 | + "timestamp": datetime.datetime(year=1984, month=8, day=28, hour=10), |
| 45 | + "campaign_data": { |
| 46 | + "campaign_content": "/clients/lee-cunningham/", |
| 47 | + "campaign_name": "(referral)", |
| 48 | + "medium": "referral", |
| 49 | + "source": "realgeeks.com", |
| 50 | + }, |
| 51 | + }, |
| 52 | + ), |
| 53 | + ( |
| 54 | + "44858868.462535200.71.3.fiztmcsr=google|fiztmccn=(organic)|fiztmcmd=organic|fiztmctr=hawaii%20real%20estate", |
| 55 | + { |
| 56 | + "campaign_number": "3", |
| 57 | + "domain_hash": "44858868", |
| 58 | + "session_counter": "71", |
| 59 | + "timestamp": datetime.datetime(year=1984, month=8, day=28, hour=10), |
| 60 | + "campaign_data": { |
| 61 | + "campaign_keyword": "hawaii real estate", |
| 62 | + "campaign_name": "(organic)", |
| 63 | + "medium": "organic", |
| 64 | + "source": "google", |
| 65 | + }, |
| 66 | + }, |
| 67 | + ), |
| 68 | + ( |
| 69 | + "112962326.462535200.1.1.fiztmgclid=CMbMrdi_ybgCFWho7AodDyAAvQ|fiztmccn=(not set)|fiztmcmd=(not set)|fiztmctr=real estate for sale in wilmington nc", |
| 70 | + { |
| 71 | + "campaign_number": "1", |
| 72 | + "domain_hash": "112962326", |
| 73 | + "session_counter": "1", |
| 74 | + "timestamp": datetime.datetime(year=1984, month=8, day=28, hour=10), |
| 75 | + "campaign_data": { |
| 76 | + "campaign_keyword": "real estate for sale in wilmington nc", |
| 77 | + "campaign_name": "(not set)", |
| 78 | + "google_click_id": "CMbMrdi_ybgCFWho7AodDyAAvQ", |
| 79 | + "medium": "(not set)", |
| 80 | + }, |
| 81 | + }, |
| 82 | + ), |
| 83 | + ], |
| 84 | +) |
| 85 | +def test_cookie_split_and_parse(cookie, expected): |
| 86 | + info = parse_cookie(cookie, prefix="fiztm") |
| 87 | + assert info == expected |
0 commit comments