# Path: habitat/views/payload_telemetry.py
# def _check_only_new(new, old):
# def _is_equal_relaxed_floats(a, b):
# def validate(new, old, userctx, secobj):
# def _estimate_time_received(receivers):
# def flight_payload_time_map(doc):
# def payload_time_map(doc):
# def time_map(doc):
# def add_listener_update(doc, req):
# def http_post_update(doc, req):
# 
# Path: habitat/views/utils.py
# def read_json_schema(schemaname):
#     mypath = os.path.dirname(inspect.getfile(inspect.currentframe()))
#     path = os.path.join(mypath, "..", "..", "couchdb", "schemas", schemaname)
#     with open(path) as f:
#         schema = json.load(f)
#     return schema


from ...views import payload_telemetry
from ...views.utils import read_json_schema
from couch_named_python import ForbiddenError, UnauthorizedError
from copy import deepcopy
from nose.tools import assert_raises
import json
import mox
    def test_tolerant_of_float_changes(self):
        old = deepcopy(doc)
        old['data']['value'] = 123.456
        old['data']['recurse'] = {"test_list": [0.00001, 1e20, 4.4],
                                  "value": 1.52142e10}
        
        # these changes should be allowed
        new = deepcopy(doc)
        new['data']['value'] = 123.4560000000001
        new['data']['recurse'] = \
            {"test_list": [0.000010000000000000005, 1e20 - 1e5, 4.4 - 1e-15],
             "value": 1.52142e10 + 1e-4}

        # check that they are actually different first
        assert old['data']['value'] != new['data']['value']
        assert all(old['data']['recurse']['test_list'][i] != 
                   new['data']['recurse']['test_list'][i] for i in range(3))
        assert old['data']['recurse']['value'] != \
                new['data']['recurse']['value']

        payload_telemetry.validate(new, old, {'roles': []}, {})

        # these should be outside of tolerance
        new = deepcopy(old)
        new['data']['value'] = 123.4560001
        assert_raises(UnauthorizedError, payload_telemetry.validate,
                new, old, {'roles': []}, {})

        new = deepcopy(old)
        new['data']['recurse']['test_list'][2] = 1e20 + 1e10

# Path: habitat/views/payload_telemetry.py
# def _check_only_new(new, old):
# def _is_equal_relaxed_floats(a, b):
# def validate(new, old, userctx, secobj):
# def _estimate_time_received(receivers):
# def flight_payload_time_map(doc):
# def payload_time_map(doc):
# def time_map(doc):
# def add_listener_update(doc, req):
# def http_post_update(doc, req):
# 
# Path: habitat/views/utils.py
# def read_json_schema(schemaname):
#     mypath = os.path.dirname(inspect.getfile(inspect.currentframe()))
#     path = os.path.join(mypath, "..", "..", "couchdb", "schemas", schemaname)
#     with open(path) as f:
#         schema = json.load(f)
#     return schema


# Path: habitat/tests/test_views/test_payload_telemetry.py
from ...views import payload_telemetry
from ...views.utils import read_json_schema
from couch_named_python import ForbiddenError, UnauthorizedError
from copy import deepcopy
from nose.tools import assert_raises
import json
import mox

    def test_tolerant_of_float_changes(self):
        old = deepcopy(doc)
        old['data']['value'] = 123.456
        old['data']['recurse'] = {"test_list": [0.00001, 1e20, 4.4],
                                  "value": 1.52142e10}
        
        # these changes should be allowed
        new = deepcopy(doc)
        new['data']['value'] = 123.4560000000001
        new['data']['recurse'] = \
            {"test_list": [0.000010000000000000005, 1e20 - 1e5, 4.4 - 1e-15],
             "value": 1.52142e10 + 1e-4}

        # check that they are actually different first
        assert old['data']['value'] != new['data']['value']
        assert all(old['data']['recurse']['test_list'][i] != 
                   new['data']['recurse']['test_list'][i] for i in range(3))
        assert old['data']['recurse']['value'] != \
                new['data']['recurse']['value']

        payload_telemetry.validate(new, old, {'roles': []}, {})

        # these should be outside of tolerance
        new = deepcopy(old)
        new['data']['value'] = 123.4560001
        assert_raises(UnauthorizedError, payload_telemetry.validate,
                new, old, {'roles': []}, {})

        new = deepcopy(old)
        new['data']['recurse']['test_list'][2] = 1e20 + 1e10

        assert_raises(UnauthorizedError, payload_telemetry.validate,