Пример #1
0
    def test_empty(self):
        """Raise on empty input - data/empty.json."""
        empty_path = os.path.join(self._TEST_DATA_DIR, 'empty.json')

        with pytest.raises(UnknownStatementError):
            with open(empty_path, 'r') as f:
                json2sql(f)
Пример #2
0
 def test_insert_json2sql(self):
     """Test INSERT RETURNING."""
     result = json2sql(table='person',
                       statement='insert',
                       columns=('person_id', 'name'),
                       values=('mosky', 'Mosky Liu'))
     assert result == "INSERT INTO \"person\" (\"person_id\", \"name\") VALUES (\'mosky\', \'Mosky Liu\')"
Пример #3
0
 def test_delete_json2sql(self):
     """Test DELETE using json2sql()."""
     result = json2sql({
         'table': 'person',
         'statement': 'delete',
         'where': {
             'person_id': 'mosky'
         }
     })
     assert result == "DELETE FROM \"person\" WHERE \"person_id\" = 'mosky'"
Пример #4
0
 def test_update_kwargs(self):
     """Test UPDATE using json2sql."""
     result = json2sql(table='person', statement='update', where={'person_id': 'mosky'}, set={'name': 'Mosky Liu'})
     assert result == 'UPDATE "person" SET "name"=\'Mosky Liu\' WHERE "person_id" = \'mosky\''
Пример #5
0
 def test_replace_json2sql(self):
     """Test replace."""
     result = json2sql(table='person',
                       statement='replace',
                       set=[['name', 'Milan'], ('age', 42)])
     assert result == "REPLACE INTO \"person\" (\"name\", \"age\") VALUES ('Milan', 42)"
Пример #6
0
 def test_no_statement(self):
     """Test no statement error."""
     with pytest.raises(NoStatementError):
         json2sql(table='person',
                  columns=('person_id', 'name'),
                  values=('mosky', 'Mosky Liu'))