0.00%
Search · Index

Weblog Page

Filtered by date 2008-02-17, 81 - 90 of 111 Postings (all, summary)

Using nXML mode in Emacs

Created by Gustaf Neumann, last modified by Gustaf Neumann 17 Feb 2008, at 07:08 AM

By Jeff Davis

OpenACS docs are written by the named authors, and may be edited by OpenACS documentation staff.

An alternative to psgml mode is nXML by James Clark, a new major mode for GNU Emacs for editing XML, and which features highlighting, indentation, and on the fly validation versus a RelaxNG Schema.

Resources

Created by Gustaf Neumann, last modified by Gustaf Neumann 17 Feb 2008, at 07:08 AM

Here are some resources that OpenACS users have found useful.

The Request Processor

Created by Gustaf Neumann, last modified by Gustaf Neumann 17 Feb 2008, at 07:08 AM

By Pete Su

OpenACS docs are written by the named authors, and may be edited by OpenACS documentation staff.

This document is a brief introduction to the OpenACS 5.2.3rc1 Request Processor; more details can be found in the OpenACS 4 Request Processor Design. Here we cover the high level concepts behind the system, and implications and usage for the application developer.

The 5.2.3rc1 Request Processor is a global filter and set of Tcl procs that respond to every incoming URL reaching the server. The following diagram summarizes the stages of the request processor assuming a URL request like http://someserver.com/notes/somepage.adp.

Stage 1: Search Site Map

The first thing the RP does is to map the given URL to the appropriate physical directory in the filesystem, from which to serve content. We do this by searching the site map data model (touched on in the Packages, and further discussed in Writing OpenACS Application Pages). This data model maps URLs to objects representing content, and these objects are typically package instances.

After looking up the appropriate object, the RP stores the URL, the ID of the object it found, and the package and package instance the object belongs to into the environment of the connection. This environment can be queried using the ad_conn procedure, which is described in detail in OpenACS 4 Request Processor Design. The page development tutorial shows you how to use this interface to make your pages aware of which instance was requested.

Stage 2: Authentication

Next, the Request Processor examines the request for session information. Session information is generally sent from the client (the user's browser) to the server via cookies. The security/session handler is described in detail in its own document. It examines the client request and either extracts or sets up new session tokens for the user.

Stage 3: Authorization

Next, the Request Processor checks if the user has appropriate access privileges to the requested part of the site. In OpenACS 5.2.3rc1, access control is dictated by the permissions system. In this case, the RP checks if the user has "read" priviledges on the object in the site map specified by the URL. This object is typically a package instance, but it could easily be something more granular, such as whehter the user can view a particular piece of content within a package instance. This automatic check makes it easy to set up sites with areas that are only accessible to specific groups of users.

Stage 4: URL Processing, File Search

Finally, the Request Processor finds the file we intend to serve, searching the filesystem to locate the actual file that corresponds to an abstract URL. It searches for files with predefined "magic" extensions, i.e. files that end with: .html, .tcl and .adp.

If the RP can't find any matching files with the expected extensions, it will look for virtual-url-handler files, or .vuh files. A .vuh file will be executed as if it were a Tcl file, but with the tail end of the URL removed. This allows the code in the .vuh file to act like a registered procedure for an entire subtree of the URL namespace. Thus a .vuh file can be thought of as a replacement for filters and registered procs, except that they integrate cleanly and correctly with the RP's URL mapping mechanisms. The details of how to use these files are described in OpenACS 4 Request Processor Design.

Once the appropriate file is found, it is either served directly if it's static content, or sent to the template system or the standard Tcl interpreter if it's a dynamic page.

Once the flow of control reaches a dynamic page, the Request Processor has populated the environment of the request with several pieces of useful information. The RP's environment is accessible through the ad_conn interface, and the following calls should be useful to you when developing dynamic pages:

[ad_conn user_id]

The ID of the user associated with this request. By convention this is zero if there is no user.

[ad_conn session_id]

The ID of the session associated with this request.

[ad_conn url]

The URL associated with the request.

[ad_conn urlv]

The URL associated with the request, represented as a list instead of a single string.

[ad_conn file]

The actual local filesystem path of the file that is being served.

[ad_conn object_url]

If the URL refers to a site map object, this is the URL to the root of the tree where the object is mounted.

[ad_conn package_url]

If the URL refers to a package instance, this is the URL to the root of the tree where the package is mounted.

[ad_conn extra_url]

If we found the URL in the site map, this is the tail of the URL following the part that matched a site map entry.

[ad_conn object_id]

If the URL refers to a site map object, this is the ID of that object.

[ad_conn package_id]

If the URL refers to a package instance, this is the ID of that package instance.

[ad_conn package_key]

If the URL refers to a package instance, this is the unique key name of the package.

[ad_conn path_info]

In a .vuh file, path_info is the trailing part of the URL not matched by the .vuh file.

Install tclwebtest.

Created by Gustaf Neumann, last modified by Gustaf Neumann 17 Feb 2008, at 07:08 AM

Download the tclwebtest source, unpack it, and put it an appropriate place. (tclwebtest 1.0 will be required for auto-tests in OpenACS 5.1. When it exists, the cvs command here will be replaced with http://prdownloads.sourceforge.net/tclwebtest/tclwebtest-0.3.tar.gz?download.) As root:

cd /tmp
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/tclwebtest co tclwebtest
#wget http://umn.dl.sourceforge.net/sourceforge/tclwebtest/tclwebtest-1.0.tar.gz
#tar xvzf tclwebtest-1-0.tar.gz
mv tclwebtest-0.3 /usr/local/
ln -s /usr/local/tclwebtest-0.3 /usr/local/tclwebtest
ln -s /usr/local/tclwebtest/tclwebtest /usr/local/bin

Installing SSL Support for an OpenACS service

Created by Gustaf Neumann, last modified by Gustaf Neumann 17 Feb 2008, at 07:08 AM

Debian Users: apt-get install openssl before proceeding.

  1. Make sure nsopenssl.so is installed for AOLserver.

  2. Uncomment this line from config.tcl.

    #ns_param   nsopenssl       ${bindir}/nsopenssl.so
    
  3. Prepare a certificate directory for the service.

    [$OPENACS_SERVICE_NAME etc]$ mkdir /var/lib/aolserver/$OPENACS_SERVICE_NAME/etc/certs
    [$OPENACS_SERVICE_NAME etc]$ chmod 700 /var/lib/aolserver/$OPENACS_SERVICE_NAME/etc/certs
    [$OPENACS_SERVICE_NAME etc]$
    mkdir /var/lib/aolserver/$OPENACS_SERVICE_NAME/etc/certs
    chmod 700 /var/lib/aolserver/$OPENACS_SERVICE_NAME/etc/certs
    
  4. It takes two files to support an SSL connection. The certificate is the public half of the key pair - the server sends the certificate to browser requesting ssl. The key is the private half of the key pair. In addition, the certificate must be signed by Certificate Authority or browsers will protest. Each web browser ships with a built-in list of acceptable Certificate Authorities (CAs) and their keys. Only a site certificate signed by a known and approved CA will work smoothly. Any other certificate will cause browsers to produce some messages or block the site. Unfortunately, getting a site certificate signed by a CA costs money. In this section, we'll generate an unsigned certificate which will work in most browsers, albeit with pop-up messages.

    Use an OpenSSL perl script to generate a certificate and key.

    Debian users: use /usr/lib/ssl/misc/CA.pl instead of /usr/share/ssl/CA

    Mac OS X users: use perl /System/Library/OpenSSL/misc/CA.pl -newcert instead of /usr/share/ssl/CA

    [$OPENACS_SERVICE_NAME $OPENACS_SERVICE_NAME]$ cd /var/lib/aolserver/$OPENACS_SERVICE_NAME/etc/certs
    [$OPENACS_SERVICE_NAME certs]$ perl /usr/share/ssl/misc/CA -newcert
    Using configuration from /usr/share/ssl/openssl.cnf
    Generating a 1024 bit RSA private key
    ...++++++
    .......++++++
    writing new private key to 'newreq.pem'
    Enter PEM pass phrase:

    Enter a pass phrase for the CA certificate. Then, answer the rest of the questions. At the end you should see this:

    Certificate (and private key) is in newreq.pem
    [$OPENACS_SERVICE_NAME certs]$

    newreq.pem contains our certificate and private key. The key is protected by a passphrase, which means that we'll have to enter the pass phrase each time the server starts. This is impractical and unnecessary, so we create an unprotected version of the key. Security implication: if anyone gets access to the file keyfile.pem, they effectively own the key as much as you do. Mitigation: don't use this key/cert combo for anything besides providing ssl for the web site.

    [root misc]# openssl rsa -in newreq.pem -out keyfile.pem
    read RSA key
    Enter PEM pass phrase:
    writing RSA key
    [$OPENACS_SERVICE_NAME certs]$ 

    To create the certificate file, we take the combined file, copy it, and strip out the key.

    [$OPENACS_SERVICE_NAME certs]$ cp newreq.pem certfile.pem
    [root misc]# emacs certfile.pem
    

    Strip out the section that looks like

    -----BEGIN RSA PRIVATE KEY-----
    Proc-Type: 4,ENCRYPTED
    DEK-Info: DES-EDE3-CBC,F3EDE7CA1B404997
    S/Sd2MYA0JVmQuIt5bYowXR1KYKDka1d3DUgtoVTiFepIRUrMkZlCli08mWVjE6T
    (11 lines omitted)
    1MU24SHLgdTfDJprEdxZOnxajnbxL420xNVc5RRXlJA8Xxhx/HBKTw==
    -----END RSA PRIVATE KEY-----
  5. If you start up using the etc/daemontools/run script, you will need to edit this script to make sure the ports are bound for SSL. Details of this are in the run script.

How to package and release an OpenACS Package

Created by Gustaf Neumann, last modified by Gustaf Neumann 17 Feb 2008, at 07:08 AM

In this example, we are packaging and releasing myfirstpackage as version 1.0.0, which is compatible with OpenACS 5.0.x.

  1. Update the version number, release date, and package maturity of your package in the APM.

  2. Make sure all changes are committed.

  3. Tag the updated work.:

    cd /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage
    cvs tag myfirstpackages-1-0-0-final
    cvs tag -F openacs-5-0-compat
    

Done. The package will be added to the repository automatically. If the correct version does not show up within 24 hours, ask for help on the OpenACS.org development forum.

Release Version Numbering

Created by Gustaf Neumann, last modified by Gustaf Neumann 17 Feb 2008, at 07:08 AM

By Ron Henderson, Revised by Joel Aufrecht

OpenACS docs are written by the named authors, and may be edited by OpenACS documentation staff.

OpenACS version numbers help identify at a high-level what is in a particular release and what has changed since the last release.

A "version number" is really just a string of the form:

major.minor.dot[ milestone ]

  • A major number change indicates a fundamental change in the architecture of the system, e.g. OpenACS 3 to ACS 4. A major change is required if core backwards compatibility is broken, if upgrade is non-trivial, or if the platform changes substantially.

  • A minor change represents the addition of new functionality or changed UI.

  • A dot holds only bug fixes and security patches. Dot releases are always recommended and safe.

  • A milestone marker indicates the state of the release:

    • d, for development, means the release is in active development and is not in its intended released form.

    • a, for alpha, means new development is complete and code checkins are frozen. Alpha builds should work well enough to be testable.

    • b, for beta, means most severe bugs are fixed and end users can start trying the release.

    • Release Candidate builds (rc) are believed to meet all of the criteria for release and can be installed on test instances of production systems.

    • Final releases have no milestone marker. (Exception: In CVS, they are tagged with -final to differentiate them from branch tags.)

    Milestone markers are numbered: d1, d2, ..., a1, b1, rc1, etc.

A complete sequence of milestones between two releases:

5.0.0
5.0.0rc2
5.0.0rc1
5.0.0b4
5.0.0b1
5.0.0a4
5.0.0a3
5.0.0a1
5.0.0d1
4.6.3

Version numbers are also recorded in the CVS repository so that the code tree can be restored to the exact state it was in for a particular release. To translate between a distribution tar file (acs-3.2.2.tar.gz) and a CVS tag, just swap '.' for '-'.The entire release history of the toolkit is recorded in the tags for the top-level readme.txt file:

> cvs log readme.txt
RCS file: /usr/local/cvsroot/acs/readme.txt,v
Working file: readme.txt
head: 3.1
branch:
locks: strict
access list:
symbolic names:
	acs-4-0: 3.1.0.8
	acs-3-2-2-R20000412: 3.1
	acs-3-2-1-R20000327: 3.1
	acs-3-2-0-R20000317: 3.1
	acs-3-2-beta: 3.1
	acs-3-2: 3.1.0.4
	acs-3-1-5-R20000304: 1.7.2.2
	acs-3-1-4-R20000228: 1.7.2.2
	acs-3-1-3-R20000220: 1.7.2.2
	acs-3-1-2-R20000213: 1.7.2.1
	acs-3-1-1-R20000205: 1.7.2.1
	acs-3-1-0-R20000204: 1.7
	acs-3-1-beta: 1.7
	acs-3-1-alpha: 1.7
	acs-3-1: 1.7.0.2
	v24: 1.5
	v23: 1.4
	start: 1.1.1.1
	arsdigita: 1.1.1
keyword substitution: kv
total revisions: 13;	selected revisions: 13
description:
...

In the future, OpenACS packages should follow this same convention on version numbers.

So what distinguishes an alpha release from a beta release? Or from a production release? We follow a specific set of rules for how OpenACS makes the transition from one state of maturity to the next. These rules are fine-tuned with each release; an example is 5.0.0 Milestones and Milestone Criteria

Each package has a maturity level. Maturity level is recorded in the .info file for each major-minor release of OpenACS, and is set to the appropriate value for that release of the package.

    <version ...>
        <provides .../>
        <requires .../>
        <maturity>1</maturity>
        <callbacks>
            ...
    
  • Level -1: Incompatible. This package is not supported for this platform and should not be expected to work.

  • Level 0: New Submission. This is the default for packages that do not have maturity explicitly set, and for new contributions. The only criterion for level 0 is that at least one person asserts that it works on a given platform.

  • Level 1: Immature. Has no open priority 1 or priority 2 bugs. Has been installed by at least 10? different people, including 1 core developer. Has been available in a stable release for at least 1 month. Has API documentation.

  • Level 2: Mature. Same as Level 1, plus has install guide and user documentation; no serious deviations from general coding practices; no namespace conflicts with existing level 2 packages.

  • Level 3: Mature and Standard. Same as level 2, plus meets published coding standards; is fully internationalized; available on both supported databases.

Database upgrade scripts must be named very precisely in order for the Package Manager to run the correct script at the correct time.

  1. Upgrade scripts should be named /packages/myfirstpackage/sql/postgresql/upgrade/upgrade-OLDVERSION-NEWVERSION.sql

  2. If the version you are working on is a later version than the current released version, OLDVERSION should be the current version. The current version is package version in the APM and in /packages/myfirstpackage/myfirstpackage.info. So if forums is at 2.0.1, OLDVERSION should be 2.0.1d1. Note that this means that new version development that includes an upgrade must start at d2, not d1.

  3. If you are working on a pre-release version of a package, use the current package version as OLDVERSION. Increment the package version as appropriate (see above) and use the new version as NEWVERSION. For example, if you are working on 2.0.1d3, make it 2.0.1d4 and use upgrade-2.0.1d3-2.0.1d4.sql.

  4. Database upgrades should be confined to development releases, not alpha or beta releases.

  5. Never use a final release number as a NEWVERSION. If you do, then it is impossible to add any more database upgrades without incrementing the overall package version.

  6. Use only the d, a, and b letters in OLDVERSION and NEWVERSION. rc is not supported by OpenACS APM.

  7. The distance from OLDVERSION to NEWVERSION should never span a release. For example if we had a bug fix in acs-kernel on 5.1.0 you wouldn't want a file upgrade-5.0.4-5.1.0d1.sql since if you subsequently need to provide a 5.0.4-5.0.5 upgrade you will have to rename the 5.0.4-5.1.0 upgrade since you can't have upgrades which overlap like that. Instead, use upgrade-5.1.0d1-5.1.0d2.sql

Set up Log Analysis Reports

Created by Gustaf Neumann, last modified by Gustaf Neumann 17 Feb 2008, at 07:08 AM

Analog is a program with processes webserver access logs, performs DNS lookup, and outputs HTML reports. Analog should already be installed. A modified configuration file is included in the OpenACS tarball.

  1. [root src]# su - $OPENACS_SERVICE_NAME
    [$OPENACS_SERVICE_NAME $OPENACS_SERVICE_NAME]$ cd /var/lib/aolserver/$OPENACS_SERVICE_NAME
    [$OPENACS_SERVICE_NAME $OPENACS_SERVICE_NAME]$ mkdir www/log
    [$OPENACS_SERVICE_NAME $OPENACS_SERVICE_NAME]$ cp -r /usr/share/analog-5.32/images www/log/
    [$OPENACS_SERVICE_NAME $OPENACS_SERVICE_NAME]$ 
    su - $OPENACS_SERVICE_NAME
    cd /var/lib/aolserver/$OPENACS_SERVICE_NAME
    cp /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/acs-core-docs/www/files/analog.cfg.txt etc/analog.cfg
    mkdir www/log
    cp -r /usr/share/analog-5.32/images www/log/
    

    Edit /var/lib/aolserver/$OPENACS_SERVICE_NAME/etc/analog.cfg and change the variable in HOSTNAME "[my organisation]" to reflect your website title. If you don't want the traffic log to be publicly visible, change OUTFILE /var/lib/aolserver/$OPENACS_SERVICE_NAME/www/log/traffic.html to use a private directory. You'll also need to edit all instances of service0 to your $OPENACS_SERVICE_NAME.

  2. Run it.

    [$OPENACS_SERVICE_NAME $OPENACS_SERVICE_NAME]$ /usr/share/analog-5.32/analog -G -g/var/lib/aolserver/$OPENACS_SERVICE_NAME/etc/analog.cfg
    /usr/share/analog-5.32/analog: analog version 5.32/Unix
    /usr/share/analog-5.32/analog: Warning F: Failed to open DNS input file
      /home/$OPENACS_SERVICE_NAME/dnscache: ignoring it
      (For help on all errors and warnings, see docs/errors.html)
    /usr/share/analog-5.32/analog: Warning R: Turning off empty Search Word Report
    [$OPENACS_SERVICE_NAME $OPENACS_SERVICE_NAME]$

    Verify that it works by browing to http://yourserver.test:8000/log/traffic.html

  3. Automate this by creating a file in /etc/cron.daily.

    [$OPENACS_SERVICE_NAME $OPENACS_SERVICE_NAME]$ exit
    logout
    
    [root root]# emacs /etc/cron.daily/analog
    

    Put this into the file:

    #!/bin/sh
    
    /usr/share/analog-5.32/analog -G -g/var/lib/aolserver/$OPENACS_SERVICE_NAME/etc/analog.cfg
    [root root]# chmod 755 /etc/cron.daily/analog
    

    Test it by running the script.

    [root root]# sh /etc/cron.daily/analog
    

    Browse to http://yourserver.test/log/traffic.html

Internationalization

Created by Gustaf Neumann, last modified by Gustaf Neumann 17 Feb 2008, at 07:08 AM

By Peter Marklund and Lars Pind

OpenACS docs are written by the named authors, and may be edited by OpenACS documentation staff.

Webtest

Created by Anett Szabo, last modified by Gustaf Neumann 17 Feb 2008, at 07:08 AM

API testing is only part of testing your package - it doesn't test the code in our adp/tcl pairs. For this, we can use TCLWebtest (see sourceforge).

TclWebtest is primarily for testing user interface and acceptance testing. It is a tool to write automated tests for web applications. It provides a simple API for issuing http requests, dealing with the result and assume specific response values, while taking care of the details such as redirects and cookies.
It has some basic html parsing functionality, to provide access to elements of the result html page that are needed for testing (mainly links and forms).

  • TCLWebtest provides a library of functions (see command reference) that make it easy to call a page through HTTP, examine the results, and drive forms. TCLwebtest's functions overlap slightly with acs-automated-testing; see the example provided for one approach on integrating them.
  • TCLWebtest tries to minimize the effort to write tests by implicitely assuming specific conditions whenever it makes sense. For example it always expects the server to return http codes other than 404 or 500, unless otherwise specified.
  • The assertion procedures are targeted at test writers who want to make sure the behaviour of their web applications stays the same, without caring for style or minor wording changes. In the example below, it is just assumed that there is a link with the text "login" on the first page, that clicking on it results in a page with at least one form with at least two text-entry fields on it, and that submitting the form with the specified values results in a page that contains the "logged in" text.
  • TCLWebtest should be suitable for testing larger chains of user interaction on a web application, for example a full ecommerce ordering session. tclwebtest could visit an ecommerce site as anonymous user, add some products to its shopping cart, check out the cart, register itself as user and enter a test address etc. The test script could also include the administration part of the interaction, by explicitely logging in as site admin, reviewing and processing the order, nuking the test user etc.
  • TCLWebtest must be installed for to work. Since automated testing uses it, it should be part of every OpenACS installation. Note that TCLwebtest is installed automatically by Malte's install script.

Hint:

In order to simplify the generation of tclwebtest scripts the  Webtest-Recorder extension (TwtR) for Firefox is available see http://www.km.co.at/km/twtr This module is a plugin for Firefox. It is used to generate/edit a tclwebtest script which can be used later for regression testing without the need of a browser. There is a certain overlap of the application range between selenium and TwtR. This plugin was developed by Åsmund Realfsen for regression/load testing of the assessment module.

 


A typical script for tclwebtest looks like this:

set SERVER "testserver"
do_request "http://$SERVER/sometesturl/"
assert text "some text"

link follow "login"

field fill "testuser"
field fill "testpassword"
form submit

assert text "you are logged in as testuser"
    
This script can be saved in a file, e.g. login.test, and executed with ./tclwebtest login.test. The script itself is tcl, so you can do powerful things with only a few commands.

 

 http://cvs.openacs.org/cvs/openacs-4/etc/install/tcl/twt-procs.tcl?rev=1.18

Command Reference:

 

Here are some guidelines on how to write automated tests with TCLWebtest. It is a joy to work with automated testing once you get the hang of it. We will use the "myfirstpackage" as an example.

Create the directory that will contain the test script and edit the script file. The directory location and file name are standards which are recognized by the automated testing package:

[$OPENACS_SERVICE_NAME www]$ mkdir /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/tcl/test
[$OPENACS_SERVICE_NAME www]$ cd /var/lib/aolserver/$OPENACS_SERVICE_NAME/packages/myfirstpackage/tcl/test

[$OPENACS_SERVICE_NAME test]$ emacs myfirstpackages-procs.tcl

Write the tests. This is obviously the big step :) The script should first call ad_library like any normal -procs.tcl file:

ad_library {
    ...
}

To create a test case you call aa_register_case test_case_name.. Once you've created the test case you start writing the needed logic. We'll use the tutorial package, "myfirstpackage," as an example. Let's say you just wrote an API for adding and deleting notes in the notes packages and wanted to test that. You'd probably want to write a test that first creates a note, then verifies that it was inserted, then perhaps deletes it again, and finally verifies that it is gone.

Naturally this means you'll be adding a lot of bogus data to the database, which you're not really interested in having there. To avoid this I usually do two things. I always put all my test code inside a call to aa_run_with_teardown which basically means that all the inserts, deletes, and updates will be rolled back once the test has been executed. A very useful feature. Instead of inserting bogus data like: set name "Simon", I tend to generate a random script in order avoid inserting a value that's already in the database:

set name [ad_generate_random_string]

Here's how the test case looks so far:

aa_register_case mfp_basic_test {
    My test
} {
    aa_run_with_teardown  -rollback  -test_code  {

       }
}

Now look at the actual test code. That's the code that goes inside -test_code {}. We want to implement test case API-001, "Given an object id from API-001, invoke mfp::note::get. Proc should return the specific word in the title."

      set name [ad_generate_random_string]
      set new_id [mfp::note::add -title $name]
      aa_true "Note add succeeded" [exists_and_not_null new_id]

To test our simple case, we must load the test file into the system (just as with the /tcl file in the basic tutorial, since the file didn't exist when the system started, the system doesn't know about it.) To make this file take effect, go to the APM and choose "Reload changed" for "MyFirstPackage". Since we'll be changing it frequently, select "watch this file" on the next page. This will cause the system to check this file every time any page is requested, which is bad for production systems but convenient for developing. We can also add some aa_register_case flags to make it easier to run the test. The -procs flag, which indicates which procs are tested by this test case, makes it easier to find procs in your package that aren't tested at all. The -cats flag, setting categories, makes it easier to control which tests to run. The smoke test setting means that this is a basic test case that can and should be run any time you are doing any test. (a definition of "smoke test")

Once the file is loaded, go to ACS Automated Testing and click on myfirstpackage. You should see your test case. Run it and examine the results.

 

Example

Now we can add the rest of the API tests, including a test with deliberately bad data. The complete test looks like:

ad_library {
    Test cases for my first package.
}

 


    
aa_register_case -cats {smoke api} -procs {mfp::note::add mfp::note::get mfp::note::delete} mfp_basic_test { A simple test that adds, retrieves, and deletes a record. } { aa_run_with_teardown -rollback -test_code { set name [ad_generate_random_string] set new_id [mfp::note::add -title $name] aa_true "Note add succeeded" [exists_and_not_null new_id] # Now check that the item exists mfp::note::get -item_id $new_id -array note_array aa_true "Note contains correct title" [string equal $note_array(title) $name] # Now check, if titel got the value of name    mfp::note::delete -item_id $new_id                            set get_again [catch {mfp::note::get -item_id $new_id -array note_array}]                 aa_false "After deleting a note, retrieving it fails" [expr $get_again == 0]             }     }
            
aa_register_case  -cats {api}  -procs {mfp::note::add mfp::note::get mfp::note::delete}  mfp_bad_data_test  {
        A simple test that adds, retrieves, and deletes a record, using some tricky data.
    } {
        aa_run_with_teardown  -rollback  -test_code  {
                set name {-Bad [BAD] \077 { $Bad}}    
                #Now name becomes this very unusual value: -Bad [BAD] \077 { $Bad}
                append name [ad_generate_random_string]
                set new_id [mfp::note::add -title $name]     
                #Now new_id becomes the value of the solution of proceduer add with starting argument $name as -title
                aa_true "Note add succeeded" [exists_and_not_null new_id]
                #Now test that new_id exists
                mfp::note::get -item_id $new_id -array note_array
                aa_true "Note contains correct title" [string equal $note_array(title) $name]
                aa_log "Title is $name"
                mfp::note::delete -item_id $new_id

                set get_again [catch {mfp::note::get -item_id $new_id -array note_array}]
                aa_false "After deleting a note, retrieving it fails" [expr $get_again == 0]
            }
    }  


aa_register_case
-cats {web smoke}
-libraries tclwebtest
mfp_web_basic_test
{
A simple tclwebtest test case for the tutorial demo package.

@author Peter Marklund
} {
# we need to get a user_id here so that it's available throughout
# this proc
set user_id [db_nextval acs_object_id_seq]

set note_title [ad_generate_random_string]

# NOTE: Never use the aa_run_with_teardown with the rollback switch
# when running Tclwebtest tests since this will put the test code in
# a transaction and changes won't be visible across HTTP requests.

aa_run_with_teardown -test_code {

#-------------------------------------------------------------
# Login
#-------------------------------------------------------------

# Make a site-wide admin user for this test
# We use an admin to avoid permission issues
array set user_info [twt::user::create -admin -user_id $user_id]

# Login the user
twt::user::login $user_info(email) $user_info(password)

#-------------------------------------------------------------
# New Note
#-------------------------------------------------------------

# Request note-edit page
set package_uri [apm_package_url_from_key myfirstpackage]
set edit_uri "${package_uri}note-edit"
aa_log "[twt::server_url]$edit_uri"
twt::do_request "[twt::server_url]$edit_uri"

# Submit a new note

tclwebtest::form find ~n note
tclwebtest::field find ~n title
tclwebtest::field fill $note_title
tclwebtest::form submit

#-------------------------------------------------------------
# Retrieve note
#-------------------------------------------------------------

# Request index page and verify that note is in listing
tclwebtest::do_request $package_uri
aa_true "New note with title \"$note_title\" is found in index page"
[string match "*${note_title}*" [tclwebtest::response body]]

#-------------------------------------------------------------
# Delete Note
#-------------------------------------------------------------
# Delete all notes

# Three options to delete the note
# 1) go directly to the database to get the id
# 2) require an API function that takes name and returns ID
# 3) screen-scrape for the ID
# all options are problematic. We'll do #1 in this example:

set note_id [db_string get_note_id_from_name "
select item_id
from cr_items
where name = :note_title
and content_type = 'mfp_note'
" -default 0]

aa_log "Deleting note with id $note_id"

set delete_uri "${package_uri}note-delete?item_id=${note_id}"
twt::do_request $delete_uri

# Request index page and verify that note is in listing
tclwebtest::do_request $package_uri
aa_true "Note with title \"$note_title\" is not found in index page after deletion."
![string match "*${note_title}*" [tclwebtest::response body]]

} -teardown_code {

twt::user::delete -user_id $user_id
}
}


 

Next Page