Commit 4847de4b authored by Daniel W Bond's avatar Daniel W Bond

new class to allow mock database with selenium

parent 1a2e6eb8
......@@ -97,7 +97,11 @@ Though you can use an existing user to access this database, here's how to creat
``CREATE USER 'bookworm'@'localhost' IDENTIFIED BY 'password';``
For local development, password strength is less important, but use a strong passphrase for deployment. You can choose a different username.
``GRANT ALL ON bookshare.* TO 'bookworm'@'localhost';`` ``FLUSH PRIVILEGES;``
``GRANT ALL ON bookshare.* TO 'bookworm'@'localhost';``
This allows your database user to create all the tables it needs on the bookshare database. (Each model in each app's models.py is a separate table, and each attribute a column, and each instance a row.)
``GRANT ALL ON test_bookshare.* TO 'bookworm'@'localhost';`` ``FLUSH PRIVILEGES;``
When running test cases, django creates a test database so your 'real' database doesn't get screwed up. This database is called 'test_' + whatever your normal database is named. Note that for permissions it doesn't matter that this database hasn't yet been created.
The .\* is to grant access all tables in the database, and 'flush privileges' reloads privileges to ensure that your user is ready to go.
......
# functional tests describe a 'user story', testing how the implementation works
# with a complete black box as to how it works on the backend
import unittest
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from django.contrib.auth.models import User
from core.models import Student
from trades.models import Listing
# your mason username and password are neccessary to log in for test cases
username = 'gmason'
......@@ -45,7 +49,7 @@ def sign_out_user(self):
# and sees a successful logout message.
self.assertIn(u'Logout successful', self.browser.find_element_by_tag_name('h2').text)
class SeleniumSetUpTearDown(unittest.TestCase):
class SeleniumSetUpTearDown(StaticLiveServerTestCase):
"""TestCase subclass to add Selenium setup and teardown."""
def setUp(self):
......@@ -95,7 +99,6 @@ class ListingTests(SeleniumSetUpTearDown):
"""Tests all the user interactions pertaining to the models in the trades app."""
def setUp(self):
# in the database
# other Student
# good Listing (other Student)
# bad Listing (other Student)
......@@ -103,13 +106,12 @@ class ListingTests(SeleniumSetUpTearDown):
return super(ListingTests, self).setUp()
def tearDown(self):
# delete the George Mason book listing
return super(ListingTests, self).tearDown()
def test_listing_management(self):
# George Mason has previously used Bookshare, but wants to sign in and
# create a new Listing.
self.browser.get('http://localhost:8000')
self.browser.get(self.live_server_url)
self.assertIn(u'SRCT Bookshare \u2022 Homepage', self.browser.title)
sign_in_user(self)
......@@ -273,7 +275,7 @@ class LookoutTests(SeleniumSetUpTearDown):
def test_lookout_management(self):
# George Mason wishes to create a lookout for a book for his class.
self.browser.get('http://localhost:8000')
self.browser.get(self.live_server_url)
self.assertIn(u'SRCT Bookshare \u2022 Homepage', self.browser.title)
sign_in_user(self)
......@@ -314,6 +316,3 @@ class LookoutTests(SeleniumSetUpTearDown):
# Finished, he hits the log out button in the navbar.
sign_out_user(self)
if __name__ == '__main__':
unittest.main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment