from django.contrib.staticfiles.testing import LiveServerTestCase
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.test import Client, TestCase

from splinter import Browser
from time import sleep

from .factories import (
    UserFactory, ClientFactory, CompanyFactory, CategoryFactory,
    ProductFactory, QuoteFactory, QuoteModsFactory)


class LiveServerSplinterTest(LiveServerTestCase):

    @classmethod
    def setUpClass(cls):
        super(LiveServerSplinterTest, cls).setUpClass()
        cls.browser = Browser()
        cls.user1 = UserFactory()
        cls.user1.set_password('secret')
        cls.user1.save()

        cls.client1 = ClientFactory()

        cls.category1 = CategoryFactory(name='Chairs')
        cls.category2 = CategoryFactory(name='Tables')

        cls.product1 = ProductFactory(category=cls.category1)
        cls.product2 = ProductFactory(category=cls.category1)
        cls.product3 = ProductFactory(category=cls.category2)

        cls.login_helper(cls.user1.username, 'secret')

    @classmethod
    def tearDownClass(cls):
        cls.browser.quit()
        super(LiveServerSplinterTest, cls).tearDownClass()
        sleep(3)

    @classmethod
    def login_helper(cls, username, password):
        cls.browser.visit('{}{}'.format(
            cls.live_server_url, '/accounts/login/')
        )

        cls.browser.fill('username', username)
        cls.browser.fill('password', password)
        cls.browser.find_by_value('Log in').first.click()

    def setUp(self):
        pass

    def test_auth_redirect_to_menu_page(self):
        self.browser.visit('{}{}'.format(
            self.live_server_url, '/menu')
        )


@@ -407,24 +407,28 @@
 rverSplinter
+Auth
 Test(LiveSer
@@ -508,32 +508,36 @@
 veServerSplinter
+Auth
 Test, cls).setUp
@@ -1018,64 +1018,8 @@
 2)%0A%0A
-        cls.login_helper(cls.user1.username, 'secret')%0A%0A
     
@@ -1118,16 +1118,20 @@
 Splinter
+Auth
 Test, cl
@@ -1167,33 +1167,16 @@
 eep(3)%0A%0A
-    @classmethod%0A
     def 
@@ -1188,19 +1188,20 @@
 _helper(
-cls
+self
 , userna
@@ -1215,35 +1215,36 @@
 sword):%0A        
-cls
+self
 .browser.visit('
@@ -1269,19 +1269,20 @@
         
-cls
+self
 .live_se
@@ -1322,35 +1322,36 @@
      )%0A%0A        
-cls
+self
 .browser.fill('u
@@ -1370,35 +1370,36 @@
 ername)%0A        
-cls
+self
 .browser.fill('p
@@ -1418,35 +1418,36 @@
 ssword)%0A        
-cls
+self
 .browser.find_by
@@ -1491,32 +1491,89 @@
 ef setUp(self):%0A
+        self.login_helper(self.user1.username, 'secret')%0A
         pass%0A%0A  
@@ -1569,24 +1569,26 @@
    pass%0A%0A   
+ #
  def test_au
@@ -1589,21 +1589,16 @@
 est_
-auth_
 redirect
 _to_
@@ -1593,16 +1593,18 @@
 redirect
+ed
 _to_menu
@@ -1608,112 +1608,752 @@
 enu_
-page(self):%0A        self.browser.visit('%7B%7D%7B%7D'.format(%0A            self.live_server_url, '/menu')%0A        
+after_login(self):%0A    #     self.login_helper(self.user1.username, 'secret')%0A    #     self.browser.visit('%7B%7D%7B%7D'.format(%0A    #         self.live_server_url, '/menu')%0A    #     )%0A    #     self.assertTrue(self.browser.is_text_present('Select An Option'))%0A%0A    def test_new_quote_button(self):%0A        self.browser.visit('%7B%7D%7B%7D'.format(%0A            self.live_server_url, '/menu')%0A        )%0A        new_quote_visible = self.browser.find_by_id('new_quote').visible%0A        self.assertFalse(new_quote_visible)%0A%0A        self.browser.find_by_id('btn_new_quote').click()%0A        self.assertTrue(self.browser.is_text_present('New Quote'))%0A%0A        new_quote_visible = self.browser.find_by_id('new_quote').visible%0A        self.assertTrue(new_quote_visible
 )%0A%0A

Save work on functional test; need to workon out teardown