Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justquick/1159645 to your computer and use it in GitHub Desktop.
Save justquick/1159645 to your computer and use it in GitHub Desktop.
From 61dfc697ea2ca60218518e319f9b20fb973c0ee3 Mon Sep 17 00:00:00 2001
From: Justin Quick <justquick@gmail.com>
Date: Sat, 6 Aug 2011 17:45:45 -0400
Subject: [PATCH] start of selenium test suite with runselenium management command.
runtime options are set by SELENIUM_CONFIG so we can test in different environments easily
---
apps/sel/management/commands/runselenium.py | 9 +++++++++
requirements.txt | 1 +
settings.py | 3 ++-
tests/LoginFailure.py | 26 ++++++++++++++++++++++++++
tests/TestGameExists.py | 23 +++++++++++++++++++++++
tests/__init__.py | 3 +++
tests/helloben | 1 -
tests/log_in_failure.sel | 22 ----------------------
8 files changed, 64 insertions(+), 24 deletions(-)
create mode 100644 apps/sel/__init__.py
create mode 100644 apps/sel/management/__init__.py
create mode 100644 apps/sel/management/commands/__init__.py
create mode 100644 apps/sel/management/commands/runselenium.py
create mode 100644 apps/sel/models.py
create mode 100644 tests/LoginFailure.py
create mode 100644 tests/TestGameExists.py
create mode 100644 tests/__init__.py
delete mode 100644 tests/helloben
delete mode 100644 tests/log_in_failure.sel
diff --git a/apps/sel/__init__.py b/apps/sel/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/apps/sel/management/__init__.py b/apps/sel/management/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/apps/sel/management/commands/__init__.py b/apps/sel/management/commands/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/apps/sel/management/commands/runselenium.py b/apps/sel/management/commands/runselenium.py
new file mode 100644
index 0000000..b0393cd
--- /dev/null
+++ b/apps/sel/management/commands/runselenium.py
@@ -0,0 +1,9 @@
+from django.core.management.base import BaseCommand
+from unittest import TestLoader, TextTestRunner
+import tests
+
+
+class Command(BaseCommand):
+ def handle(self, *args, **kwargs):
+ TextTestRunner(verbosity=2).run(
+ TestLoader().loadTestsFromModule(tests))
diff --git a/apps/sel/models.py b/apps/sel/models.py
new file mode 100644
index 0000000..e69de29
diff --git a/requirements.txt b/requirements.txt
index 2352399..124af34 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -108,3 +108,4 @@ reportlab==2.5
django-ajax-selects
south
gunicorn
+selenium
\ No newline at end of file
diff --git a/settings.py b/settings.py
index f85dbe3..e05b2ec 100644
--- a/settings.py
+++ b/settings.py
@@ -237,6 +237,7 @@ INSTALLED_APPS = (
'newsletter',
'endless_pagination',
'gunicorn',
+ 'sel',
)
@@ -404,4 +405,4 @@ EMAIL_HOST_PASSWORD = 'notgnar!'
EMAIL_USE_TLS = 1
EMAIL_DEBUG = False
-
+SELENIUM_CONFIG = ("localhost", 4444, "*chrome", "http://localhost:8000/")
diff --git a/tests/LoginFailure.py b/tests/LoginFailure.py
new file mode 100644
index 0000000..7bd68ab
--- /dev/null
+++ b/tests/LoginFailure.py
@@ -0,0 +1,26 @@
+from selenium import selenium
+import unittest, time, re
+from django.conf import settings
+
+class LoginFailure(unittest.TestCase):
+ def setUp(self):
+ self.verificationErrors = []
+ self.selenium = selenium(*settings.SELENIUM_CONFIG)
+ self.selenium.start()
+
+ def test_login_failure(self):
+ sel = self.selenium
+ sel.open("/")
+ sel.type("name=email", "asdfasdfasdf")
+ sel.type("name=password", "qwerqwerqwerqwer")
+ sel.click("css=input.loginbutton")
+ sel.wait_for_page_to_load("30000")
+ try: self.failUnless(sel.is_text_present("Log into HvZSOURCE"))
+ except AssertionError, e: self.verificationErrors.append(str(e))
+
+ def tearDown(self):
+ self.selenium.stop()
+ self.assertEqual([], self.verificationErrors)
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/TestGameExists.py b/tests/TestGameExists.py
new file mode 100644
index 0000000..585d81d
--- /dev/null
+++ b/tests/TestGameExists.py
@@ -0,0 +1,23 @@
+from selenium import selenium
+import unittest, time, re
+
+from django.conf import settings
+
+class TestGameExists(unittest.TestCase):
+ def setUp(self):
+ self.verificationErrors = []
+ self.selenium = selenium(*settings.SELENIUM_CONFIG)
+ self.selenium.start()
+
+ def test_game_exists(self):
+ sel = self.selenium
+ sel.open("/games/")
+ try: self.failUnless(sel.is_text_present("Test Game"))
+ except AssertionError, e: self.verificationErrors.append(str(e))
+
+ def tearDown(self):
+ self.selenium.stop()
+ self.assertEqual([], self.verificationErrors)
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 0000000..225e378
--- /dev/null
+++ b/tests/__init__.py
@@ -0,0 +1,3 @@
+
+from LoginFailure import *
+from TestGameExists import *
\ No newline at end of file
diff --git a/tests/helloben b/tests/helloben
deleted file mode 100644
index c855332..0000000
--- a/tests/helloben
+++ /dev/null
@@ -1 +0,0 @@
-Charlie Sheen, Ben Vareen, Shrink to the size of a Lima Bean
diff --git a/tests/log_in_failure.sel b/tests/log_in_failure.sel
deleted file mode 100644
index 2718b6a..0000000
--- a/tests/log_in_failure.sel
+++ /dev/null
@@ -1,22 +0,0 @@
-from selenium import selenium
-import unittest, time, re
-
-class Log_In_Failure(unittest.TestCase):
- def setUp(self):
- self.verificationErrors = []
- self.selenium = selenium("localhost", 4444, "*chrome", "http://benbeecherisawesome.com/")
- self.selenium.start()
-
- def test_log_in_failure(self):
- sel = self.selenium
- sel.open("/")
- sel.type("email", "moormanpt@gmail.com")
- sel.type("password", "litereeding")
- sel.click("css=button.loginbutton")
-
- def tearDown(self):
- self.selenium.stop()
- self.assertEqual([], self.verificationErrors)
-
-if __name__ == "__main__":
- unittest.main()
--
1.7.4+GitX
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment