From cbeca06e91ffe7aee16ebacbe641ae84064b4252 Mon Sep 17 00:00:00 2001 From: Jean Yang Date: Sat, 13 Feb 2016 10:38:05 -0500 Subject: [PATCH] updated tests --- test/web/coursemanager/Jcourse.conf | 2 +- test/web/hipaa/Hipaa.conf | 5 +- test/web/hipaa/test_Hipaa.py | 82 +++++++++++------------------ 3 files changed, 36 insertions(+), 53 deletions(-) diff --git a/test/web/coursemanager/Jcourse.conf b/test/web/coursemanager/Jcourse.conf index 356d2e1..b5d82e1 100755 --- a/test/web/coursemanager/Jcourse.conf +++ b/test/web/coursemanager/Jcourse.conf @@ -8,7 +8,7 @@ title=Conf FunkLoad tests description=Simply testing a default static page # the server url to test -url=http://54.148.81.226 +url=http://54.200.253.211 #http://jcourse.jeeves.csail.mit.edu # the User-Agent header to send diff --git a/test/web/hipaa/Hipaa.conf b/test/web/hipaa/Hipaa.conf index d9652f0..c5bb504 100755 --- a/test/web/hipaa/Hipaa.conf +++ b/test/web/hipaa/Hipaa.conf @@ -8,7 +8,7 @@ title=Hipaa FunkLoad tests description=Simply testing a default static page # the server url to test -url = http://54.148.81.226/ +url = http://54.213.184.86 # url=http://hipaa.jeeves.csail.mit.edu # the User-Agent header to send @@ -25,6 +25,9 @@ nb_time=20 [test_login] description=Login in. +[test_register] +num_users=1020 + # ------------------------------------------------------------ # Credential access # diff --git a/test/web/hipaa/test_Hipaa.py b/test/web/hipaa/test_Hipaa.py index 0cd34af..f924d63 100755 --- a/test/web/hipaa/test_Hipaa.py +++ b/test/web/hipaa/test_Hipaa.py @@ -18,19 +18,17 @@ def setUp(self): self.server_url = self.conf_get('main', 'url') self.lipsum = Lipsum() - def login_as(self, username, password): + def login_as(self, username, password, pageURL="/index", descr="Get index"): # The description should be set in the configuration file server_url = self.server_url - self.get(server_url + "/", - description="Get /") reply = self.get(server_url + "/index", description="Get index") csrftoken = extract_token(self.getBody(), "name='csrfmiddlewaretoken' value='", "' />") - self.post(server_url + "/accounts/login/?next=/", + self.post(server_url + "/accounts/login/?next=" + pageURL, params=[['csrfmiddlewaretoken', csrftoken], - ['redirect_to', '/index'], + ['redirect_to', pageURL], ['username', username], ['password', password]], description="Post /accounts/login/") @@ -54,31 +52,31 @@ def test_login(self): reply = self.get(self.server_url + page, description="Get index") self.logout() - """ - self.login_as("admin", "admin") - self.logout() - """ - - def test_register(self): - username = self.lipsum.getUniqWord() - password = self.lipsum.getWord() - name = self.lipsum.getWord() + " " + self.lipsum.getWord() - email = self.lipsum.getWord() + "@example.org" - - server_url = self.server_url - # self.get(server_url + "/register", description='Get url') + self.logout() - csrftoken = extract_token(self.getBody(), "name='csrfmiddlewaretoken' value='", "' />") - self.post(server_url + "/register", - params=[ ['csrfmiddlewaretoken', csrftoken], - ['username', username], - ['password1', password], - ['password2', password], - ['name', name], - ['email', email], - ['profiletype', '1']], - description="Post /register") + num_users = self.conf_getInt('test_register', 'num_users') + for i in range(num_users): + username = self.lipsum.getUniqWord() + password = self.lipsum.getWord() + name = self.lipsum.getWord() + " " + self.lipsum.getWord() + email = self.lipsum.getWord() + "@example.org" + + server_url = self.server_url + + csrftoken = extract_token(self.getBody(), "name='csrfmiddlewaretoken' value='", "' />") + self.post(server_url + "/register", + params=[ ['csrfmiddlewaretoken', csrftoken], + ['username', username], + ['password1', password], + ['password2', password], + ['name', name], + ['email', email], + ['profiletype', '1']], + description="Post /register") + + self.assert_("index" in self.getLastUrl(), "Error in registration") + self.logout() def test_credential(self): credential_host = self.conf_get('credential', 'host') @@ -88,29 +86,11 @@ def test_credential(self): self.login_as(login, pwd) self.logout() - def test_random_register(self): - self.logout() - - username = self.lipsum.getUniqWord() - password = self.lipsum.getUniqWord() - - server_url = self.server_url - # self.get(server_url + "/register", description='Get url') - - csrftoken = extract_token(self.getBody(), "name='csrfmiddlewaretoken' value='", "' />") - self.post(server_url + "/register", - params=[ ['csrfmiddlewaretoken', csrftoken], - ['username', username], - ['password1', password], - ['password2', password], - ['name', 'New User'], - ['email', 'new_user@example.org'], - ['profiletype', '1']], - description="Post /register") - - # TODO: Check page after logging in. - self.logout() - self.login_as(username, password) + def test_show_all_users(self): + page = "/users" + self.login_as("admin", "admin", page, "Get users") + self.assert_(page == self.getLastUrl(), "Error in login") + reply = self.get(self.server_url + page, description="Get users") self.logout() if __name__ in ('main', '__main__'):