Projet

Général

Profil

0001-engine-format-where-sql-condition-string-47766.patch

Nicolas Roche, 06 novembre 2020 14:27

Télécharger (2,96 ko)

Voir les différences:

Subject: [PATCH] engine: format where sql condition string (#47766)

 bijoe/engine.py       |  1 +
 tests/test_schema1.py | 27 +++++++++++++++++++++++++++
 2 files changed, 28 insertions(+)
bijoe/engine.py
416 416
            sql = 'SELECT ' + ', '.join(projections)
417 417
            table_expression = ' %s' % self.cube.fact_table
418 418
            if joins:
419 419
                table_expression = self.build_table_expression(joins, self.fact_table)
420 420
            sql += ' FROM %s' % table_expression
421 421
            where_conditions = 'true'
422 422
            if where:
423 423
                where_conditions = ' AND '.join(where)
424
                where_conditions = where_conditions.format(fact_table=self.cube.fact_table)
424 425
                sql += ' WHERE %s' % where_conditions
425 426
            if group_by:
426 427
                sql += ' GROUP BY %s' % ', '.join(group_by)
427 428
            if order_by:
428 429
                sql += ' ORDER BY %s' % ', '.join(order_by)
429 430
            sql = sql.format(fact_table=self.cube.fact_table,
430 431
                             table_expression=table_expression,
431 432
                             where_conditions=where_conditions)
tests/test_schema1.py
372 372
    form.set('filter__a', ['x', 'y'])
373 373
    response = form.submit('visualize')
374 374
    assert get_table(response) == [
375 375
        ['A', 'x', 'y', 'z'],
376 376
        ['number of rows', '7', '9', '0']
377 377
    ]
378 378

  
379 379

  
380
def test_json_dimensions_having_percent(schema1, app, admin):
381
    login(app, admin)
382
    response = app.get('/')
383
    response = response.click('schema1')
384
    response = response.click('Facts 1')
385
    form = response.form
386

  
387
    form.set('representation', 'table')
388
    form.set('measure', 'percent')
389
    form.set('drilldown_x', 'a')
390
    response = form.submit('visualize')
391
    assert get_table(response) == [
392
        ['A', 'x', 'y', 'z'],
393
        ['pourcentage des demandes', '41,18 %', '52,94 %', '5,88 %']
394
    ]
395

  
396
    assert 'filter__a' in form.fields
397
    assert set([o[0] for o in form['filter__a'].options]) == {'x', 'y', 'z', '__none__'}
398

  
399
    form.set('filter__a', ['x', 'y'])
400
    response = form.submit('visualize')
401
    assert get_table(response) == [
402
        ['A', 'x', 'y', 'z'],
403
        ['pourcentage des demandes', '43,75 %', '56,25 %', '0,00 %']
404
    ]
405

  
406

  
380 407
def test_sum_integer_measure(schema1, app, admin):
381 408
    login(app, admin)
382 409
    response = app.get('/')
383 410
    response = response.click('schema1')
384 411
    response = response.click('Facts 1')
385 412
    form = response.form
386 413
    form.set('representation', 'table')
387 414
    form.set('measure', 'sum_integer')
388
-