def test_build_document_set():
    def build_gapy_response(visits, name, start_date):
        return {
            "metrics": {"visits": visits},
            "dimensions": {"customVarValue1": name},
            "start_date": start_date,
        }

    mappings = {
        "customVarValue1": "name"
    }
    results = [
        build_gapy_response("12345", "Jane", date(2013, 4, 1)),
        build_gapy_response("2313", "John", date(2013, 4, 1)),
        build_gapy_response("4323", "Joanne", date(2013, 4, 8)),
    ]
    docs = build_document_set(results, "people", mappings)

    assert_that(docs, has_item(has_entries({
        "name": "Jane",
        "_timestamp": dt(2013, 4, 1, 0, 0, 0, "UTC"),
        "dataType": "people",
        "visits": 12345,
    })))
    assert_that(docs, has_item(has_entries({
        "name": "John",
        "_timestamp": dt(2013, 4, 1, 0, 0, 0, "UTC"),
        "visits": 2313,
    })))
    assert_that(docs, has_item(has_entries({
        "name": "Joanne",
        "_timestamp": dt(2013, 4, 8, 0, 0, 0, "UTC"),
        "visits": 4323,
    })))
def test_data_id():
    assert_that(
        data_id("a", dt(2012, 1, 1, 12, 0, 0, "UTC"), "week", ['one', 'two']),
        is_(
            ("YV8yMDEyMDEwMTEyMDAwMF93ZWVrX29uZV90d28=",
             "a_20120101120000_week_one_two")
        )
    )
Example #3
0
def test_build_document_set():
    def build_gapy_response(visits, name, start_date):
        return {
            "metrics": {
                "visits": visits
            },
            "dimensions": {
                "customVarValue1": name
            },
            "start_date": start_date,
        }

    mappings = {"customVarValue1": "name"}
    results = [
        build_gapy_response("12345", "Jane", date(2013, 4, 1)),
        build_gapy_response("2313", "John", date(2013, 4, 1)),
        build_gapy_response("4323", "Joanne", date(2013, 4, 8)),
    ]
    docs = build_document_set(results, "people", mappings)

    assert_that(
        docs,
        has_item(
            has_entries({
                "name": "Jane",
                "_timestamp": dt(2013, 4, 1, 0, 0, 0, "UTC"),
                "dataType": "people",
                "visits": 12345,
            })))
    assert_that(
        docs,
        has_item(
            has_entries({
                "name": "John",
                "_timestamp": dt(2013, 4, 1, 0, 0, 0, "UTC"),
                "visits": 2313,
            })))
    assert_that(
        docs,
        has_item(
            has_entries({
                "name": "Joanne",
                "_timestamp": dt(2013, 4, 8, 0, 0, 0, "UTC"),
                "visits": 4323,
            })))
def test_unicode_data_id():
    base64, human = data_id(
        "a",
        dt(2012, 1, 1, 12, 0, 0, "UTC"),
        "week",
        ['one', u"© ☯ ☮"])

    assert_is_instance(human, str)
    assert_that(human, is_(str("a_20120101120000_week_one_© ☯ ☮")))
    assert_that(base64,
                is_("YV8yMDEyMDEwMTEyMDAwMF93ZWVrX29uZV_CqSDimK8g4piu"))
Example #5
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,
    }))
Example #6
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,
    }))
Example #7
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,
        }))
Example #8
0
def test_data_id():
    assert_that(
        data_id("a", dt(2012, 1, 1, 12, 0, 0, "UTC"), "week", ['one', 'two']),
        is_(("YV8yMDEyMDEwMTEyMDAwMF93ZWVrX29uZV90d28=",
             "a_20120101120000_week_one_two")))
 def test_datetime_encoding(self):
     s = JSONEncoder().default(dt(2013, 5, 1, 12, 0, 15, "Europe/London"))
     assert_that(s, is_("2013-05-01T12:00:15+01:00"))
 def test_datetime_encoding(self):
     s = JSONEncoder().default(dt(2013, 5, 1, 12, 0, 15, "Europe/London"))
     assert_that(s, is_("2013-05-01T12:00:15+01:00"))