Skip to content

Commit b9a86d0

Browse files
authored
Merge pull request #2435 from lonvia/bdd-select-step
Bdd select step
2 parents 775beff + 69739e8 commit b9a86d0

File tree

5 files changed

+139
-94
lines changed

5 files changed

+139
-94
lines changed

tests/bdd/environment.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ def before_scenario(context, scenario):
122122
context.geometry_factory = GeometryFactory()
123123
context.osm2pgsql_replication.ReplicationServer = ReplicationServerMock()
124124
context.urlrequest_responses = {}
125+
context.sql_statements = {}
125126

126127
def _mock_urlopen(request):
127128
if not request.full_url in context.urlrequest_responses:
@@ -153,10 +154,3 @@ def test_db(context, **kwargs):
153154
def working_directory(context, **kwargs):
154155
with tempfile.TemporaryDirectory() as tmpdir:
155156
yield Path(tmpdir)
156-
157-
158-
def before_tag(context, tag):
159-
if tag == 'needs-pg-index-includes':
160-
if context.config.userdata['PG_VERSION'] < 110000:
161-
context.scenario.skip("No index includes in PostgreSQL < 11")
162-

tests/bdd/flex/delete-callbacks.feature

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,29 @@ Feature: Test for delete callbacks
2727

2828
Given the input file '008-ch.osc.gz'
2929

30+
Given the SQL statement grouped_counts
31+
"""
32+
SELECT osm_type,
33+
count(*),
34+
sum(extra) AS sum_extra,
35+
sum(osm_id) AS sum_osm_id
36+
FROM change
37+
GROUP BY osm_type
38+
"""
39+
3040
Scenario: Delete callbacks are called
3141
When running osm2pgsql flex with parameters
3242
| --slim | -a |
33-
34-
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
35-
| osm_type | count | sum |
36-
| N | 16773 | 16779 |
37-
| W | 4 | 9 |
38-
| R | 1 | 3 |
43+
Then statement grouped_counts returns exactly
44+
| osm_type | count | sum_extra |
45+
| N | 16773 | 16779 |
46+
| W | 4 | 9 |
47+
| R | 1 | 3 |
3948

4049
When running osm2pgsql flex with parameters
4150
| --slim | -a |
42-
43-
Then SELECT osm_type, count(*), sum(osm_id) FROM change GROUP BY osm_type
44-
| osm_type | count | sum |
51+
Then statement grouped_counts returns exactly
52+
| osm_type | count | sum_osm_id |
4553
| N | 16773 | 37856781001834 |
4654
| W | 4 | 350933407 |
4755
| R | 1 | 2871571 |
@@ -72,8 +80,8 @@ Feature: Test for delete callbacks
7280
"""
7381
When running osm2pgsql flex with parameters
7482
| --slim | -a |
75-
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
76-
| osm_type | count | sum |
83+
Then statement grouped_counts returns exactly
84+
| osm_type | count | sum_extra |
7785
| N | 16773 | 16773 |
7886
| W | 4 | 4 |
7987
| R | 1 | 1 |
@@ -105,8 +113,8 @@ Feature: Test for delete callbacks
105113
"""
106114
When running osm2pgsql flex with parameters
107115
| --slim | -a |
108-
Then SELECT osm_type, count(*), sum(extra) FROM change GROUP BY osm_type
109-
| osm_type | count | sum |
116+
Then statement grouped_counts returns exactly
117+
| osm_type | count | sum_extra |
110118
| N | 16773 | 16773|
111119
| W | 4 | 4|
112120
| R | 1 | 1|

tests/bdd/flex/lua-index-definitions.feature

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
Feature: Index definitions in Lua file
22

3+
Background:
4+
Given the SQL statement mytable_indexes
5+
"""
6+
SELECT indexdef, indisprimary as is_primary
7+
FROM pg_catalog.pg_index, pg_catalog.pg_indexes
8+
WHERE schemaname = 'public'
9+
AND tablename = 'mytable'
10+
AND indrelid = tablename::regclass
11+
AND indexrelid = indexname::regclass
12+
"""
13+
314
Scenario: Indexes field in table definition must be an array
415
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
516
And the lua style
@@ -36,9 +47,9 @@ Feature: Index definitions in Lua file
3647
})
3748
"""
3849
When running osm2pgsql flex
39-
Then SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable' AND indexdef LIKE '%USING gist (geom)%'
40-
| schemaname | tablename |
41-
| public | mytable |
50+
Then statement mytable_indexes returns
51+
| indexdef@substr |
52+
| USING gist (geom) |
4253

4354
Scenario: Empty indexes field in table definition gets you no index
4455
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -56,8 +67,8 @@ Feature: Index definitions in Lua file
5667
})
5768
"""
5869
When running osm2pgsql flex
59-
Then SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable'
60-
| schemaname | tablename |
70+
Then statement mytable_indexes returns exactly
71+
| indexdef |
6172

6273
Scenario: Explicitly setting an index column works
6374
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -77,9 +88,9 @@ Feature: Index definitions in Lua file
7788
})
7889
"""
7990
When running osm2pgsql flex
80-
Then SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable' AND indexdef LIKE '%USING btree (name)%'
81-
| schemaname | tablename |
82-
| public | mytable |
91+
Then statement mytable_indexes returns
92+
| indexdef@substr |
93+
| USING btree (name) |
8394

8495
Scenario: Explicitly setting multiple indexes
8596
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -101,15 +112,11 @@ Feature: Index definitions in Lua file
101112
})
102113
"""
103114
When running osm2pgsql flex
104-
Then SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable' AND indexdef LIKE '%USING btree (name)%'
105-
| schemaname | tablename |
106-
| public | mytable |
107-
And SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable' AND indexdef LIKE '%USING gist (geom)%'
108-
| schemaname | tablename |
109-
| public | mytable |
110-
And SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable' AND indexdef LIKE '%USING btree (name, tags)%'
111-
| schemaname | tablename |
112-
| public | mytable |
115+
Then statement mytable_indexes returns exactly
116+
| indexdef@substr |
117+
| USING btree (name) |
118+
| USING gist (geom) |
119+
| USING btree (name, tags) |
113120

114121
Scenario: Method can not be missing
115122
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -244,11 +251,10 @@ Feature: Index definitions in Lua file
244251
})
245252
"""
246253
When running osm2pgsql flex
247-
Then SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable' AND indexdef LIKE '%USING btree (lower(name))%'
248-
| schemaname | tablename |
249-
| public | mytable |
254+
Then statement mytable_indexes returns
255+
| indexdef@substr |
256+
| USING btree (lower(name)) |
250257

251-
@needs-pg-index-includes
252258
Scenario: Include field must be a string or array
253259
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
254260
And the lua style
@@ -272,7 +278,6 @@ Feature: Index definitions in Lua file
272278
The 'include' field in an index definition must contain a string or an array.
273279
"""
274280

275-
@needs-pg-index-includes
276281
Scenario: Include field must contain a valid column
277282
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
278283
And the lua style
@@ -296,7 +301,6 @@ Feature: Index definitions in Lua file
296301
Unknown column 'foo' in table 'mytable'.
297302
"""
298303

299-
@needs-pg-index-includes
300304
Scenario: Include field works with string
301305
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
302306
And the lua style
@@ -315,11 +319,10 @@ Feature: Index definitions in Lua file
315319
})
316320
"""
317321
When running osm2pgsql flex
318-
Then SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable' AND indexdef LIKE '%USING btree (name)%' AND indexdef LIKE '%INCLUDE (tags)%'
319-
| schemaname | tablename |
320-
| public | mytable |
322+
Then statement mytable_indexes returns
323+
| indexdef@substr |
324+
| USING btree (name) INCLUDE (tags) |
321325

322-
@needs-pg-index-includes
323326
Scenario: Include field works with array
324327
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
325328
And the lua style
@@ -338,9 +341,9 @@ Feature: Index definitions in Lua file
338341
})
339342
"""
340343
When running osm2pgsql flex
341-
Then SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable' AND indexdef LIKE '%USING btree (name)%' AND indexdef LIKE '%INCLUDE (tags)%'
342-
| schemaname | tablename |
343-
| public | mytable |
344+
Then statement mytable_indexes returns
345+
| indexdef@substr |
346+
| USING btree (name) INCLUDE (tags) |
344347

345348
Scenario: Tablespace needs a string
346349
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -383,9 +386,9 @@ Feature: Index definitions in Lua file
383386
})
384387
"""
385388
When running osm2pgsql flex
386-
Then SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable' AND indexdef LIKE '%USING btree (name)%'
387-
| schemaname | tablename |
388-
| public | mytable |
389+
Then statement mytable_indexes returns
390+
| indexdef@substr |
391+
| USING btree (name) |
389392

390393
Scenario: Unique needs a boolean
391394
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -428,9 +431,9 @@ Feature: Index definitions in Lua file
428431
})
429432
"""
430433
When running osm2pgsql flex
431-
Then SELECT schemaname, tablename FROM pg_catalog.pg_indexes WHERE tablename = 'mytable' AND indexdef LIKE '%USING btree (name)%' AND indexdef LIKE '%UNIQUE%'
432-
| schemaname | tablename |
433-
| public | mytable |
434+
Then statement mytable_indexes returns
435+
| indexdef@fullmatch |
436+
| .*UNIQUE.*USING btree \(name\).* |
434437

435438
Scenario: Where condition needs a string
436439
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -473,9 +476,9 @@ Feature: Index definitions in Lua file
473476
})
474477
"""
475478
When running osm2pgsql flex
476-
Then table pg_catalog.pg_indexes contains
477-
| schemaname | tablename | indexdef@fullmatch |
478-
| public | mytable | .*USING btree \(name\).*WHERE \(name = lower\(name\)\).* |
479+
Then statement mytable_indexes returns
480+
| indexdef@substr |
481+
| USING btree (name) WHERE (name = lower(name)) |
479482

480483

481484
Scenario: Don't create id index if the configuration doesn't mention it
@@ -493,9 +496,9 @@ Feature: Index definitions in Lua file
493496
})
494497
"""
495498
When running osm2pgsql flex
496-
Then table pg_catalog.pg_indexes doesn't contain
497-
| schemaname | tablename | indexname@fullmatch |
498-
| public | mytable | .*node_id.* |
499+
Then statement mytable_indexes returns exactly
500+
| indexdef@substr |
501+
| USING gist (geom) |
499502

500503
Scenario: Don't create id index if the configuration doesn't says so
501504
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -512,9 +515,9 @@ Feature: Index definitions in Lua file
512515
})
513516
"""
514517
When running osm2pgsql flex
515-
Then table pg_catalog.pg_indexes doesn't contain
516-
| schemaname | tablename | indexname@fullmatch |
517-
| public | mytable | .*node_id.* |
518+
Then statement mytable_indexes returns exactly
519+
| indexdef@substr |
520+
| USING gist (geom) |
518521

519522
Scenario: Always create id index if the configuration says so
520523
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
@@ -531,16 +534,16 @@ Feature: Index definitions in Lua file
531534
})
532535
"""
533536
When running osm2pgsql flex
534-
Then table pg_catalog.pg_indexes contains
535-
| schemaname | tablename | indexname@fullmatch |
536-
| public | mytable | .*node_id.* |
537+
Then statement mytable_indexes returns
538+
| indexdef@substr |
539+
| USING btree (node_id) |
537540

538541
Scenario: Create a unique id index when requested
539542
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
540543
And the lua style
541544
"""
542545
local t = osm2pgsql.define_table({
543-
name = 'foo',
546+
name = 'mytable',
544547
ids = { type = 'node', id_column = 'node_id', create_index = 'unique' },
545548
columns = {}
546549
})
@@ -550,20 +553,17 @@ Feature: Index definitions in Lua file
550553
end
551554
"""
552555
When running osm2pgsql flex
553-
Then table foo has 1562 rows
554-
Then table pg_catalog.pg_indexes contains
555-
| tablename | indexdef@fullmatch |
556-
| foo | CREATE UNIQUE INDEX .* USING .*\(node_id\) |
557-
And SELECT count(*) FROM pg_catalog.pg_index WHERE indrelid = 'foo'::regclass and indisprimary
558-
| count |
559-
| 0 |
556+
Then table mytable has 1562 rows
557+
Then statement mytable_indexes returns
558+
| indexdef@fullmatch | is_primary |
559+
| CREATE UNIQUE INDEX .* USING .*\(node_id\).* | False |
560560

561561
Scenario: Create a primary key id index when requested
562562
Given the input file 'liechtenstein-2013-08-03.osm.pbf'
563563
And the lua style
564564
"""
565565
local t = osm2pgsql.define_table({
566-
name = 'foo',
566+
name = 'mytable',
567567
ids = { type = 'node', id_column = 'node_id', create_index = 'primary_key' },
568568
columns = {}
569569
})
@@ -573,10 +573,7 @@ Feature: Index definitions in Lua file
573573
end
574574
"""
575575
When running osm2pgsql flex
576-
Then table foo has 1562 rows
577-
Then table pg_catalog.pg_indexes contains
578-
| tablename | indexdef@fullmatch |
579-
| foo | CREATE UNIQUE INDEX .* USING .*\(node_id\) |
580-
And SELECT count(*) FROM pg_catalog.pg_index WHERE indrelid = 'foo'::regclass and indisprimary
581-
| count |
582-
| 1 |
576+
Then table mytable has 1562 rows
577+
Then statement mytable_indexes returns
578+
| indexdef@fullmatch | is_primary |
579+
| CREATE UNIQUE INDEX .* USING .*\(node_id\) | True |

0 commit comments

Comments
 (0)