Olemis Lang avatar Olemis Lang committed 77a50a7

BH Multiproduct #387 : Extend functional testers API with 'as_user' context manager

Comments (0)

Files changed (2)

 t598/t598_r1510975_functional_tester_product.diff
 t387/t387_r1515319_functional_test.6.diff
 t387/t387_r1515319_functional_test.7.diff
+t387/t387_r1526822_functional_test.8.diff
 t387/t387_r1524640_no_r5994.diff

t387/t387_r1526822_functional_test.8.diff

+# HG changeset patch
+# Parent fc1aec50ea88423068999f6371a2ebc9d7c5393d
+BH Multiproduct #387 : Extend functional testers API with 'as_user' context manager
+
+diff -r fc1aec50ea88 bloodhound_multiproduct/tests/functional/__init__.py
+--- a/bloodhound_multiproduct/tests/functional/__init__.py	Tue Oct 01 19:07:17 2013 -0500
++++ b/bloodhound_multiproduct/tests/functional/__init__.py	Tue Oct 01 19:29:45 2013 -0500
+@@ -717,6 +717,29 @@
+         tc.follow('Tickets')
+         tc.url(self.url + '/dashboard')
+ 
++    def as_user(self, user, restore='admin'):
++        """Context manager to track access to the web site 
++        as user and restore login afterwards (by default to admin)
++        """
++        @contextlib.contextmanager
++        def login_ctx():
++            try:
++                try:
++                    self.logout()
++                except:
++                    pass
++                self.login(user)
++                yield self
++            finally:
++                try:
++                    self.logout()
++                except:
++                    pass
++                if restore:
++                    self.login(restore)
++
++        return login_ctx
++
+ 
+ class BloodhoundGlobalEnvFunctionalTester(BloodhoundFunctionalTester):
+     """Library of higher-level operations for interacting with
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.