def test_update_history_webusage_without_history(spark, main_summary_data):
    main_summary = spark.createDataFrame(*main_summary_data)
    usage, os, locales, top10addon = agg_usage(main_summary,
                                               date='20180201',
                                               period=1,
                                               sample_factor=100.0 / 1,
                                               country_list=['DE'])
    usage_df = usage.toPandas()
    os_df = os.toPandas()
    locales_df = locales.toPandas()
    top10addon_df = top10addon.toPandas()

    fxhealth, webusage = all_metrics_per_day(['DE'],
                                             usage_pd_df=usage_df,
                                             os_pd_df=os_df,
                                             locales_pd_df=locales_df,
                                             topaddons_pd_df=top10addon_df)

    updated_webusage = update_history(webusage, None)

    expected_webusage = {
        'DE': [{
            "date": "2018-02-01",
            "metrics": {
                "pct_TP": 50.0,
                "pct_addon": 100.0,
                "os": {
                    u"Mac OS X": 50.0,
                    u"Windows 10": 50.0
                },
                "locale": {
                    u"en-US": 50.0,
                    u"DE": 50.0
                },
                "top10addons": {
                    u'SHA-1 deprecation staged rollout': 100.0
                }
            }
        }],
        'All': [{
            "date": "2018-02-01",
            "metrics": {
                "pct_TP": 50.0,
                "pct_addon": 100.0,
                "os": {
                    u"Mac OS X": 50.0,
                    u"Windows 10": 50.0
                },
                "locale": {
                    u"en-US": 50.0,
                    u"DE": 50.0
                },
                "top10addons": {
                    u'SHA-1 deprecation staged rollout': 100.0
                }
            }
        }]
    }

    assert expected_webusage == updated_webusage
def test_update_history_fxhealth_without_history(spark, main_summary_data):
    main_summary = spark.createDataFrame(*main_summary_data)
    usage, os, locales, top10addon = agg_usage(main_summary,
                                               date='20180201',
                                               period=1,
                                               sample_factor=100.0 / 1,
                                               country_list=['DE'])
    usage_df = usage.toPandas()
    os_df = os.toPandas()
    locales_df = locales.toPandas()
    top10addon_df = top10addon.toPandas()

    fxhealth, webusage = all_metrics_per_day(['DE'],
                                             usage_pd_df=usage_df,
                                             os_pd_df=os_df,
                                             locales_pd_df=locales_df,
                                             topaddons_pd_df=top10addon_df)

    updated_fxhealth = update_history(fxhealth, None)

    expected_fxhealth = {
        'DE': [{
            "date": "2018-02-01",
            "metrics": {
                "avg_daily_usage(hours)": 300.0 / 3600 / 2.0,
                "avg_intensity": 1.0,
                "pct_latest_version": 50.0,
                "MAU": 200.0,
                "YAU": 200.0,
                "pct_new_user": 50.0
            }
        }],
        'All': [{
            "date": "2018-02-01",
            "metrics": {
                "avg_daily_usage(hours)": 300.0 / 3600 / 2.0,
                "avg_intensity": 1.0,
                "pct_latest_version": 50.0,
                "MAU": 200.0,
                "YAU": 200.0,
                "pct_new_user": 50.0
            }
        }]
    }

    assert expected_fxhealth == updated_fxhealth