Exemplo n.º 1
0
 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
Exemplo n.º 2
0
    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()
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
    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()
Exemplo n.º 5
0
    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
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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)]
Exemplo n.º 8
0
    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
Exemplo n.º 9
0
 def test_can_specify_table(self):
     assert hasattr(InsertQuery(self.db), 'table') is True
Exemplo n.º 10
0
 def test_can_specify_dict_values(self):
     assert hasattr(InsertQuery(self.db), 'from_dicts') is True
Exemplo n.º 11
0
 def test_can_specify_fields_to_insert(self):
     assert hasattr(InsertQuery(self.db), 'fields') is True
Exemplo n.º 12
0
 def test_attributes(self):
     expected = ('_db', '_fields', '_table', '_values')
     result = InsertQuery(self.db).__slots__
     assert result == expected
Exemplo n.º 13
0
 def test_is_slotted(self):
     with pytest.raises(AttributeError):
         InsertQuery(Trainer).__dict__