def test_can_be_output_as_string(self): query = InsertQuery(self.db).table(Trainer).from_dicts({ 'name': 'Giovanni', 'age': 42 }) expected = "(INSERT INTO trainer (age, name) VALUES (?, ?))" assert str(query) == expected
def add_pokemon(self, names): try: names = names.split() except: pass for name in names: InsertQuery(self.db).table(Pokemon).from_dicts( self.POKEMONS[name]).execute()
def add_trainer(self, names): try: names = names.split() except: pass for name in names: InsertQuery(self.db).table(Trainer).from_dicts( self.TRAINERS[name]).execute()
def add_attack(self, names): try: names = names.split() except: pass for name in names: InsertQuery(self.db).table(Attack).from_dicts( self.ATTACKS[name]).execute()
def test_can_select_with_exists_return_true(self): InsertQuery(self.db).table(Trainer).from_dicts({ 'name': 'Giovanni', 'age': 42 }).execute() result = SelectQuery(self.db).select( SelectQuery(self.db).tables(Trainer).exists()).execute() expected = 1 assert result[0][0] == expected
def test_can_insert_one_row_from_dict(self): ngiovanni = Trainer._db._connection.execute( "SELECT count(name) FROM trainer WHERE name = 'Giovanni'" ).fetchone() assert ngiovanni[0] == 0 InsertQuery(self.db).table(Trainer).from_dicts({ 'name': 'Giovanni', 'age': 42 }).execute() ngiovanni = Trainer._db._connection.execute( "SELECT count(name) FROM trainer WHERE name = 'Giovanni'" ).fetchone() assert ngiovanni[0] == 1
def test_result_order_by_several_fields_with_sort_order(self): InsertQuery(self.db).table(Trainer).from_dicts([{ 'name': 'Jessie', 'age': 17 }, { 'name': 'Giovanni', 'age': 66 }, { 'name': 'Giovanni', 'age': 42 }]).execute() result = (SelectQuery(self.db).select( Trainer.name, Trainer.age).tables(Trainer).order_by( Trainer.name.asc(), Trainer.age.desc()).execute()) assert result == [('Giovanni', 66), ('Giovanni', 42), ('Jessie', 17)]
def test_can_insert_many_rows_from_dict(self): ntrainers = Trainer._db._connection.execute( "SELECT count(name) FROM trainer WHERE name = 'Giovanni' OR name = 'James'" ).fetchone() assert ntrainers[0] == 0 InsertQuery(self.db).table(Trainer).from_dicts([{ 'name': 'Giovanni', 'age': 42 }, { 'name': 'James', 'age': 21 }]).execute() ngiovanni = Trainer._db._connection.execute( "SELECT count(name) FROM trainer WHERE name = 'Giovanni' OR name = 'James'" ).fetchone() assert ngiovanni[0] == 2
def test_can_specify_table(self): assert hasattr(InsertQuery(self.db), 'table') is True
def test_can_specify_dict_values(self): assert hasattr(InsertQuery(self.db), 'from_dicts') is True
def test_can_specify_fields_to_insert(self): assert hasattr(InsertQuery(self.db), 'fields') is True
def test_attributes(self): expected = ('_db', '_fields', '_table', '_values') result = InsertQuery(self.db).__slots__ assert result == expected
def test_is_slotted(self): with pytest.raises(AttributeError): InsertQuery(Trainer).__dict__