<s> from active_alchemy import SQLAlchemy <EOL> import unittest <EOL> table_name = "<STR_LIT>" <EOL> class TestActiveSqlAlchemy ( unittest . TestCase ) : <EOL> @ staticmethod <EOL> def create_test_model ( db ) : <EOL> class TestModel ( db . Model ) : <EOL> name = db . Column ( db . String ( <NUM_LIT:20> ) ) <EOL> location = db . Column ( db . String ( <NUM_LIT:20> ) ) <EOL> db . create_all ( ) <EOL> return TestModel <EOL> def setUp ( self ) : <EOL> uri = '<STR_LIT>' <EOL> self . db = SQLAlchemy ( uri ) <EOL> self . model = self . create_test_model ( self . db ) <EOL> def tearDown ( self ) : <EOL> self . db . query ( self . model ) . delete ( ) <EOL> self . db . commit ( ) <EOL> def add_entry ( self ) : <EOL> return self . model ( name = "<STR_LIT>" , location = "<STR_LIT>" ) . save ( ) <EOL> def test_init_save ( self ) : <EOL> e = self . add_entry ( ) <EOL> self . assertIsNotNone ( e ) <EOL> def test_table_name ( self ) : <EOL> self . assertEquals ( table_name , self . model . __table__ . name ) <EOL> def test_create ( self ) : <EOL> data = { <EOL> "<STR_LIT:name>" : "<STR_LIT>" , <EOL> "<STR_LIT:location>" : "<STR_LIT>" <EOL> } <EOL> self . assertIs ( <NUM_LIT:0> , len ( list ( self . model . all ( ) ) ) ) <EOL> v = self . add_entry ( ) <EOL> self . assertIs ( <NUM_LIT:1> , len ( list ( self . model . all ( ) ) ) ) <EOL> e = v . create ( ** data ) <EOL> self . assertIsNotNone ( e ) <EOL> self . assertIs ( <NUM_LIT:2> , len ( list ( self . model . all ( ) ) ) ) <EOL> e . update ( location = "<STR_LIT>" ) <EOL> self . assertEquals ( e . location , "<STR_LIT>" ) <EOL> def test_update ( self ) : <EOL> n_loc = "<STR_LIT>" <EOL> e = self . add_entry ( ) <EOL> e . update ( location = n_loc ) <EOL> self . assertEqual ( n_loc , e . location ) <EOL> def test_delete ( self ) : <EOL> e = self . add_entry ( ) <EOL> e . delete ( ) <EOL> self . assertTrue ( e . is_deleted ) <EOL> def test_undelete ( self ) : <EOL> e = self . add_entry ( ) <EOL> e . delete ( ) <EOL> self . assertTrue ( e . is_deleted ) <EOL> e . delete ( False ) <EOL> self . assertFalse ( e . is_deleted ) <EOL> def test_delete_hard ( self ) : <EOL> e = self . add_entry ( ) <EOL> self . assertIs ( <NUM_LIT:1> , len ( list ( self . model . all ( ) ) ) ) <EOL> e . delete ( hard_delete = True ) <EOL> self . assertIs ( <NUM_LIT:0> , len ( list ( self . model . all ( include_deleted = True ) ) ) ) <EOL> def test_get ( self ) : <EOL> e = self . add_entry ( ) <EOL> self . assertIsNotNone ( self . model . get ( e . id ) ) <EOL> def test_get_deleted ( self ) : <EOL> e = self . add_entry ( ) . delete ( ) <EOL> self . assertIsNone ( self . model . get ( e . id ) ) <EOL> self . assertIsNotNone ( self . model . get ( e . id , include_deleted = True ) ) <EOL> def test_all ( self ) : <EOL> self . add_entry ( ) <EOL> self . add_entry ( ) <EOL> self . add_entry ( ) <EOL> self . add_entry ( ) <EOL> self . add_entry ( ) <EOL> self . assertIs ( <NUM_LIT:5> , len ( list ( self . model . all ( ) ) ) ) <EOL> def test_all_but_deleted ( self ) : <EOL> self . add_entry ( ) <EOL> self . add_entry ( ) <EOL> self . add_entry ( ) . delete ( ) <EOL> self . add_entry ( ) . delete ( ) <EOL> self . add_entry ( ) <EOL> self . assertIs ( <NUM_LIT:3> , len ( list ( self . model . all ( ) ) ) ) <EOL> def test_all_but_undeleted ( self ) : <EOL> self . add_entry ( ) <EOL> self . add_entry ( ) <EOL> self . add_entry ( ) . delete ( ) <EOL> self . add_entry ( ) . delete ( ) . delete ( False ) <EOL> self . add_entry ( ) <EOL> self . assertIs ( <NUM_LIT:4> , len ( list ( self . model . all ( ) ) ) ) <EOL> self . assertIs ( <NUM_LIT:5> , len ( list ( self . model . all ( include_deleted = True ) ) ) ) <EOL> def test_to_dict ( self ) : <EOL> e = self . add_entry ( ) <EOL> self . assertIsInstance ( e . to_dict ( ) , dict ) <EOL> def test_to_json ( self ) : <EOL> e = self . add_entry ( ) <EOL> self . assertIsInstance ( e . to_json ( ) , str ) <EOL> def test_all_distinct ( self ) : <EOL> for n in xrange ( <NUM_LIT:15> ) : <EOL> self . add_entry ( ) <EOL> es = self . model . all ( self . model . name . distinct ( ) ) <EOL> self . assertIs ( <NUM_LIT:1> , len ( list ( es ) ) ) <EOL> def test_paginate ( self ) : <EOL> for n in xrange ( <NUM_LIT:15> ) : <EOL> self . add_entry ( ) <EOL> es = self . model . all ( ) . paginate ( page = <NUM_LIT:2> , per_page = <NUM_LIT:4> ) <EOL> self . assertIs ( <NUM_LIT:4> , es . total_pages ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
