# Path: performanceplatform/collector/ga/plugins/compute_id.py
# class ComputeIdFrom(object):
# 
#     def __init__(self, *fields):
#         self.fields = fields
# 
#     def __call__(self, documents):
#         for document in documents:
# 
#             id_parts = (stringify(document[field]) for field in self.fields)
#             id_string = "_".join(id_parts)
# 
#             _id, humanId = value_id(id_string)
# 
#             document['_id'] = _id
#             document['humanId'] = humanId
# 
#         return documents
# 
# def value_id(value):
#     value_bytes = value.encode('utf-8')
#     return base64.urlsafe_b64encode(value_bytes), value_bytes


from performanceplatform.collector.ga.plugins.compute_id \
    import ComputeIdFrom, value_id
    from nose.tools import assert_in, assert_equal
    from pprint import pprint


def test_ComputeIdFrom():

    documents = [
        {"a": 1, "b": 2, "c": 3}
    ]

    plugin = ComputeIdFrom("a", "b")

    documents = plugin(documents)

    (document,) = documents

    assert_in("a", document)
    assert_in("b", document)

    assert_in("_id", document)
    assert_in("humanId", document)

    pprint(document)


# Path: performanceplatform/collector/ga/plugins/compute_id.py
# class ComputeIdFrom(object):
# 
#     def __init__(self, *fields):
#         self.fields = fields
# 
#     def __call__(self, documents):
#         for document in documents:
# 
#             id_parts = (stringify(document[field]) for field in self.fields)
#             id_string = "_".join(id_parts)
# 
#             _id, humanId = value_id(id_string)
# 
#             document['_id'] = _id
#             document['humanId'] = humanId
# 
#         return documents
# 
# def value_id(value):
#     value_bytes = value.encode('utf-8')
#     return base64.urlsafe_b64encode(value_bytes), value_bytes


# Path: tests/performanceplatform/collector/ga/plugins/test_compute_id.py
from performanceplatform.collector.ga.plugins.compute_id \
    import ComputeIdFrom, value_id
    from nose.tools import assert_in, assert_equal
    from pprint import pprint



def test_ComputeIdFrom():

    documents = [
        {"a": 1, "b": 2, "c": 3}
    ]

    plugin = ComputeIdFrom("a", "b")

    documents = plugin(documents)

    (document,) = documents

    assert_in("a", document)
    assert_in("b", document)

    assert_in("_id", document)
    assert_in("humanId", document)

    pprint(document)


    _id, humanId = value_id("{0}_{1}".format(document['a'], document['b']))