import unittest
import spynner


class TestInterface(unittest.TestCase):

    def test_login(self):
        browser = spynner.Browser()
        browser.load("http://localhost:8080/")
        browser.fill("#username", "admin")
        browser.fill("#password", "1234567")
        browser.click("#submit")
        browser.wait_load()
        self.assertIn('<a href="/user/logout">log out</a>', browser.html)
        self.assertIn('<a id="user" href="/user/view/admin">admin</a>', browser.html)

        browser.click_link('a[href="/user/logout"]')
        browser.fill("#username", "test")
        browser.fill("#password", "1234567")
        browser.click("#submit")
        browser.wait_load()
        self.assertIn('<a href="/user/logout">log out</a>', browser.html)
        self.assertIn('<a id="user" href="/user/view/test">test</a>', browser.html)


def suite():
   suite = unittest.TestSuite()
   suite.addTest(unittest.makeSuite(TestInterface))
   return suite
