"""Tests for parsing MR_ACTIVE table.""" import json import pytest from parse_mr_active import dynamo_active_record_to_json MR_ACTIVE_NEW_FORMAT = { 'isrc': '{\"s\": \"CYA111100111\"}', 'locked_territories': ( '{\"m\": {\"AD\": {\"m\": {\"reason\": {\"s\": \"Registry Backfill' ' MEAT\"}}},\"AE\": {\"m\": {\"reason\": {\"s\": \"Registry Backfill' ' MEAT\"}}}}}'), 'territories': ( '{\"m\": {\"US\": {\"l\" :[{\"m\": {\"tuid\": {\"n\": \"11507054\"}}}]' '},\"CA\": {\"l\": [{\"m\": {\"tuid\": {\"n\": \"11507054\"}}}]}}}'), 'timestamp': '{\"n\": \"1484033255525.7922\"}' } MR_ACTIVE_NEW_FORMAT_PARSED = ( '{"territories": {"CA": ["11507054"], "US": ["11507054"]},' ' "locked_territories": {"AD": "Registry Backfill MEAT",' ' "AE": "Registry Backfill MEAT"}, "isrc": "CYA111100111"}') MR_ACTIVE_OLD_FORMAT = { 'isrc': '{\"s\": \"CYA111100111\"}', 'locked_territories': ( '{\"m\": {\"AD\": {\"m\": {\"reason\": {\"s\": \"Registry Backfill' ' MEAT\"}}},\"AE\": {\"m\": {\"reason\": {\"s\": \"Registry Backfill' ' MEAT\"}}}}}'), 'territories': ( '{\"m\": {\"US\": {\"m\": {\"tuid\": {\"n\": \"11507054\"}}},' '\"CA\": {\"m\": {\"tuid\": {\"n\": \"11507054\"}}}}}'), 'timestamp': '{\"n\": \"1484033255525.7922\"}' } MR_ACTIVE_OLD_FORMAT_PARSED = ( '{"territories": {"CA": ["11507054"], "US": ["11507054"]},' ' "locked_territories": {"AD": "Registry Backfill MEAT", "AE":' ' "Registry Backfill MEAT"}, "isrc": "CYA111100111"}') @pytest.mark.parametrize( 'record, expected_result', [ (MR_ACTIVE_OLD_FORMAT, MR_ACTIVE_OLD_FORMAT_PARSED), (MR_ACTIVE_NEW_FORMAT, MR_ACTIVE_NEW_FORMAT_PARSED) ] ) def test_parse_mr_active(record, expected_result): """Test parse MR_ACTIVE table success.""" parsed = dynamo_active_record_to_json(record) assert json.loads(parsed) == json.loads(expected_result)