def test_db_config(self): self.db_master = _make_db() self.db_slave = _make_db(create=False) self.setup_session() app = _make_app(_db_master=self.db_master, _db_slave=self.db_slave, _heka_client=get_client('ichnaea')) app.get('/stats_location.json', status=200)
def test_db_config(self): self.db_master = _make_db() self.db_slave = _make_db() self.setup_session() app = _make_app(_db_master=self.db_master, _db_slave=self.db_slave, _heka_client=self.heka_client) app.get('/stats_unique_cell.json', status=200)
def test_db_config(self): self.db_rw = _make_db() self.db_ro = _make_db() self.setup_session() app = _make_app(_db_rw=self.db_rw, _db_ro=self.db_ro, _raven_client=self.raven_client, _redis_client=self.redis_client, _stats_client=self.stats_client, ) app.get('/stats_wifi.json', status=200)
def test_db_config(self): self.db_master = _make_db() self.db_slave = _make_db() self.setup_session() app = _make_app(_db_master=self.db_master, _db_slave=self.db_slave, _heka_client=self.heka_client, _stats_client=self.stats_client, _redis=self.redis_client, ) app.get('/stats_wifi.json', status=200)
def test_db_config(self): self.db_rw = _make_db() self.db_ro = _make_db() self.setup_session() app = _make_app(_db_rw=self.db_rw, _db_ro=self.db_ro, _raven_client=self.raven_client, _stats_client=self.stats_client, _redis=self.redis_client, ) app.get('/stats_wifi.json', status=200)
def test_db_config(self): self.db_master = _make_db() self.db_slave = _make_db() self.setup_session() app = _make_app( _db_master=self.db_master, _db_slave=self.db_slave, _heka_client=self.heka_client, _stats_client=self.stats_client, _redis=self.redis_client, ) app.get('/stats_wifi.json', status=200)
def test_db_hooks(self): db_rw = _make_db() db_ro = _make_db() app = _make_app(_db_rw=db_rw, _db_ro=db_ro, _raven_client=self.raven_client, _redis_client=self.redis_client, _stats_client=self.stats_client, ) # check that our _db hooks are passed through self.assertTrue(app.app.registry.db_rw is db_rw) self.assertTrue(app.app.registry.db_ro is db_ro)
def test_files(self): today = util.utcnow().date() rows = [ dict(time=today, lat=12.345, lon=12.345), dict(time=today, lat=0, lon=12.345), dict(time=today, lat=-10.000, lon=-11.000), ] for row in rows: lat, lon = DataMap.scale(row['lat'], row['lon']) data = DataMap.shard_model(lat, lon)( grid=(lat, lon), created=row['time'], modified=row['time']) self.session.add(data) self.session.flush() lines = [] rows = 0 with util.selfdestruct_tempdir() as temp_dir: quaddir = os.path.join(temp_dir, 'quadtrees') os.mkdir(quaddir) shapes = os.path.join(temp_dir, 'shapes') tiles = os.path.join(temp_dir, 'tiles') for shard_id, shard in DataMap.shards().items(): filename = 'map_%s.csv.gz' % shard_id filepath = os.path.join(temp_dir, filename) result = export_file( None, filepath, shard.__tablename__, _db_rw=_make_db(), _session=self.session) if not result: self.assertFalse(os.path.isfile(filepath)) continue rows += result with util.gzip_open(filepath, 'r') as fd: written = fd.read() lines.extend([line.split(',') for line in written.split()]) encode_file(filename, temp_dir, quaddir, DATAMAPS_DIR) quadfolder = os.path.join(quaddir, 'map_' + shard_id) self.assertTrue(os.path.isdir(quadfolder)) self._check_quadtree(quadfolder) merge_files(quaddir, shapes, DATAMAPS_DIR) self._check_quadtree(shapes) render_tiles(shapes, tiles, 1, 2, DATAMAPS_DIR, PNGQUANT) self.assertEqual(sorted(os.listdir(tiles)), ['0', '1', '2']) self.assertEqual(sorted(os.listdir(os.path.join(tiles, '0', '0'))), ['0.png', '*****@*****.**']) self.assertEqual(rows, 36) self.assertEqual(len(lines), 36) self.assertEqual(set([round(float(l[0]), 2) for l in lines]), set([-10.0, 0.0, 12.35])) self.assertEqual(set([round(float(l[1]), 2) for l in lines]), set([-11.0, 12.35]))
def test_database_error(self): # self.app is a class variable, so we keep this test in # its own class to avoid isolation problems # create a database connection to the discard port self.app.app.registry.db_ro = _make_db( uri='mysql+pymysql://none:[email protected]:9/test_location') res = self.app.get('/__heartbeat__', status=200) self.assertEqual(res.content_type, 'application/json') self.assertEqual(res.json['status'], 'OK')
def test_database_error(self): # self.app is a class variable, so we keep this test in # its own class to avoid isolation problems app = self.app # create a database connection to the discard port self.app.app.registry.db_slave = _make_db( uri='mysql+pymysql://none:[email protected]:9/test_location') res = app.get('/__heartbeat__', status=503) self.assertEqual(res.content_type, 'text/plain')
def setUp(self): super(TestMonitorErrors, self).setUp() # create database connections to the discard port db_uri = 'mysql+pymysql://none:[email protected]:9/none' self.broken_db = _make_db(uri=db_uri) self.app.app.registry.db_rw = self.broken_db self.app.app.registry.db_ro = self.broken_db # create broken geoip db self.app.app.registry.geoip_db = GeoIPNull() # create broken redis connection redis_uri = 'redis://127.0.0.1:9/15' self.broken_redis = _make_redis(redis_uri) self.app.app.registry.redis_client = self.broken_redis
def setUp(self): super(TestMonitorErrors, self).setUp() # create database connections to the discard port db_uri = 'mysql+pymysql://none:[email protected]:9/none' self.broken_db = _make_db(uri=db_uri) self.app.app.registry.db_master = self.broken_db self.app.app.registry.db_slave = self.broken_db # create broken geoip db self.app.app.registry.geoip_db = GeoIPNull() # create broken redis connection redis_uri = 'redis://127.0.0.1:9/15' self.broken_redis = _make_redis(redis_uri) self.app.app.registry.redis_client = self.broken_redis # create broken stats client self.broken_stats = PingableStatsClient(host='127.0.0.1', port=0) self.app.app.registry.stats_client = self.broken_stats
def setUp(self): self.db = _make_db() # capture state of fresh database self.head_metadata = self.inspect_db() DBIsolation.cleanup_tables(self.db.engine)
def setUp(self): super(MigrationTest, self).setUp() self.db = _make_db() # capture state of fresh database self.head_metadata = self.inspect_db() DBTestCase.cleanup_tables(self.db.engine)
#!/usr/bin/env python from IPython.config.loader import Config from IPython.terminal.embed import InteractiveShellEmbed from ichnaea.tests.base import _make_db import os from os.path import split, abspath import sys thisfile = abspath(__file__) ichnaea_root = split(split(thisfile)[0])[0] sys.path.append(ichnaea_root) SQLURI = os.environ.get('SQLURI') db = _make_db(SQLURI) session = db.session() ipshell = InteractiveShellEmbed( config=Config(), banner1='Dropping into IPython', exit_msg='Leaving Interpreter, back to program.') ipshell()
def test_files(self): today = util.utcnow().date() rows = [ dict(time=today, lat=12.345, lon=12.345), dict(time=today, lat=0, lon=12.345), dict(time=today, lat=-10.000, lon=-11.000), ] for row in rows: lat, lon = DataMap.scale(row['lat'], row['lon']) data = DataMap.shard_model(lat, lon)(grid=(lat, lon), created=row['time'], modified=row['time']) self.session.add(data) self.session.flush() lines = [] rows = 0 with util.selfdestruct_tempdir() as temp_dir: quaddir = os.path.join(temp_dir, 'quadtrees') os.mkdir(quaddir) shapes = os.path.join(temp_dir, 'shapes') tiles = os.path.join(temp_dir, 'tiles') for shard_id, shard in DataMap.shards().items(): filename = 'map_%s.csv.gz' % shard_id filepath = os.path.join(temp_dir, filename) result = export_file(None, filepath, shard.__tablename__, _db_rw=_make_db(), _session=self.session) if not result: self.assertFalse(os.path.isfile(filepath)) continue rows += result with util.gzip_open(filepath, 'r') as fd: written = fd.read() lines.extend([line.split(',') for line in written.split()]) encode_file(filename, temp_dir, quaddir, DATAMAPS_DIR) quadfolder = os.path.join(quaddir, 'map_' + shard_id) self.assertTrue(os.path.isdir(quadfolder)) self._check_quadtree(quadfolder) merge_files(quaddir, shapes, DATAMAPS_DIR) self._check_quadtree(shapes) render_tiles(shapes, tiles, 1, 2, DATAMAPS_DIR, PNGQUANT) self.assertEqual(sorted(os.listdir(tiles)), ['0', '1', '2']) self.assertEqual(sorted(os.listdir(os.path.join(tiles, '0', '0'))), ['0.png', '*****@*****.**']) self.assertEqual(rows, 36) self.assertEqual(len(lines), 36) self.assertEqual(set([round(float(l[0]), 2) for l in lines]), set([-10.0, 0.0, 12.35])) self.assertEqual(set([round(float(l[1]), 2) for l in lines]), set([-11.0, 12.35]))
def test_db_config(self): self.db_master = _make_db() self.db_slave = _make_db(create=False) self.setup_session() app = _make_app(_db_master=self.db_master, _db_slave=self.db_slave) app.get('/stats_location.json', status=200)