<filename>tests/test_basic.py
from six import text_type

import parsely_raw_data

expected_view = {
    "action": "pageview",
    "apikey": "example.com",
    "campaign_id": None,
    "channel": "website",
    "display": True,
    "display_avail_height": 877,
    "display_avail_width": 1436,
    "display_pixel_depth": 24,
    "display_total_height": 900,
    "display_total_width": 1440,
    "engaged_time_inc": None,
    "extra_data": None,
    "flags_is_amp": False,
    "event_id": "0x32bc4058da8233e6ddd86ba0a8920586",
    "ip_city": "Toronto",
    "ip_continent": "NA",
    "ip_country": "CA",
    "ip_lat": 43.7124,
    "ip_lon": -79.3644,
    "ip_postal": "M4G",
    "ip_subdivision": "ON",
    "ip_timezone": "America/Toronto",
    "ip_market_nielsen": None,
    "ip_market_doubleclick": None,
    "ip_market_name": None,
    "metadata": False,
    "metadata_authors": None,
    "metadata_canonical_url": None,
    "metadata_custom_metadata": None,
    "metadata_data_source": None,
    "metadata_duration": None,
    "metadata_full_content_word_count": None,
    "metadata_image_url": None,
    "metadata_page_type": None,
    "metadata_post_id": None,
    "metadata_pub_date_tmsp": None,
    "metadata_save_date_tmsp": None,
    "metadata_section": None,
    "metadata_share_urls": None,
    "metadata_tags": None,
    "metadata_thumb_url": None,
    "metadata_title": None,
    "metadata_urls": None,
    "pageload_id": None,
    "pageview_id": None,
    "ref_category": "internal",
    "ref_clean": "http://www.example.com/article-123",
    "ref_domain": "example.com",
    "ref_fragment": "",
    "ref_netloc": "www.example.com",
    "ref_params": "",
    "ref_path": "/article-123",
    "ref_query": "",
    "ref_scheme": "http",
    "referrer": "http://www.example.com/article-123",
    "schema_version": parsely_raw_data.__version__,
    "session": True,
    "session_id": 5,
    "session_initial_referrer": "https://www.google.ca/",
    "session_initial_url": "http://www.example.com/",
    "session_last_session_timestamp": "1_470_045_600_000",
    "session_timestamp": "1_471_428_000_000",
    "slot": False,
    "sref_category": "search",
    "sref_clean": "https://www.google.ca/",
    "sref_domain": "google",
    "sref_fragment": "",
    "sref_netloc": "www.google.ca",
    "sref_params": "",
    "sref_path": "/",
    "sref_query": "",
    "sref_scheme": "https",
    "surl_clean": "http://www.example.com/",
    "surl_domain": "example.com",
    "surl_fragment": "",
    "surl_netloc": "www.example.com",
    "surl_params": "",
    "surl_path": "/",
    "surl_query": "",
    "surl_scheme": "http",
    "surl_utm_campaign": None,
    "surl_utm_content": None,
    "surl_utm_medium": None,
    "surl_utm_source": None,
    "surl_utm_term": None,
    "timestamp_info": True,
    "timestamp_info_nginx_ms": "1_429_707_722_000",
    "timestamp_info_override_ms": None,
    "timestamp_info_pixel_ms": None,
    "ts_action": "2015-04-22 13:02:02",
    "ts_session_current": "2016-08-17 10:00:00",
    "ts_session_last": "2016-08-01 10:00:00",
    "ua_browser": "Chrome",
    "ua_browserversion": "52.0.2743",
    "ua_device": "Other",
    "ua_devicebrand": None,
    "ua_devicemodel": None,
    "ua_devicetouchcapable": False,
    "ua_devicetype": "desktop",
    "ua_os": "Mac OS X",
    "ua_osversion": "10.10.5",
    "url": "http://www.example.com/",
    "url_clean": "http://www.example.com/",
    "url_domain": "example.com",
    "url_fragment": "",
    "url_netloc": "www.example.com",
    "url_params": "",
    "url_path": "/",
    "url_query": "",
    "url_scheme": "http",
    "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36",
    "utm_campaign": None,
    "utm_content": None,
    "utm_medium": None,
    "utm_source": None,
    "utm_term": None,
    "videostart_id": None,
    "version": 1,
    "visitor": True,
    "visitor_ip": "192.168.127.12",
    "visitor_network_id": "",
    "visitor_site_id": "e71604df-a912-455d-aaf3-a9c72a6dd86c",
}

test_view = {
    "action": "pageview",
    "apikey": "example.com",
    "channel": "website",
    "display": True,
    "display_avail_height": 877,
    "display_avail_width": 1436,
    "display_pixel_depth": 24,
    "display_total_height": 900,
    "display_total_width": 1440,
    "event_id": "0x32bc4058da8233e6ddd86ba0a8920586",
    "ip_city": "Toronto",
    "ip_continent": "NA",
    "ip_country": "CA",
    "ip_lat": 43.7124,
    "ip_lon": -79.3644,
    "ip_postal": "M4G",
    "ip_subdivision": "ON",
    "ip_timezone": "America/Toronto",
    "ip_market_nielsen": None,
    "ip_market_doubleclick": None,
    "ip_market_name": None,
    "metadata": False,
    "metadata_authors": None,
    "metadata_canonical_url": None,
    "metadata_custom_metadata": None,
    "metadata_data_source": None,
    "metadata_duration": None,
    "metadata_full_content_word_count": None,
    "metadata_image_url": None,
    "metadata_page_type": None,
    "metadata_post_id": None,
    "metadata_pub_date_tmsp": None,
    "metadata_save_date_tmsp": None,
    "metadata_section": None,
    "metadata_share_urls": None,
    "metadata_tags": None,
    "metadata_thumb_url": None,
    "metadata_title": None,
    "metadata_urls": None,
    "pageload_id": None,
    "pageview_id": None,
    "ref_category": "internal",
    "ref_clean": "http://www.example.com/article-123",
    "ref_domain": "example.com",
    "ref_fragment": "",
    "ref_netloc": "www.example.com",
    "ref_params": "",
    "ref_path": "/article-123",
    "ref_query": "",
    "ref_scheme": "http",
    "referrer": "http://www.example.com/article-123",
    "schema_version": parsely_raw_data.__version__,
    "session": True,
    "session_id": 5,
    "session_initial_referrer": "https://www.google.ca/",
    "session_initial_url": "http://www.example.com/",
    "session_last_session_timestamp": "1_470_045_600_000",
    "session_timestamp": "1_471_428_000_000",
    "slot": False,
    "sref_category": "search",
    "sref_clean": "https://www.google.ca/",
    "sref_domain": "google",
    "sref_fragment": "",
    "sref_netloc": "www.google.ca",
    "sref_params": "",
    "sref_path": "/",
    "sref_query": "",
    "sref_scheme": "https",
    "surl_clean": "http://www.example.com/",
    "surl_domain": "example.com",
    "surl_fragment": "",
    "surl_netloc": "www.example.com",
    "surl_params": "",
    "surl_path": "/",
    "surl_query": "",
    "surl_scheme": "http",
    "surl_utm_campaign": None,
    "surl_utm_content": None,
    "surl_utm_medium": None,
    "surl_utm_source": None,
    "surl_utm_term": None,
    "timestamp_info": True,
    "timestamp_info_nginx_ms": "1_429_707_722_000",
    "timestamp_info_override_ms": None,
    "timestamp_info_pixel_ms": None,
    "ts_action": "2015-04-22 13:02:02",
    "ts_session_current": "2016-08-17 10:00:00",
    "ts_session_last": "2016-08-01 10:00:00",
    "ua_browser": "Chrome",
    "ua_browserversion": "52.0.2743",
    "ua_device": "Other",
    "ua_devicetouchcapable": False,
    "ua_devicetype": "desktop",
    "ua_os": "Mac OS X",
    "ua_osversion": "10.10.5",
    "url": "http://www.example.com/",
    "url_clean": "http://www.example.com/",
    "url_domain": "example.com",
    "url_fragment": "",
    "url_netloc": "www.example.com",
    "url_params": "",
    "url_path": "/",
    "url_query": "",
    "url_scheme": "http",
    "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36",
    "version": 1,
    "visitor": True,
    "visitor_ip": "192.168.127.12",
    "visitor_network_id": "",
    "visitor_site_id": "e71604df-a912-455d-aaf3-a9c72a6dd86c",
}


def test_normalize_keys_empty_dict():
    # Return schema keys
    public_schema_keys = {text_type(field["key"]) for field in parsely_raw_data.schema.SCHEMA}

    # test passing empty dict yields full dict with empty rows
    event_empty_dict = {
        "event_id": "1234"
    }
    normalized_dict = dict(parsely_raw_data.normalize_keys(event_empty_dict, schema=public_schema_keys))
    assert len(normalized_dict.keys()) == len(public_schema_keys)


def test_normalize_keys_partially_complete_dict():
    public_schema_keys = {text_type(field["key"]) for field in parsely_raw_data.schema.SCHEMA}

    # test passing event dict yield all expected fields in schema
    normalized_dict = parsely_raw_data.normalize_keys(test_view, schema=public_schema_keys)
    assert normalized_dict == expected_view


def test_basic():
    pass


if __name__ == "__main__":
    test_basic()

<filename>tests/test_basic.py
from six import text_type

import parsely_raw_data

expected_view = {
    "action": "pageview",
    "apikey": "example.com",
    "campaign_id": None,
    "channel": "website",
    "display": True,
    "display_avail_height": 877,
    "display_avail_width": 1436,
    "display_pixel_depth": 24,
    "display_total_height": 900,
    "display_total_width": 1440,
    "engaged_time_inc": None,
    "extra_data": None,
    "flags_is_amp": False,
    "event_id": "0x32bc4058da8233e6ddd86ba0a8920586",
    "ip_city": "Toronto",
    "ip_continent": "NA",
    "ip_country": "CA",
    "ip_lat": 43.7124,
    "ip_lon": -79.3644,
    "ip_postal": "M4G",
    "ip_subdivision": "ON",
    "ip_timezone": "America/Toronto",
    "ip_market_nielsen": None,
    "ip_market_doubleclick": None,
    "ip_market_name": None,
    "metadata": False,
    "metadata_authors": None,
    "metadata_canonical_url": None,
    "metadata_custom_metadata": None,
    "metadata_data_source": None,
    "metadata_duration": None,
    "metadata_full_content_word_count": None,
    "metadata_image_url": None,
    "metadata_page_type": None,
    "metadata_post_id": None,
    "metadata_pub_date_tmsp": None,
    "metadata_save_date_tmsp": None,
    "metadata_section": None,
    "metadata_share_urls": None,
    "metadata_tags": None,
    "metadata_thumb_url": None,
    "metadata_title": None,
    "metadata_urls": None,
    "pageload_id": None,
    "pageview_id": None,
    "ref_category": "internal",
    "ref_clean": "http://www.example.com/article-123",
    "ref_domain": "example.com",
    "ref_fragment": "",
    "ref_netloc": "www.example.com",
    "ref_params": "",
    "ref_path": "/article-123",
    "ref_query": "",
    "ref_scheme": "http",
    "referrer": "http://www.example.com/article-123",
    "schema_version": parsely_raw_data.__version__,
    "session": True,
    "session_id": 5,
    "session_initial_referrer": "https://www.google.ca/",
    "session_initial_url": "http://www.example.com/",
    "session_last_session_timestamp": "1_470_045_600_000",
    "session_timestamp": "1_471_428_000_000",
    "slot": False,
    "sref_category": "search",
    "sref_clean": "https://www.google.ca/",
    "sref_domain": "google",
    "sref_fragment": "",
    "sref_netloc": "www.google.ca",
    "sref_params": "",
    "sref_path": "/",
    "sref_query": "",
    "sref_scheme": "https",
    "surl_clean": "http://www.example.com/",
    "surl_domain": "example.com",
    "surl_fragment": "",
    "surl_netloc": "www.example.com",
    "surl_params": "",
    "surl_path": "/",
    "surl_query": "",
    "surl_scheme": "http",
    "surl_utm_campaign": None,
    "surl_utm_content": None,
    "surl_utm_medium": None,
    "surl_utm_source": None,
    "surl_utm_term": None,
    "timestamp_info": True,
    "timestamp_info_nginx_ms": "1_429_707_722_000",
    "timestamp_info_override_ms": None,
    "timestamp_info_pixel_ms": None,
    "ts_action": "2015-04-22 13:02:02",
    "ts_session_current": "2016-08-17 10:00:00",
    "ts_session_last": "2016-08-01 10:00:00",
    "ua_browser": "Chrome",
    "ua_browserversion": "52.0.2743",
    "ua_device": "Other",
    "ua_devicebrand": None,
    "ua_devicemodel": None,
    "ua_devicetouchcapable": False,
    "ua_devicetype": "desktop",
    "ua_os": "Mac OS X",
    "ua_osversion": "10.10.5",
    "url": "http://www.example.com/",
    "url_clean": "http://www.example.com/",
    "url_domain": "example.com",
    "url_fragment": "",
    "url_netloc": "www.example.com",
    "url_params": "",
    "url_path": "/",
    "url_query": "",
    "url_scheme": "http",
    "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36",
    "utm_campaign": None,
    "utm_content": None,
    "utm_medium": None,
    "utm_source": None,
    "utm_term": None,
    "videostart_id": None,
    "version": 1,
    "visitor": True,
    "visitor_ip": "192.168.127.12",
    "visitor_network_id": "",
    "visitor_site_id": "e71604df-a912-455d-aaf3-a9c72a6dd86c",
}

test_view = {
    "action": "pageview",
    "apikey": "example.com",
    "channel": "website",
    "display": True,
    "display_avail_height": 877,
    "display_avail_width": 1436,
    "display_pixel_depth": 24,
    "display_total_height": 900,
    "display_total_width": 1440,
    "event_id": "0x32bc4058da8233e6ddd86ba0a8920586",
    "ip_city": "Toronto",
    "ip_continent": "NA",
    "ip_country": "CA",
    "ip_lat": 43.7124,
    "ip_lon": -79.3644,
    "ip_postal": "M4G",
    "ip_subdivision": "ON",
    "ip_timezone": "America/Toronto",
    "ip_market_nielsen": None,
    "ip_market_doubleclick": None,
    "ip_market_name": None,
    "metadata": False,
    "metadata_authors": None,
    "metadata_canonical_url": None,
    "metadata_custom_metadata": None,
    "metadata_data_source": None,
    "metadata_duration": None,
    "metadata_full_content_word_count": None,
    "metadata_image_url": None,
    "metadata_page_type": None,
    "metadata_post_id": None,
    "metadata_pub_date_tmsp": None,
    "metadata_save_date_tmsp": None,
    "metadata_section": None,
    "metadata_share_urls": None,
    "metadata_tags": None,
    "metadata_thumb_url": None,
    "metadata_title": None,
    "metadata_urls": None,
    "pageload_id": None,
    "pageview_id": None,
    "ref_category": "internal",
    "ref_clean": "http://www.example.com/article-123",
    "ref_domain": "example.com",
    "ref_fragment": "",
    "ref_netloc": "www.example.com",
    "ref_params": "",
    "ref_path": "/article-123",
    "ref_query": "",
    "ref_scheme": "http",
    "referrer": "http://www.example.com/article-123",
    "schema_version": parsely_raw_data.__version__,
    "session": True,
    "session_id": 5,
    "session_initial_referrer": "https://www.google.ca/",
    "session_initial_url": "http://www.example.com/",
    "session_last_session_timestamp": "1_470_045_600_000",
    "session_timestamp": "1_471_428_000_000",
    "slot": False,
    "sref_category": "search",
    "sref_clean": "https://www.google.ca/",
    "sref_domain": "google",
    "sref_fragment": "",
    "sref_netloc": "www.google.ca",
    "sref_params": "",
    "sref_path": "/",
    "sref_query": "",
    "sref_scheme": "https",
    "surl_clean": "http://www.example.com/",
    "surl_domain": "example.com",
    "surl_fragment": "",
    "surl_netloc": "www.example.com",
    "surl_params": "",
    "surl_path": "/",
    "surl_query": "",
    "surl_scheme": "http",
    "surl_utm_campaign": None,
    "surl_utm_content": None,
    "surl_utm_medium": None,
    "surl_utm_source": None,
    "surl_utm_term": None,
    "timestamp_info": True,
    "timestamp_info_nginx_ms": "1_429_707_722_000",
    "timestamp_info_override_ms": None,
    "timestamp_info_pixel_ms": None,
    "ts_action": "2015-04-22 13:02:02",
    "ts_session_current": "2016-08-17 10:00:00",
    "ts_session_last": "2016-08-01 10:00:00",
    "ua_browser": "Chrome",
    "ua_browserversion": "52.0.2743",
    "ua_device": "Other",
    "ua_devicetouchcapable": False,
    "ua_devicetype": "desktop",
    "ua_os": "Mac OS X",
    "ua_osversion": "10.10.5",
    "url": "http://www.example.com/",
    "url_clean": "http://www.example.com/",
    "url_domain": "example.com",
    "url_fragment": "",
    "url_netloc": "www.example.com",
    "url_params": "",
    "url_path": "/",
    "url_query": "",
    "url_scheme": "http",
    "user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36",
    "version": 1,
    "visitor": True,
    "visitor_ip": "192.168.127.12",
    "visitor_network_id": "",
    "visitor_site_id": "e71604df-a912-455d-aaf3-a9c72a6dd86c",
}


def test_normalize_keys_empty_dict():
    # Return schema keys
    public_schema_keys = {text_type(field["key"]) for field in parsely_raw_data.schema.SCHEMA}

    # test passing empty dict yields full dict with empty rows
    event_empty_dict = {
        "event_id": "1234"
    }
    normalized_dict = dict(parsely_raw_data.normalize_keys(event_empty_dict, schema=public_schema_keys))
    assert len(normalized_dict.keys()) == len(public_schema_keys)


def test_normalize_keys_partially_complete_dict():
    public_schema_keys = {text_type(field["key"]) for field in parsely_raw_data.schema.SCHEMA}

    # test passing event dict yield all expected fields in schema
    normalized_dict = parsely_raw_data.normalize_keys(test_view, schema=public_schema_keys)
    assert normalized_dict == expected_view


def test_basic():
    pass


if __name__ == "__main__":
    test_basic()

# Return schema keys # test passing empty dict yields full dict with empty rows # test passing event dict yield all expected fields in schema