Source

htsql / test / input / addon.yaml

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
#
# Copyright (c) 2006-2013, Prometheus Research, LLC
#

title: HTSQL Extensions
suite: addon
tests:

# TWEAK - tweaks for HTSQL
- title: tweak
  tests:
  # Addon description
  - ctl: [ext, tweak]

# TWEAK.AUTOLIMIT - limit number of rows
- title: tweak.autolimit
  tests:
  # Addon description
  - ctl: [ext, tweak.autolimit]

  # Set limit=10000 (default)
  - load: demo
    extensions:
      tweak.autolimit: {}

  - uri: /{2+2}
  - uri: /school
  - uri: /school?code='art'{*, /department}
  - uri: /school{*, /department}?code='art'

  # Merging consecutive limits.
  - uri: /school.limit(10001)
  - uri: /school.limit(10000)
  - uri: /school.limit(9999)
  - uri: /program.limit(2,3)
  - uri: /program.limit(2,3).sort(title)
  - uri: /program.limit(2,3).school
  - uri: /program.limit(2,3).student

  # Set limit=5
  - load: demo
    extensions:
      tweak.autolimit: { limit: 5 }

  - uri: /{2+2}
  - uri: /school

  # Merging consecutive limits
  - uri: /school.limit(6)
  - uri: /school.limit(5)
  - uri: /school.limit(4)
  - uri: /program.limit(2,3)
  - uri: /program.limit(2,3).sort(title)
  - uri: /program.limit(2,3).school
  - uri: /program.limit(2,3).student

  # Set limit=null
  - load: demo
    extensions:
      tweak.autolimit: { limit: null }

  - uri: /{2+2}
  - uri: /school

# TWEAK.CORS - cross-origin resource sharing
- title: tweak.cors
  tests:
  # Addon description
  - ctl: [ext, tweak.cors]

  # Set origin=* (default)
  - load: demo
    extensions:
      tweak.cors: {}
  - uri: /school

  # Set origin=http://demo.htsql.org
  - load: demo
    extensions:
      tweak.cors: { origin: 'http://demo.htsql.org' }
  - uri: /school

  # Set origin=null
  - load: demo
    extensions:
      tweak.cors: { origin: null }
  - uri: /school

# TWEAK.CSRF - cross-site request forgery protection
- title: tweak.csrf
  tests:
  # Addon description
  - ctl: [ext, tweak.csrf]

  # Test with both unprotected read and write disabled
  - load: demo
    extensions:
      tweak.csrf: {}
  - uri: /
    ignore: &ignore-htsql-csrf-token |
      Set-Cookie:.htsql-csrf-token=([0-9A-Za-z]+)
  - uri: /school
    ignore: *ignore-htsql-csrf-token
    expect: 403

  # Passing CSRF token back to the server
  - py: |
      # pass-csrf-token
      import wsgiref.util
      class response:
          status = None
          headers = None
          body = None
      def start_response(status, headers, exc=None):
          response.status = status
          response.headers = headers
      def request(environ):
          wsgiref.util.setup_testing_defaults(environ)
          response.status = None
          response.headers = None
          response.body = ''.join(__pbbt__['htsql'](environ, start_response))
          return (response.status, response.headers, response.body)
      status, headers, body = request({'PATH_INFO': "/"})
      token = None
      for header, value in headers:
          if header.lower() == 'set-cookie':
              if ';' in value:
                  value = value.split(';', 1)[0]
              if '=' in value:
                  name, value = value.split('=', 1)
                  if name == 'htsql-csrf-token':
                      token = value
      assert token is not None
      environ = {
          'PATH_INFO': "/school",
          'HTTP_COOKIE': "htsql-csrf-token=%s" % token,
          'HTTP_X_HTSQL_CSRF_TOKEN': token,
      }
      status, headers, body = request(environ)
      assert status == "200 OK"
      print status
      for header, value in headers:
          print "%s: %s" % (header, value)
      print
      print body

  # Test with unprotected read enabled
  - load: demo
    extensions:
      tweak.csrf:
        allow_cs_read: true
  - uri: /school
    ignore: *ignore-htsql-csrf-token

# TWEAK.DJANGO - adapt to Django
- py: |
    # has-django
    try:
        import django
        if django.VERSION > (1, 3):
            __pbbt__['django'] = True
    except ImportError:
        pass
  if: [sqlite, pgsql, mysql, oracle]
- title: tweak.django
  if: django
  tests:
  # Addon description
  - ctl: [ext, tweak.django]

  # Load `test_django_sandbox` and deploy the database
  - py: |
      # add-module-path
      if 'sqlite' in __pbbt__:
          import sqlite3
          __pbbt__['sqlite3_converters'] = sqlite3.converters.copy()
      import __builtin__, sys, os, os.path
      from htsql.core.util import DB
      path = os.path.join(os.getcwd(), "test/code")
      sys.path.insert(0, path)
      __builtin__.sandbox = DB.parse(__pbbt__['sandbox'].db)
      os.environ['DJANGO_SETTINGS_MODULE'] = 'test_django_sandbox.settings'
      from test_django_sandbox import createdb
      createdb()

  # Test Django-generated database
  - db: null
    extensions:
      htsql:
        debug: true
      tweak.django:
        settings: test_django_sandbox.settings
  - uri: /polls_poll{question, pub_date, count(polls_choice)}
  - uri: /polls_choice{poll.question, choice, votes}
  # Escaping issues
  - uri: /polls_choice?choice~'s'
    skip: true

  # Restore the original `sys.path`
  - py: |
      # remove-module-path
      from test_django_sandbox import dropdb
      dropdb()
      import __builtin__, sys, os, os.path
      path = os.path.join(os.getcwd(), "test/code")
      sys.path.remove(path)
      del os.environ['DJANGO_SETTINGS_MODULE']
      for name in sorted(sys.modules):
          if name.startswith(('test_django_sandbox', 'django')):
              del sys.modules[name]
      del __builtin__.sandbox
      if 'sqlite' in __pbbt__:
          import sqlite3
          sqlite3.converters.clear()
          sqlite3.converters.update(__pbbt__['sqlite3_converters'])
          del __pbbt__['sqlite3_converters']

# TWEAK.FILEDB - make a database from a set of CSV files
- title: tweak.filedb
  if: sqlite
  tests:
  # Addon description
  - ctl: [ext, tweak.filedb]

  # Sample CSV files
  - write: build/regress/table.csv
    data: |
        id,text,date
        1,one,2011-01-01
        2,two,2012-02-02
        3,,
  - write: build/regress/Names.csv
    data: |
        regular,"""With Spaces""",copy,copy,,_0
  - write: build/regress/irregular-fields.csv
    data: |
        column1,column2,column3
        regular,row,with 3 columns
        short,row
        long,row,with...,an extra column
  - write: build/regress/nothing.csv
    data: |
        ,,,
        ,,,
        ,,,
  - write: build/regress/duplicate-table-name.csv
    data: |
        filename
        duplicate-table-name.csv
  - write: build/regress/Duplicate_Table_Name.csv
    data: |
        filename
        Duplicate_Table_Name.csv
  - write: build/regress/empty.csv
    data: ""

  # Initialize the application
  - db: null
    extensions:
      htsql:
        debug: true
      tweak.filedb:
        sources:
        - file: build/regress/table.csv
        - file: build/regress/Names.csv
        - file: build/regress/nothing.csv
        - file: build/regress/duplicate-table-name.csv
        - file: build/regress/Duplicate_Table_Name.csv
        - file: build/regress/empty.csv

  # Database content
  - uri: /table{id:integer,text,date:date}
  - uri: /names
  - uri: /nothing
  - uri: /duplicate_table_name
  - uri: /_5
  - uri: /empty
    expect: 400

  # CSV files for testing caching (first batch)
  - write: build/regress/volatile.csv
    data: |
        source
        volatile
  - write: build/regress/permanent.csv
    data: |
        source
        permanent
  - write: build/regress/hidden.csv
    data: |
        source
        hidden

  # Initialize the application with a cache
  - db: null
    extensions:
      htsql:
        debug: true
      tweak.filedb:
        sources:
        - file: build/regress/volatile.csv
        - file: build/regress/permanent.csv
        - file: build/regress/hidden.csv
        cache-file: build/regress/filedb.sqlite

  # Available tables
  - uri: /volatile
  - uri: /permanent
  - uri: /hidden
  - uri: /_source
    expect: 400

  # Update some CSV files and add another one
  - write: build/regress/volatile.csv
    data: |
        source
        volatile/updated
  - write: build/regress/new.csv
    data: |
        source
        new

  # Make an application with updated files
  - db: null
    extensions:
      htsql:
        debug: true
      tweak.filedb:
        sources:
        - file: build/regress/permanent.csv
        - file: build/regress/volatile.csv
        - file: build/regress/new.csv
        cache-file: build/regress/filedb.sqlite

  # Available tables
  - uri: /permanent
  - uri: /volatile
  - uri: /hidden
    expect: 400
  - uri: /new

  # Make an applicate with the cache file directly
  - db:
      engine: sqlite
      database: build/regress/filedb.sqlite
    extensions:
      htsql:
        debug: true

  # Cache content
  - uri: /permanent
  - uri: /volatile
  - uri: /hidden
  - uri: /new
  - uri: /_source
    ignore: true
  - uri: /{_source[permanent].timestamp<=_source[volatile].timestamp}

  # Cleanup
  - rm:
    - build/regress/table.csv
    - build/regress/Names.csv
    - build/regress/irregular-fields.csv
    - build/regress/nothing.csv
    - build/regress/duplicate-table-name.csv
    - build/regress/Duplicate_Table_Name.csv
    - build/regress/empty.csv
    - build/regress/permanent.csv
    - build/regress/volatile.csv
    - build/regress/hidden.csv
    - build/regress/new.csv
    - build/regress/filedb.sqlite

# TWEAK.GATEWAY - define gateways to other databases
- title: tweak.gateway
  if: mysql
  tests:
  # Addon description
  - ctl: [ext, tweak.gateway]

  # Load the addon
  - load: demo
    extensions:
      tweak.gateway:
        gateways:
          sqlite_gw: sqlite:///build/regress/sqlite/htsql_demo.sqlite

  # Normal queries
  - uri: /sqlite_gw(/school)
  - uri: /department[ee]{name, count(course)}/:sqlite_gw

  # Formats and commands
  - uri: /sqlite_gw(/school[art].program)/:json
  - uri: /sqlite_gw(/fetch(count(course)))/:raw

  # Errors
  - uri: /sqlite_gw(/school/:html)
    expect: 400
    skip: true # is it still an error?
  - uri: /sqlite_gw(/nothing)
    expect: 400

# TWEAK.HELLO - 'Hello, World!'
- title: tweak.hello
  tests:
  # Addon description
  - ctl: [ext, tweak.hello]

  # Load the addon
  - load: demo
    extensions:
      tweak.hello: {}

  # Run the command
  - uri: /hello()

  # Invalid invocation
  - uri: /hello('world')
    expect: 400

  # Plugin parameters
  - load: demo
    extensions:
      tweak.hello:
        address: home
        repeat: 3
  - uri: /hello()

# TWEAK.INET - IPv4 data type
- title: tweak.inet
  if: pgsql
  tests:
  # Addon description
  - ctl: [ext, tweak.inet]

  # Use the `edge` database to get `other{inet}`
  - load: edge
    extensions:
      tweak.inet: {}

  # Introspection and conversion
  - uri: /other{code, inet+, inet(inet), text(inet), integer(inet)}

  # Conversions
  - uri: /{inet('127.0.0.1')}
  - uri: /{inet(text('127.0.0.1')), inet(2130706433)}
  - uri: /{text(inet('127.0.0.1')), integer(inet('127.0.0.1'))}

  # Invalid literals and conversions
  - uri: /{inet('HTSQL')}
    expect: 400
  - uri: /{inet(text('HTSQL'))}
    expect: 409
  - uri: /{inet(-1)}
    expect: 409

  # Comparison
  - uri: /{inet('192.168.24.1')=inet('192.168.24.1'),
           inet('192.168.24.1')!=inet('192.168.12.10'),
           inet('192.168.24.1')>inet('192.168.12.10')}

  # Arithmetics
  - uri: /{inet('192.168.12.10')+3063,
           inet('192.168.24.1')-3063,
           inet('192.168.24.1')-inet('192.168.12.10')}

# TWEAK.META - meta database
- title: tweak.meta
  tests:
  # Addon description
  - ctl: [ext, tweak.meta]

  # Load the addon
  - load: demo
    extensions:
      tweak.meta: {}

  # Tables
  - uri: /table/:meta
  - uri: /field/:meta
  - uri: /column/:meta
  - uri: /link/:meta

  # Links
  - uri: /(table?name='department').field/:meta
  - uri: /(table?name='department').column/:meta
  - uri: /(table?name='department').link/:meta
  - uri: /(table?name='department').link_via_target/:meta
  - uri: /(field?table_name='school').table/:meta
  - uri: /(field?table_name='school').column/:meta
  - uri: /(field?table_name='school').link/:meta
  - uri: /(column?table_name='program').table/:meta
  - uri: /(column?table_name='program').field/:meta
  - uri: /(link?table_name='student').table/:meta
  - uri: /(link?table_name='student').target/:meta
  - uri: /(link?table_name='student').field/:meta
  - uri: /(link?table_name='student').reverse/:meta
  - uri: /(link?table_name='student').link_via_reverse/:meta

  # Links and cardinality
  - uri: /table?name='department'
            {name, count(field), count(column),
             count(link), count(link_via_target)}
         /:meta
  - uri: /field?table_name='school'
            {table{name}, name, kind, column{domain}, link{is_singular}}
         /:meta
  - uri: /column?table_name='program'
            {table{name}, field{name, sort}}
         /:meta
  - uri: /link?table_name='student'
            {table{name}, target{name}, field{name},
             reverse{name}, link_via_reverse{name}}
         /:meta

  # Scalar queries
  - uri: /count(table)/:meta
  # Alternative syntax
  - uri: /meta(/count(table))

  # Meta-meta database
  - uri: /table/:meta/:meta
  - uri: /field/:meta/:meta
  - uri: /column/:meta/:meta
  - uri: /link/:meta/:meta

  # Invalid queries
  - uri: /meta()
    expect: 400
  - uri: /meta(/column,/link)
    expect: 400
  - uri: /meta(/schema)
    expect: 400
  - uri: /meta(table)
    expect: 400

  # Describe columns of the `type` database
  - load: edge
    extensions:
      tweak.meta: {}
  - uri: /meta(/column.sort(table.name, field.sort))

  # Respect `can_read`
  - load: demo
    extensions:
      tweak.csrf: {}
      tweak.meta: {}
  - uri: /meta(/table)
    ignore: *ignore-htsql-csrf-token
    expect: 403

# TWEAK.OVERRIDE - adjust database metadata
- title: tweak.override
  tests:
  # Addon description
  - ctl: [ext, tweak.override]

  # Test `included-tables`
  - load: demo
    extensions:
      tweak.override:
        included-tables: [school, program]
  - uri: /avg(school.count(program))
  - uri: /avg(school.count(department))
    expect: 400

  # Test `excluded-tables`
  - load: demo
    extensions:
      tweak.override:
        excluded-tables: [department, course]
  - uri: /avg(school.count(program))
  - uri: /avg(school.count(department))
    expect: 400

  # Test `included-tables` and `excluded-tables` together
  - load: demo
    extensions:
      tweak.override:
        included-tables: [school, program, department, course]
        excluded-tables: [department, course]
  - uri: /avg(school.count(program))
  - uri: /avg(school.count(department))
    expect: 400

  # Test schema qualifiers
  - load: demo
    extensions:
      tweak.override:
        included-tables: [ad.*]
    if: [pgsql, mssql]
  - uri: /count(program)
    if: [pgsql, mssql]
  - uri: /count(student)
    expect: 400
    if: [pgsql, mssql]

  # Test `included-columns`
  - load: demo
    extensions:
      tweak.override:
        included-columns: ["*code", "*name"]
  - uri: /school{code, count(department)}
  - uri: /student{name, count(enrollment)}
    expect: 400

  # Test `excluded-columns`
  - load: demo
    extensions:
      tweak.override:
        excluded-columns: [confidential.ssn]
  - uri: /max(confidential.pay_grade)
  - uri: /confidential.ssn
    expect: 400

  # Test `not-nulls`, `unique-keys` and `foreign-keys`
  - load: demo
    extensions:
      tweak.override:
        not-nulls: [student.school_code, student.program_code]
        unique-keys:
          - student(name, dob)!
        foreign-keys:
          - student(school_code) -> school
          - student(name)? -> instructor(full_name)
  - uri: /student{name, dob, school.code, program.code, exists(instructor)}.limit(1)

  # Test `class-labels`
  - load: demo
    extensions:
      tweak.override:
        class-labels:
          c14n: classification
          campus: (school^campus)
          active_students(): (student?is_active)
          students_by_year($year): (student?year(start_date)=$year)
  - uri: /count(c14n)
  - uri: /campus{campus, count(school)}
  - uri: /classification
    expect: 400
  - uri: /active_students().limit(10)
  - uri: /students_by_year(2010){name, dob, start_date}.limit(10)
  - uri: /active_students
    expect: 400
  - uri: /active_students(2010)
    expect: 400
  - uri: /students_by_year
    expect: 400
  - uri: /students_by_year()
    expect: 400

  # Test `field-labels` and `field-orders`
  - load: demo
    extensions:
      tweak.override:
        field-labels:
          program.includes: program -> program(*, part_of_code)
          student.full_name: name
          student.class: student -> enrollment, enrollment -> class
          student.avg_grade: (avg(enrollment.grade))
          program.active_students(): (student?is_active)
          program.students_by_year($year): (student?year(start_date)=$year)
        field-orders:
          student: [full_name, gender, dob, avg_grade]
          program: [code, title, degree]
  - uri: /program?exists(includes)
  - uri: /program?exists(program_via_part_of)
    expect: 400
  - uri: /student?count(class)>55
  - uri: /student.name
    expect: 400
  - uri: /(program?code='gart').active_students()
  - uri: /(program?code='gart').students_by_year(2010)
                {full_name, dob, start_date}
  - uri: /program.active_students
    expect: 400
  - uri: /program.active_students(2010)
    expect: 400
  - uri: /program.students_by_year
    expect: 400
  - uri: /program.students_by_year()
    expect: 400

  # Test duplicate labels with different number of parameters.
  - load: demo
    extensions:
      tweak.override:
        class-labels:
          active_students: (active_students())
          active_students(): (active_students(2010))
          active_students($year): (active_students($year, {'f','m'}))
          active_students($year, $gender):
                (student?is_active&year(start_date)=$year&gender=$gender)
        field-labels:
          program.active_students: (active_students())
          program.active_students(): (active_students(2010))
          program.active_students($year): (active_students($year, {'f','m'}))
          program.active_students($year, $gender):
                (student?is_active&year(start_date)=$year&gender=$gender)
  - uri: /active_students{name, gender, start_date}.limit(5)
  - uri: /active_students(){name, gender, start_date}.limit(5)
  - uri: /active_students(2009){name, gender, start_date}.limit(5)
  - uri: /active_students(2009, 'm'){name, gender, start_date}.limit(5)
  - uri: /active_students(2009, 'm', 'phd')
    expect: 400
  - uri: /(program?code='gart').active_students{name, gender, start_date}
  - uri: /(program?code='gart').active_students(){name, gender, start_date}
  - uri: /(program?code='gart').active_students(2009){name, gender, start_date}
  - uri: /(program?code='gart').active_students(2009, 'm'){name, gender, start_date}
  - uri: /(program?code='gart').active_students(2009, 'm', 'phd')
    expect: 400

  # Test `unlabeled_tables` and `unlabeled_columns`
  - load: demo
    extensions:
      tweak.override:
        field-labels:
          student.class: student -> enrollment, enrollment -> class
        unlabeled-tables: [enrollment]
        unlabeled-columns: [id]
  - uri: /student{name}?count(class)>55
  - uri: /enrollment
    expect: 400
  - uri: /student.enrollment
    expect: 400
  - uri: /student.id
    expect: 400

  # Test `globals`
  - load: demo
    extensions:
      tweak.override:
        globals:
          curr_date: date('2010-04-15')
          max_dob(): max(@student{dob})
          trunc_year(d): date(year(d),1,1)
  - uri: /(student{name, dob}?date(start_date)>curr_date).limit(10)
  - uri: /student{name, dob}?dob>max_dob()-30
  - uri: /student^trunc_year(dob){*, count(^)}

# TWEAK.POOL - cache database connections
- title: tweak.pool
  tests:
  # Addon description
  - ctl: [ext, tweak.pool]
  # No need for special tests since `tweak.pool` is already used
  # with regular tests for all database adapters except SQLite.

# TWEAK.RESOURCE - serve static files
- title: tweak.resource
  tests:
  # Addon description
  - ctl: [ext, tweak.resource]

  # We can only test for `Not Found` error
  - load: demo
    extensions:
      tweak.resource: {}
  - uri: /-/not-found
    expect: 404

  # Non-standard prefix
  - load: demo
    extensions:
      tweak.resource:
        indicator: ;)
  - uri: /-/not-found
    expect: 400
  - uri: /;)/not-found
    expect: 404

# TWEAK.SHELL - in-browser HTSQL editor
- title: tweak.shell
  tests:
  # Addon description
  - ctl: [ext, tweak.shell]
  - ctl: [ext, tweak.shell.default]

  # A trivial test
  - load: demo
    extensions:
      tweak.shell: {}
  - uri: /shell()
    ignore: true

  # Auxiliary commands
  - uri: /complete()
  - uri: /complete(school)
  - uri: /complete(department, course)
  - uri: /produce('/school')
  - uri: /produce('/school', 3)
  - uri: /analyze('/school')
  - uri: /with_permissions(/produce('/school:top'), 'true', 'false')
  - uri: /with_permissions(/produce('/school:top'), 'false', 'false')

  # Using `/shell()` as the default command
  - load: demo
    extensions:
      tweak.shell.default: {}
  - uri: /
  - uri: /
    headers:
      Accept: '*/*'
    ignore: true

# TWEAK.SQLALCHEMY - adapt to SQLAlchemy
- py: |
    # has-sqlalchemy
    try:
        import sqlalchemy
        if sqlalchemy.__version__ > '0.7.':
            __pbbt__['sqlalchemy'] = True
    except ImportError:
        pass
- title: tweak.sqlalchemy
  if: sqlalchemy
  tests:
  # Addon description
  - ctl: [ext, tweak.sqlalchemy]

  # Make sure `test_sqlalchemy_*` could be found
  - py: |
      # add-module-path
      import __builtin__, sys, os, os.path
      from htsql.core.util import DB
      path = os.path.join(os.getcwd(), "test/code")
      sys.path.insert(0, path)
      __builtin__.demo = DB.parse(__pbbt__['demo'].db)
      __builtin__.sandbox = DB.parse(__pbbt__['sandbox'].db)
      from test_sqlalchemy_sandbox import createdb
      createdb()

  # Test SQLAlchemy integration with an existing schema
  - db: null
    extensions:
      htsql:
        debug: true
      tweak.sqlalchemy:
        engine: test_sqlalchemy_demo.engine
        metadata: test_sqlalchemy_demo.metadata

  # Check if columns are recognized
  - uri: /school{code, name, campus}?code='art'
  - uri: /program{school_code, code, title, degree, part_of_code}
                ?school_code='ns'&code='gmth'
  - uri: /department{code, name, school_code}
                ?code='mth'
  - uri: /course{department_code, no, title, credits, description}
                ?department_code='astro'&no=215

  # Check if links are recognized
  - uri: /(school?code='art').department{name}
  - uri: /(school?code='art').program{title}
  - uri: /(department?code='mth').school{name}
  - uri: /(department?code='mth').course{title}
  - uri: /(program?school_code='ns'&code='gmth').school{name}
  - uri: /(program?school_code='ns'&code='gmth').part_of{title}
  - uri: /(program?school_code='ns'&code='gmth').program_via_part_of{title}
  - uri: /(course?department_code='astro'&no=215).department{name}

  # Test integration on SQLAlchemy-generated schema
  - db: null
    extensions:
      htsql:
        debug: true
      tweak.sqlalchemy:
        engine: test_sqlalchemy_sandbox.engine
        metadata: test_sqlalchemy_sandbox.metadata

  - uri: /users{name, fullname, count(addresses)}
  - uri: /addresses{user.name, email_address}

  # Restore the original `sys.path`
  - py: |
      # remove-module-path
      from test_sqlalchemy_sandbox import dropdb
      dropdb()
      import __builtin__, sys, os, os.path
      path = os.path.join(os.getcwd(), "test/code")
      sys.path.remove(path)
      del sys.modules['test_sqlalchemy_demo']
      del sys.modules['test_sqlalchemy_sandbox']
      del __builtin__.demo
      del __builtin__.sandbox

# TWEAK.SYSTEM - add access to system tables
- title: tweak.system
  if: pgsql
  tests:
  # Addon description
  - ctl: [ext, tweak.system]

  # Test for added links
  - load: demo
    extensions:
      tweak.system: {}
  - uri: /pg_class{relname, relkind}?pg_namespace.nspname='ad'

# TWEAK.TIMEOUT - limit query execution time
- title: tweak.system
  if: pgsql
  tests:
  # Addon description
  - ctl: [ext, tweak.timeout]

  # Test canceling of a query
  - load: demo
    extensions:
      tweak.timeout:
        timeout: 3
  - uri: /count(enrollment.fork().fork())
    expect: 409
    ignore: true
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.