[CMF-checkins] CVS: CMF/functest/creator - scaffolding.py:1.1 submit_news.zft:1.1

Tres Seaver tseaver@zope.com
Thu, 29 Aug 2002 19:05:41 -0400


Update of /cvs-repository/CMF/functest/creator
In directory cvs.zope.org:/tmp/cvs-serv13211/creator

Added Files:
	scaffolding.py submit_news.zft 
Log Message:
 - Move functional tests here from FunctionalTests library examples.

=== Added File CMF/functest/creator/scaffolding.py ===
"""
    Scaffolding methods for CMF_base tests.

    - "setup" methods should return boolean "OK to continue" values.

    - "postcondition" methods should return boolean "test succeeded" values.

    - "teardown" methods don't need to return anything at all.

    Methods can assume that Zope has been imported;  they may not (yet)
    import any Zope-specific packages or modules.

    Each method will be passed a handle to the root Zope object ('app')
    and a dictionary ('test_vars') containing the "defaults" used in
    constructing the functional tests.
"""

from Products.CMFCore.PortalFolder import PortalFolder

def submit_news_setup( app, test_vars, result ):
    """
        Ensure that member exists, with given password, and that she
        has an member folder without an object called "testnews".
    """
    site_path   = test_vars.get( 'site_path', '/' )
    userid      = test_vars.get( 'userid', 'user' )
    password    = test_vars.get( 'password', 'password' )
    newsitem_id = test_vars.get( 'newsitem_id', 'testnews' )

    cmf_site    = app.unrestrictedTraverse( site_path )
    acl_users   = cmf_site.acl_users

    user        = acl_users.getUserById( userid, None )
    if user is None:
        acl_users._doAddUser( userid, password, ( 'Member', ), () )
        user    = acl_users.getUserById( userid, None )
    user        = user.__of__( acl_users )
    
    try:
        folder      = cmf_site.unrestrictedTraverse( 'Members/%s' % userid )
    except:
        cmf_site.portal_membership.createMemberarea( userid )
        folder      = cmf_site.unrestrictedTraverse( 'Members/%s' % userid )

    if newsitem_id in folder.objectIds():
        folder.manage_delObjects( ids=[newsitem_id] )
    
    get_transaction().commit()

    return 1

def submit_news_postcondition( app, test_vars, result ):
    """
    """
    app._p_jar.sync() # must get caught up!

    site_path   = test_vars.get( 'site_path', '/' )
    userid      = test_vars.get( 'userid', 'user' )
    newsitem_id = test_vars.get( 'newsitem_id', 'testnews' )

    cmf_site    = app.unrestrictedTraverse( site_path )
    wf_tool     = cmf_site.portal_workflow

    newsitem    = cmf_site.unrestrictedTraverse( 'Members/%s/%s'
                                % ( userid, newsitem_id ) )
    assert wf_tool.getInfoFor( newsitem, 'review_state' ) == 'pending'
    
    get_transaction().commit()

    return 1

def submit_news_teardown( app, test_vars, result ):
    """
    """
    site_path   = test_vars.get( 'site_path', '/' )
    userid      = test_vars.get( 'userid', 'user' )
    newsitem_id = test_vars.get( 'newsitem_id', 'testnews' )

    cmf_site    = app.unrestrictedTraverse( site_path )
    folder      = cmf_site.unrestrictedTraverse( 'Members/%s' % userid )
    if newsitem_id in folder.objectIds():
        folder.manage_delObjects( ids=[newsitem_id] )
    
    get_transaction().commit()


=== Added File CMF/functest/creator/submit_news.zft ===
[Scenario]
Title : Submit news item for publication
Use_case: Member publishes content

[Setup]
Filename: %(config_dir)s/scaffolding.py
Function: submit_news_setup

[Home_Page]
URL: %(portal_url)s/%(site_path)s
Expected_Result: 200

[Login_Form]
URL: %(portal_url)s/%(site_path)s/login_form
Expected_Result: 200

[Login]
URL: %(portal_url)s/%(site_path)s/logged_in
Field_1: %(doh)sac_name:string = %(userid)s
Field_2: %(doh)sac_password:string = %(password)s
Expected_Result: 200

[My_Stuff]
URL: %(portal_url)s/%(site_path)s/Members/%(userid)s/folder_contents
# Authentication could be via cookie, instead
Authentication: %(userid)s:%(password)s
Expected_Result: 200

[Factories]
URL: %(portal_url)s/%(site_path)s/Members/%(userid)s/folder_factories
Authentication: %(userid)s:%(password)s
Expected_Result: 200

[New_Item]
URL: %(portal_url)s/%(site_path)s/Members/%(userid)s/invokeFactory
Authentication: %(userid)s:%(password)s
Field_1: id:string=testnews
Field_2: type_name:string=News Item
Expected_Result: 302
Expected_Redirect: %(portal_url)s/Members/%(userid)s/testnews/metadata_edit_form

[Metadata]
URL: %(portal_url)s/%(site_path)s/Members/%(userid)s/testnews/metadata_edit
Authentication: %(userid)s:%(password)s
Field_1: title:string=New News
Field_2: description:string=This is a test news item.
Field_3: subject:tokens=Foo Bar Baz
Field_4: format:string=text/plain
Field_5: change_and_edit:string= Change & Edit
Expected_Result: 302
Expected_Redirect: %(portal_url)s/Members/%(userid)s/testnews/newsitem_edit_form

[Edit_Form]
URL: %(portal_url)s/%(site_path)s/Members/%(userid)s/testnews/newsitem_edit_form
Authentication: %(userid)s:%(password)s
Expected_Result: 200

[Edit]
URL: %(portal_url)s/%(site_path)s/Members/%(userid)s/testnews/newsitem_edit
Authentication: %(userid)s:%(password)s
Field_1: description:string=This is a test news item.
Field_2: text:string=Testing, testing: 1, 2, 3...
Expected_Result: 302
Expected_Redirect: %(portal_url)s/Members/%(userid)s/testnews/newsitem_edit_form

[View]
URL: %(portal_url)s/%(site_path)s/Members/%(userid)s/testnews/newsitem_view
Authentication: %(userid)s:%(password)s
Expected_Result: 200

[Submit_form]
URL: %(portal_url)s/%(site_path)s/Members/%(userid)s/testnews/content_submit_form
Authentication: %(userid)s:%(password)s
Expected_Result: 200

[Submit]
URL: %(portal_url)s/%(site_path)s/Members/%(userid)s/testnews/content_status_modify
Authentication: %(userid)s:%(password)s
Field_1: comment:string=Submitting
Field_2: workflow_action:string=submit
Expected_Result: 302
Expected_Redirect: %(portal_url)s/Members/user/testnews/view

[Postcondition]
Filename: %(config_dir)s/scaffolding.py
Function: submit_news_postcondition

[Teardown]
Filename: %(config_dir)s/scaffolding.py
Function: submit_news_teardown

[DEFAULT]
userid: user
password: password
doh: __