<s> """<STR_LIT>""" <EOL> try : <EOL> import sqlalchemy as sql <EOL> HAS_SQLALCHEMY = True <EOL> except ImportError : <EOL> HAS_SQLALCHEMY = False <EOL> try : <EOL> import psycopg2 <EOL> HAS_POSTGRES = True <EOL> except ImportError : <EOL> HAS_POSTGRES = False <EOL> try : <EOL> import _mysql <EOL> HAS_MYSQL = True <EOL> except ImportError : <EOL> HAS_MYSQL = False <EOL> import datetime <EOL> import unittest <EOL> from flask import Blueprint <EOL> from test import FlaskTrackUsageTestCase <EOL> from flask_track_usage import TrackUsage <EOL> from flask_track_usage . storage . sql import SQLStorage <EOL> @ unittest . skipUnless ( HAS_SQLALCHEMY , "<STR_LIT>" ) <EOL> class TestSQLiteStorage ( FlaskTrackUsageTestCase ) : <EOL> def _create_storage ( self ) : <EOL> engine = sql . create_engine ( "<STR_LIT>" ) <EOL> metadata = sql . MetaData ( bind = engine ) <EOL> self . storage = SQLStorage ( <EOL> engine = engine , <EOL> metadata = metadata , <EOL> table_name = self . given_table_name <EOL> ) <EOL> metadata . create_all ( ) <EOL> def tearDown ( self ) : <EOL> meta = sql . MetaData ( ) <EOL> meta . reflect ( bind = self . storage . _eng ) <EOL> for table in reversed ( meta . sorted_tables ) : <EOL> self . storage . _eng . execute ( table . delete ( ) ) <EOL> def setUp ( self ) : <EOL> self . given_table_name = '<STR_LIT>' <EOL> FlaskTrackUsageTestCase . setUp ( self ) <EOL> self . blueprint = Blueprint ( '<STR_LIT>' , __name__ ) <EOL> @ self . blueprint . route ( '<STR_LIT>' ) <EOL> def blueprint ( ) : <EOL> return "<STR_LIT>" <EOL> self . app . register_blueprint ( self . blueprint ) <EOL> self . _create_storage ( ) <EOL> self . track_usage = TrackUsage ( self . app , self . storage ) <EOL> self . track_usage . include_blueprint ( self . blueprint ) <EOL> def test_table_name ( self ) : <EOL> meta = sql . MetaData ( ) <EOL> meta . reflect ( bind = self . storage . _eng ) <EOL> assert self . given_table_name == meta . tables . keys ( ) [ <NUM_LIT:0> ] <EOL> def test_storage_data_basic ( self ) : <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> con = self . storage . _eng . connect ( ) <EOL> s = sql . select ( [ self . storage . track_table ] ) <EOL> result = con . execute ( s ) . fetchone ( ) <EOL> assert result [ <NUM_LIT:1> ] == u'<STR_LIT>' <EOL> assert result [ <NUM_LIT:2> ] is None <EOL> assert result [ <NUM_LIT:3> ] is None <EOL> assert result [ <NUM_LIT:4> ] is None <EOL> assert result [ <NUM_LIT:5> ] is None <EOL> assert result [ <NUM_LIT:6> ] is None <EOL> assert result [ <NUM_LIT:8> ] == <NUM_LIT:200> <EOL> assert result [ <NUM_LIT:9> ] is None <EOL> assert result [ <NUM_LIT:10> ] == None <EOL> assert result [ <NUM_LIT:11> ] == False <EOL> assert result [ <NUM_LIT:12> ] is None <EOL> assert result [ <NUM_LIT> ] == '<STR_LIT:/>' <EOL> assert result [ <NUM_LIT> ] . __class__ is float <EOL> assert type ( result [ <NUM_LIT:15> ] ) is datetime . datetime <EOL> def test_storage_data_blueprint ( self ) : <EOL> self . client . get ( '<STR_LIT>' ) <EOL> con = self . storage . _eng . connect ( ) <EOL> s = sql . select ( [ self . storage . track_table ] ) <EOL> result = con . execute ( s ) . fetchone ( ) <EOL> assert result [ <NUM_LIT:1> ] == u'<STR_LIT>' <EOL> assert result [ <NUM_LIT:2> ] is None <EOL> assert result [ <NUM_LIT:3> ] is None <EOL> assert result [ <NUM_LIT:4> ] is None <EOL> assert result [ <NUM_LIT:5> ] is None <EOL> assert result [ <NUM_LIT:6> ] == '<STR_LIT>' <EOL> assert result [ <NUM_LIT:8> ] == <NUM_LIT:200> <EOL> assert result [ <NUM_LIT:9> ] is None <EOL> assert result [ <NUM_LIT:10> ] is None <EOL> assert result [ <NUM_LIT:11> ] == False <EOL> assert result [ <NUM_LIT:12> ] is None <EOL> assert result [ <NUM_LIT> ] == '<STR_LIT>' <EOL> assert result [ <NUM_LIT> ] . __class__ is float <EOL> assert type ( result [ <NUM_LIT:15> ] ) is datetime . datetime <EOL> def test_storage__get_raw ( self ) : <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> result = self . storage . _get_raw ( ) [ <NUM_LIT:0> ] <EOL> assert result [ <NUM_LIT:1> ] == u'<STR_LIT>' <EOL> assert result [ <NUM_LIT:2> ] is None <EOL> assert result [ <NUM_LIT:3> ] is None <EOL> assert result [ <NUM_LIT:4> ] is None <EOL> assert result [ <NUM_LIT:5> ] is None <EOL> assert result [ <NUM_LIT:6> ] is None <EOL> assert result [ <NUM_LIT:8> ] == <NUM_LIT:200> <EOL> assert result [ <NUM_LIT:9> ] is None <EOL> assert result [ <NUM_LIT:10> ] is None <EOL> assert result [ <NUM_LIT:11> ] == False <EOL> assert result [ <NUM_LIT:12> ] is None <EOL> assert result [ <NUM_LIT> ] == '<STR_LIT:/>' <EOL> assert result [ <NUM_LIT> ] . __class__ is float <EOL> assert type ( result [ <NUM_LIT:15> ] ) is datetime . datetime <EOL> self . client . get ( '<STR_LIT>' ) <EOL> rows = self . storage . _get_raw ( ) <EOL> print rows [ <NUM_LIT:1> ] <EOL> result = rows [ <NUM_LIT:1> ] <EOL> assert result [ <NUM_LIT:1> ] == u'<STR_LIT>' <EOL> assert result [ <NUM_LIT:2> ] is None <EOL> assert result [ <NUM_LIT:3> ] is None <EOL> assert result [ <NUM_LIT:4> ] is None <EOL> assert result [ <NUM_LIT:5> ] is None <EOL> assert result [ <NUM_LIT:6> ] == '<STR_LIT>' <EOL> assert result [ <NUM_LIT:8> ] == <NUM_LIT:200> <EOL> assert result [ <NUM_LIT:9> ] is None <EOL> assert result [ <NUM_LIT:10> ] is None <EOL> assert result [ <NUM_LIT:11> ] == False <EOL> assert result [ <NUM_LIT:12> ] is None <EOL> assert result [ <NUM_LIT> ] == '<STR_LIT>' <EOL> assert result [ <NUM_LIT> ] . __class__ is float <EOL> assert type ( result [ <NUM_LIT:15> ] ) is datetime . datetime <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> assert len ( self . storage . _get_raw ( ) ) == <NUM_LIT:3> <EOL> assert len ( self . storage . _get_raw ( limit = <NUM_LIT:2> ) ) == <NUM_LIT:2> <EOL> assert len ( self . storage . _get_raw ( limit = <NUM_LIT:1> ) ) == <NUM_LIT:1> <EOL> now = datetime . datetime . utcnow ( ) + datetime . timedelta ( <NUM_LIT:0> , <NUM_LIT:5> ) <EOL> assert len ( self . storage . _get_raw ( start_date = now ) ) == <NUM_LIT:0> <EOL> assert len ( self . storage . _get_raw ( end_date = now ) ) == <NUM_LIT:3> <EOL> assert len ( self . storage . _get_raw ( end_date = now , limit = <NUM_LIT:2> ) ) == <NUM_LIT:2> <EOL> def test_storage__get_usage ( self ) : <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> result = self . storage . _get_raw ( ) [ <NUM_LIT:0> ] <EOL> result2 = self . storage . _get_usage ( ) [ <NUM_LIT:0> ] <EOL> assert result [ <NUM_LIT:1> ] == result2 [ '<STR_LIT:url>' ] <EOL> assert result [ <NUM_LIT:2> ] == result2 [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:3> ] == result2 [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:4> ] == result2 [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:5> ] == result2 [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] <EOL> assert result [ <NUM_LIT:6> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:8> ] == result2 [ '<STR_LIT:status>' ] <EOL> assert result [ <NUM_LIT:9> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:10> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:11> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:12> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT> ] == result2 [ '<STR_LIT:path>' ] <EOL> assert result [ <NUM_LIT> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:15> ] == result2 [ '<STR_LIT:date>' ] <EOL> def test_storage_get_usage ( self ) : <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> result = self . storage . _get_raw ( ) [ <NUM_LIT:0> ] <EOL> result2 = self . storage . get_usage ( ) [ <NUM_LIT:0> ] <EOL> assert result [ <NUM_LIT:1> ] == result2 [ '<STR_LIT:url>' ] <EOL> assert result [ <NUM_LIT:2> ] == result2 [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:3> ] == result2 [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:4> ] == result2 [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:5> ] == result2 [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] <EOL> assert result [ <NUM_LIT:6> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:8> ] == result2 [ '<STR_LIT:status>' ] <EOL> assert result [ <NUM_LIT:9> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:10> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:11> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:12> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT> ] == result2 [ '<STR_LIT:path>' ] <EOL> assert result [ <NUM_LIT> ] == result2 [ '<STR_LIT>' ] <EOL> assert result [ <NUM_LIT:15> ] == result2 [ '<STR_LIT:date>' ] <EOL> def test_storage_get_usage_pagination ( self ) : <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> self . client . get ( '<STR_LIT:/>' ) <EOL> limit = <NUM_LIT:10> <EOL> num_pages = <NUM_LIT:10> <EOL> for page in range ( <NUM_LIT:1> , num_pages + <NUM_LIT:1> ) : <EOL> result = self . storage . _get_usage ( limit = limit , page = page ) <EOL> assert len ( result ) == limit <EOL> result = self . storage . _get_raw ( limit = <NUM_LIT:100> ) <EOL> result2 = self . storage . get_usage ( limit = <NUM_LIT:100> ) <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> assert result [ i ] [ <NUM_LIT:1> ] == result2 [ i ] [ '<STR_LIT:url>' ] <EOL> assert result [ i ] [ <NUM_LIT:2> ] == result2 [ i ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert result [ i ] [ <NUM_LIT:3> ] == result2 [ i ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert result [ i ] [ <NUM_LIT:4> ] == result2 [ i ] [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> assert result [ i ] [ <NUM_LIT:5> ] == result2 [ i ] [ '<STR_LIT>' ] [ '<STR_LIT:version>' ] <EOL> assert result [ i ] [ <NUM_LIT:6> ] == result2 [ i ] [ '<STR_LIT>' ] <EOL> assert result [ i ] [ <NUM_LIT:8> ] == result2 [ i ] [ '<STR_LIT:status>' ] <EOL> assert result [ i ] [ <NUM_LIT:9> ] == result2 [ i ] [ '<STR_LIT>' ] <EOL> assert result [ i ] [ <NUM_LIT:10> ] == result2 [ i ] [ '<STR_LIT>' ] <EOL> assert result [ i ] [ <NUM_LIT:11> ] == result2 [ i ] [ '<STR_LIT>' ] <EOL> assert result [ i ] [ <NUM_LIT:12> ] == result2 [ i ] [ '<STR_LIT>' ] <EOL> assert result [ i ] [ <NUM_LIT> ] == result2 [ i ] [ '<STR_LIT:path>' ] <EOL> assert result [ i ] [ <NUM_LIT> ] == result2 [ i ] [ '<STR_LIT>' ] <EOL> assert result [ i ] [ <NUM_LIT:15> ] == result2 [ i ] [ '<STR_LIT:date>' ] <EOL> @ unittest . skipUnless ( HAS_POSTGRES , "<STR_LIT>" ) <EOL> @ unittest . skipUnless ( ( HAS_SQLALCHEMY ) , "<STR_LIT>" ) <EOL> class TestPostgresStorage ( TestSQLiteStorage ) : <EOL> def _create_storage ( self ) : <EOL> engine = sql . create_engine ( <EOL> "<STR_LIT>" ) <EOL> metadata = sql . MetaData ( bind = engine ) <EOL> self . storage = SQLStorage ( <EOL> engine = engine , <EOL> metadata = metadata , <EOL> table_name = self . given_table_name <EOL> ) <EOL> metadata . create_all ( ) <EOL> @ unittest . skipUnless ( HAS_MYSQL , "<STR_LIT>" ) <EOL> @ unittest . skipUnless ( ( HAS_SQLALCHEMY ) , "<STR_LIT>" ) <EOL> class TestMySQLStorage ( TestSQLiteStorage ) : <EOL> def _create_storage ( self ) : <EOL> engine = sql . create_engine ( <EOL> "<STR_LIT>" ) <EOL> metadata = sql . MetaData ( bind = engine ) <EOL> self . storage = SQLStorage ( <EOL> engine = engine , <EOL> metadata = metadata , <EOL> table_name = self . given_table_name <EOL> ) <EOL> metadata . create_all ( ) </s>
