<commit_before>from unittest import TestCase
from webtest import TestApp

from ichnaea import main
from ichnaea.db import Cell, Measure
from ichnaea.renderer import dump_decimal_json


def _make_app():
    global_config = {}
    wsgiapp = main(global_config, celldb='sqlite://', measuredb='sqlite://')
    return TestApp(wsgiapp)


class TestSearch(TestCase):

    def test_ok(self):
        app = _make_app()
        session = app.app.registry.celldb.session()
        cell = Cell()
        cell.lat = 12345678
        cell.lon = 23456789
        cell.mcc = 123
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        session.add(cell)
        session.commit()

        res = app.post_json('/v1/search',
            {"cell": [{"mcc": 123, "mnc": 1, "lac": 2, "cid": 1234}]},
            status=200)
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.body, '{"status": "ok", "lat": 12.345678, '
            '"lon": 23.456789, "accuracy": 20000}')

    def test_not_found(self):
        app = _make_app()
        res = app.post_json('/v1/search',
            {"cell": [{"mcc": 1, "mnc": 2, "lac": 3, "cid": 4}]},
            status=200)<commit_msg>add test for wifi not_found case<commit_after>from unittest import TestCase
from webtest import TestApp

from ichnaea import main
from ichnaea.db import Cell, Measure
from ichnaea.renderer import dump_decimal_json


def _make_app():
    global_config = {}
    wsgiapp = main(global_config, celldb='sqlite://', measuredb='sqlite://')
    return TestApp(wsgiapp)


class TestSearch(TestCase):

    def test_ok(self):
        app = _make_app()
        session = app.app.registry.celldb.session()
        cell = Cell()
        cell.lat = 12345678
        cell.lon = 23456789
        cell.mcc = 123
        cell.mnc = 1
        cell.lac = 2
        cell.cid = 1234
        session.add(cell)
        session.commit()

        res = app.post_json('/v1/search',
            {"cell": [{"mcc": 123, "mnc": 1, "lac": 2, "cid": 1234}]},
            status=200)
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.body, '{"status": "ok", "lat": 12.345678, '
            '"lon": 23.456789, "accuracy": 20000}')

    def test_not_found(self):
        app = _make_app()
        res = app.post_json('/v1/search',
            {"cell": [{"mcc": 1, "mnc": 2, "lac": 3, "cid": 4}]},
            status=200)
        self.assertEqual(res.content_type, 'application/json')
        self.assertEqual(res.body, '{"status": "not_found"}')

    def test_wifi_not_found(self):
        app = _make_app()
        res = app.post_json('/v1/search',
            {"wifi": [{"bssid": "ab:cd:12:34"}]},
            status=200)
{'fraction_non_alphanumeric': 0.15362106803218728, 'fraction_numerical': 0.05193855157278712, 'mean_word_length': 2.410224438902743, 'pattern_counts': {'":': 31, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7361968', 'n_tokens_mistral': 1041, 'n_tokens_neox': 920, 'n_words': 205}