[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Factorise 'svn lock' validation code

From: Madan U Sreenivasan <madan_at_collab.net>
Date: 2006-05-24 09:49:58 CEST

[[[
Factorize out code for locking a path and validating
the contents of the lock.

Suggested by: djames

* subversion/tests/cmdline/svntest/actions.py
   (run_and_verify_lock): New function to lock a path, and
    validate the contents of the lock.

* subversion/tests/cmdline/lock_tests.py
   (examine_lock, examine_lock_via_url, examine_lock_encoded_recurse):
    Modified to use svntest.actions.run_and_verify_lock().
]]]

Index: subversion/tests/cmdline/lock_tests.py
===================================================================
--- subversion/tests/cmdline/lock_tests.py (revision 19800)
+++ subversion/tests/cmdline/lock_tests.py (working copy)
@@ -301,24 +301,10 @@
   file_path = os.path.join(sbox.wc_dir, fname)
 
   # lock a file as wc_author
- svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',
- '--username', svntest.main.wc_author,
- '--password', svntest.main.wc_passwd,
- '-m', comment, file_path)
+ svntest.actions.run_and_validate_lock(file_path,
+ svntest.main.wc_author,
+ svntest.main.wc_passwd)
 
- output, err = svntest.actions.run_and_verify_svn(None, None, [],
- 'info', file_path)
-
- lock_info = output[-6:-1]
- if ((len(lock_info) != 5)
- or (not lock_info[0].startswith('Lock Token: opaquelocktoken:'))
- or (lock_info[1] != 'Lock Owner: %s\n' % svntest.main.wc_author)
- or (not lock_info[2].startswith('Lock Created:'))
- or (lock_info[4] != '%s\n' % comment)):
- raise svntest.Failure
-
-
-
 #----------------------------------------------------------------------
 # II.C.1: Lock a file in wc A. Check out wc B. Break the lock in wc
 # B. Verify that wc A gracefully cleans up the lock via update as
@@ -891,22 +877,11 @@
   file_path = os.path.join(sbox.wc_dir, fname)
   file_url = svntest.main.current_repo_url + '/' + fname
 
- # lock a file as wc_author
- svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',
- '--username', svntest.main.wc_author2,
- '--password', svntest.main.wc_passwd,
- '--no-auth-cache',
- '-m', comment, file_path)
+ # lock the file url and check the contents of lock
+ svntest.actions.run_and_validate_lock(file_url,
+ svntest.main.wc_author2,
+ svntest.main.wc_passwd)
 
- output, err = svntest.actions.run_and_verify_svn(None, None, [], 'info',
- file_url)
-
- match_line = 'Lock Owner: ' + svntest.main.wc_author2 + '\n'
-
- if not match_line in output:
- print "Error: expected output '%s' not found in output." % match_line
- raise svntest.Failure
-
 #----------------------------------------------------------------------
 def lock_several_files(sbox):
   "lock/unlock several files in one go"
@@ -1520,7 +1495,6 @@
   wc_dir = sbox.wc_dir
 
   fname = 'A/B/F/one iota'
- comment = 'This is a lock test.'
   file_path = os.path.join(sbox.wc_dir, fname)
 
   svntest.main.file_append(file_path, "This represents a binary file\n")
@@ -1542,29 +1516,12 @@
                                         None, None,
                                         file_path)
 
- # lock the file
- svntest.actions.run_and_verify_svn(None, ".*locked by user", [], 'lock',
- '--username', svntest.main.wc_author,
- '--password', svntest.main.wc_passwd,
- '-m', comment, file_path)
+ # lock the file and validate the contents
+ svntest.actions.run_and_validate_lock(file_path,
+ svntest.main.wc_author,
+ svntest.main.wc_passwd)
 
- # Run info and check that we get the lock fields.
- output, err = \
- svntest.actions.run_and_verify_svn(None, None, [],
- 'info', '-R',
- svntest.main.current_repo_url +
- '/A/B/F')
 
- lock_info = output[-6:-1]
- if ((len(lock_info) != 5)
- or (not lock_info[0].startswith('Lock Token: opaquelocktoken:'))
- or (lock_info[1] != 'Lock Owner: %s\n' % svntest.main.wc_author)
- or (not lock_info[2].startswith('Lock Created:'))
- or (lock_info[4] != '%s\n' % comment)):
- raise svntest.Failure
-
-
-
 ########################################################################
 # Run the tests
 
Index: subversion/tests/cmdline/svntest/actions.py
===================================================================
--- subversion/tests/cmdline/svntest/actions.py (revision 19800)
+++ subversion/tests/cmdline/svntest/actions.py (working copy)
@@ -761,7 +761,32 @@
     display_trees(None, 'DIFF OUTPUT TREE', output_tree, mytree)
     raise
 
+def run_and_validate_lock(path, username, password):
+ """`svn lock' the given path and validate the contents of the lock.
+ Use the given username. This is important because locks are
+ user specific."""
 
+ comment = "Locking path:%s." % path
+
+ # lock the path
+ run_and_verify_svn(None, ".*locked by user", [], 'lock',
+ '--username', username,
+ '--password', password,
+ '-m', comment, path)
+
+ # Run info and check that we get the lock fields.
+ output, err = run_and_verify_svn(None, None, [],
+ 'info','-R',
+ path)
+
+ lock_info = output[-6:-1]
+ if ((len(lock_info) != 5)
+ or (not lock_info[0].startswith('Lock Token: opaquelocktoken:'))
+ or (lock_info[1] != 'Lock Owner: %s\n' % username)
+ or (not lock_info[2].startswith('Lock Created:'))
+ or (lock_info[4] != '%s\n' % comment)):
+ raise svntest.Failure
+
 ######################################################################
 # Displaying expected and actual output
 

Factorize out code for locking a path and validating
the contents of the lock.

Suggested by: djames

* subversion/tests/cmdline/svntest/actions.py
  (run_and_verify_lock): New function to lock a path, and
   validate the contents of the lock.

* subversion/tests/cmdline/lock_tests.py
  (examine_lock, examine_lock_via_url, examine_lock_encoded_recurse):
   Modified to use svntest.actions.run_and_verify_lock().

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed May 24 09:19:28 2006

This is an archived mail posted to the Subversion Dev mailing list.