Kirill Simonov avatar Kirill Simonov committed 0b6d371

Added tests for tweak.resource.

Comments (0)

Files changed (7)

src/htsql_tweak/resource/__init__.py

 class TweakResourceAddon(Addon):
 
     name = 'tweak.resource'
-    hint = """static resource support"""
+    hint = """serve static files"""
     help = """
-      This plugin creates a mechanism for other plugins, such as
-      the ``tweak.shell`` to provide access to static resources
-      such as Javascript and CSS files. 
+    This addon adds a mechanism for serving static files via HTTP.
+    This mechanism is used by other addons to provide access to static
+    resources such as Javascript and CSS files.
+
+    Normally, static files are served under HTTP prefix `/-/`.  Use
+    parameter `indicator` to change the prefix.
     """
 
     parameters = [
-            Parameter('indicator', StrVal(r'^[^/]+$'), default='-'),
+            Parameter('indicator', StrVal(r'^[^/]+$'), default='-',
+                      value_name="STR",
+                      hint="""location for static files (default: `-`)"""),
     ]
 
     def __init__(self, app, attributes):

test/input/addon.yaml

   - uri: /student.id
     expect: 400
 
+# 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
+
+

test/output/mssql.yaml

             bind error: unknown attribute 'id':
                 /student.id
                          ^^
+      - id: tweak.resource
+        tests:
+        - ctl: [ext, tweak.resource]
+          stdout: |+
+            TWEAK.RESOURCE - serve static files
+
+            This addon adds a mechanism for serving static files via HTTP.
+            This mechanism is used by other addons to provide access to static
+            resources such as Javascript and CSS files.
+
+            Normally, static files are served under HTTP prefix `/-/`.  Use
+            parameter `indicator` to change the prefix.
+
+            Parameters:
+              indicator=STR            : location for static files (default: `-`)
+
+          exit: 0
+        - uri: /-/not-found
+          status: 404 Not Found
+          headers:
+          - [Content-Type, text/plain]
+          body: |
+            Resourse does not exist: '/not-found'.
+        - uri: /-/not-found
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            parse error: expected NAME; got SYMBOL u'/':
+                /-/not-found
+                  ^
+        - uri: /;)/not-found
+          status: 404 Not Found
+          headers:
+          - [Content-Type, text/plain]
+          body: |
+            Resourse does not exist: '/not-found'.

test/output/mysql.yaml

             bind error: unknown attribute 'id':
                 /student.id
                          ^^
+      - id: tweak.resource
+        tests:
+        - ctl: [ext, tweak.resource]
+          stdout: |+
+            TWEAK.RESOURCE - serve static files
+
+            This addon adds a mechanism for serving static files via HTTP.
+            This mechanism is used by other addons to provide access to static
+            resources such as Javascript and CSS files.
+
+            Normally, static files are served under HTTP prefix `/-/`.  Use
+            parameter `indicator` to change the prefix.
+
+            Parameters:
+              indicator=STR            : location for static files (default: `-`)
+
+          exit: 0
+        - uri: /-/not-found
+          status: 404 Not Found
+          headers:
+          - [Content-Type, text/plain]
+          body: |
+            Resourse does not exist: '/not-found'.
+        - uri: /-/not-found
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            parse error: expected NAME; got SYMBOL u'/':
+                /-/not-found
+                  ^
+        - uri: /;)/not-found
+          status: 404 Not Found
+          headers:
+          - [Content-Type, text/plain]
+          body: |
+            Resourse does not exist: '/not-found'.

test/output/oracle.yaml

             bind error: unknown attribute 'id':
                 /student.id
                          ^^
+      - id: tweak.resource
+        tests:
+        - ctl: [ext, tweak.resource]
+          stdout: |+
+            TWEAK.RESOURCE - serve static files
+
+            This addon adds a mechanism for serving static files via HTTP.
+            This mechanism is used by other addons to provide access to static
+            resources such as Javascript and CSS files.
+
+            Normally, static files are served under HTTP prefix `/-/`.  Use
+            parameter `indicator` to change the prefix.
+
+            Parameters:
+              indicator=STR            : location for static files (default: `-`)
+
+          exit: 0
+        - uri: /-/not-found
+          status: 404 Not Found
+          headers:
+          - [Content-Type, text/plain]
+          body: |
+            Resourse does not exist: '/not-found'.
+        - uri: /-/not-found
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            parse error: expected NAME; got SYMBOL u'/':
+                /-/not-found
+                  ^
+        - uri: /;)/not-found
+          status: 404 Not Found
+          headers:
+          - [Content-Type, text/plain]
+          body: |
+            Resourse does not exist: '/not-found'.

test/output/pgsql.yaml

             bind error: unknown attribute 'id':
                 /student.id
                          ^^
+      - id: tweak.resource
+        tests:
+        - ctl: [ext, tweak.resource]
+          stdout: |+
+            TWEAK.RESOURCE - serve static files
+
+            This addon adds a mechanism for serving static files via HTTP.
+            This mechanism is used by other addons to provide access to static
+            resources such as Javascript and CSS files.
+
+            Normally, static files are served under HTTP prefix `/-/`.  Use
+            parameter `indicator` to change the prefix.
+
+            Parameters:
+              indicator=STR            : location for static files (default: `-`)
+
+          exit: 0
+        - uri: /-/not-found
+          status: 404 Not Found
+          headers:
+          - [Content-Type, text/plain]
+          body: |
+            Resourse does not exist: '/not-found'.
+        - uri: /-/not-found
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            parse error: expected NAME; got SYMBOL u'/':
+                /-/not-found
+                  ^
+        - uri: /;)/not-found
+          status: 404 Not Found
+          headers:
+          - [Content-Type, text/plain]
+          body: |
+            Resourse does not exist: '/not-found'.

test/output/sqlite.yaml

             bind error: unknown attribute 'id':
                 /student.id
                          ^^
+      - id: tweak.resource
+        tests:
+        - ctl: [ext, tweak.resource]
+          stdout: |+
+            TWEAK.RESOURCE - serve static files
+
+            This addon adds a mechanism for serving static files via HTTP.
+            This mechanism is used by other addons to provide access to static
+            resources such as Javascript and CSS files.
+
+            Normally, static files are served under HTTP prefix `/-/`.  Use
+            parameter `indicator` to change the prefix.
+
+            Parameters:
+              indicator=STR            : location for static files (default: `-`)
+
+          exit: 0
+        - uri: /-/not-found
+          status: 404 Not Found
+          headers:
+          - [Content-Type, text/plain]
+          body: |
+            Resourse does not exist: '/not-found'.
+        - uri: /-/not-found
+          status: 400 Bad Request
+          headers:
+          - [Content-Type, text/plain; charset=UTF-8]
+          body: |
+            parse error: expected NAME; got SYMBOL u'/':
+                /-/not-found
+                  ^
+        - uri: /;)/not-found
+          status: 404 Not Found
+          headers:
+          - [Content-Type, text/plain]
+          body: |
+            Resourse does not exist: '/not-found'.
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.