Guest User

Untitled

a guest
Nov 22nd, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. from django.contrib.staticfiles.testing import StaticLiveServerTestCase
  2. from django.contrib.auth.models import User
  3. from selenium import webdriver
  4.  
  5. class TestName(StaticLiveServerTestCase):
  6. @classmethod
  7. def setUpClass(cls):
  8. super().setUpClass()
  9. cls.browser = webdriver.Firefox()
  10.  
  11. @classmethod
  12. def tearDownClass(cls):
  13. cls.browser.quit()
  14. super().tearDownClass()
  15.  
  16. def setUp(self):
  17. super(TestName, self).setUp()
  18.  
  19. test_user = User.objects.create(username='Testuser')
  20. test_user.set_password('senha8dg')
  21. test_user.save()
  22.  
  23. # Login the user
  24. self.assertTrue(self.client.login(username='Testuser', password='senha8dg'))
  25. # Add cookie to log in the browser
  26. cookie = self.client.cookies['sessionid']
  27. self.browser.get(self.live_server_url) # visit page in the site domain so the page accepts the cookie
  28. self.browser.add_cookie({'name': 'sessionid', 'value': cookie.value, 'secure': False, 'path': '/'})
Add Comment
Please, Sign In to add comment