Ejemplo n.º 1
0
def test_if_we_provide_id_field_array_it_is_used():
    doc = build_document({"dimensions": {"a": u"1؁", "b": u"2"},
                          "metrics": {"some_metric": "123"},
                          "start_date": date(2014, 2, 19)},
                         "data_type",
                         idMapping=["a", "b"])

    eq_(doc["_id"], "MdiBMg==")
Ejemplo n.º 2
0
def test_if_we_provide_id_field_it_is_used():
    doc = build_document({"dimensions": {"idVar": "foo"},
                          "metrics": {"some_metric": 123},
                          "start_date": date(2014, 2, 19)},
                         "data_type",
                         idMapping="idVar")

    eq_(doc["_id"], "Zm9v")
Ejemplo n.º 3
0
def test_build_document_no_dimensions():
    gapy_response = {
        "metrics": {"visits": "12345", "visitors": "5376"}
    }

    data = build_document(gapy_response, "foo", date(2013, 4, 1))

    assert_that(data, has_entries({
        "_timestamp": dt(2013, 4, 1, 0, 0, 0, "UTC"),
        "timeSpan": "week",
        "visits": 12345,
        "visitors": 5376,
    }))
Ejemplo n.º 4
0
def test_build_document_mappings_are_applied_to_dimensions():
    mappings = {
        "customVarValue1": "name"
    }
    gapy_response = {
        "metrics": {"visits": "12345"},
        "dimensions": {"customVarValue1": "Jane"},
    }

    doc = build_document(gapy_response, "people", date(2013, 4, 1), mappings)

    assert_that(doc, has_entries({
        "name": "Jane"
    }))
Ejemplo n.º 5
0
def test_if_we_provide_id_field_it_is_used():
    doc = build_document(
        {
            "dimensions": {
                "idVar": "foo"
            },
            "metrics": {
                "some_metric": 123
            },
            "start_date": date(2014, 2, 19)
        },
        "data_type",
        idMapping="idVar")

    eq_(doc["_id"], "Zm9v")
Ejemplo n.º 6
0
def test_build_document_mappings_are_applied_to_dimensions():
    mappings = {"customVarValue1": "name"}
    gapy_response = {
        "metrics": {
            "visits": "12345"
        },
        "dimensions": {
            "customVarValue1": "Jane"
        },
        "start_date": date(2013, 4, 1),
    }

    doc = build_document(gapy_response, "people", mappings)

    assert_that(doc, has_entries({"name": "Jane"}))
Ejemplo n.º 7
0
def test_if_we_provide_id_field_array_it_is_used():
    doc = build_document(
        {
            "dimensions": {
                "a": u"1؁",
                "b": u"2"
            },
            "metrics": {
                "some_metric": "123"
            },
            "start_date": date(2014, 2, 19)
        },
        "data_type",
        idMapping=["a", "b"])

    eq_(doc["_id"], "MdiBMg==")
Ejemplo n.º 8
0
def test_build_document():
    gapy_response = {
        "metrics": {"visits": "12345"},
        "dimensions": {"date": "2013-04-02"}
    }

    data = build_document(gapy_response, "weeklyvisits", date(2013, 4, 1))

    assert_that(data, has_entries({
        "_id": "d2Vla2x5dmlzaXRzXzIwMTMwNDAxMDAwMDAwX3dlZWtfMjAxMy0wNC0wMg==",
        "humanId": 'weeklyvisits_20130401000000_week_2013-04-02',
        "dataType": "weeklyvisits",
        "_timestamp": dt(2013, 4, 1, 0, 0, 0, "UTC"),
        "timeSpan": "week",
        "date": "2013-04-02",
        "visits": 12345,
    }))
Ejemplo n.º 9
0
def test_build_document_no_dimensions():
    gapy_response = {
        "metrics": {
            "visits": "12345",
            "visitors": "5376"
        },
        "start_date": date(2013, 4, 1),
    }

    data = build_document(gapy_response, "foo")

    assert_that(
        data,
        has_entries({
            "_timestamp": dt(2013, 4, 1, 0, 0, 0, "UTC"),
            "timeSpan": "week",
            "visits": 12345,
            "visitors": 5376,
        }))
Ejemplo n.º 10
0
def test_build_document_with_multi_value_field_mappings():
    mappings = {
        "multiValuesField": "originalField",
        "multiValuesField_0": "first",
        "multiValuesField_1": "second",
        "multiValuesField_2": "third",
    }

    gapy_response = {
        "metrics": {"visits": "12345"},
        "dimensions": {
            "multiValuesField": "first value:second value:third value"
        }
    }

    doc = build_document(gapy_response, "multival", date(2013, 4, 1), mappings)

    assert_that(doc, has_entries({
        "originalField": "first value:second value:third value",
        "first": "first value",
        "second": "second value",
        "third": "third value",
    }))
Ejemplo n.º 11
0
def test_build_document_fails_with_no_data_type():
    build_document({}, None)
Ejemplo n.º 12
0
def test_build_document_fails_with_no_data_type():
    build_document({}, None)
Ejemplo n.º 13
0
def test_build_document_fails_with_no_data_type():
    build_document({}, None, date(2012, 12, 12))