django_pfm/pfm/tests.py
2017-10-31 16:37:02 +03:00

65 lines
2.6 KiB
Python

import datetime
from django.utils import timezone
from django.test import TestCase
from django.core.urlresolvers import reverse
from pfm.models import Account, Transaction
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium.webdriver.phantomjs.webdriver import WebDriver
class MySeleniumTests(StaticLiveServerTestCase):
UserModel = User
user_credentials = {'username': 'test', 'password': 'test'}
@classmethod
def setUpClass(cls):
super(MySeleniumTests, cls).setUpClass()
cls.selenium = WebDriver()
cls.selenium.implicitly_wait(10)
@classmethod
def tearDownClass(cls):
cls.selenium.quit()
super(MySeleniumTests, cls).tearDownClass()
def test_login(self):
User.objects.create_user(**self.user_credentials)
self.selenium.get('%s%s' % (self.live_server_url, '/pfm/login/?next=/pfm/'))
username_input = self.selenium.find_element_by_name("username")
username_input.send_keys('test')
password_input = self.selenium.find_element_by_name("password")
password_input.send_keys('test1')
self.selenium.find_element_by_xpath('//input[@value="login"]').click()
password_input = self.selenium.find_element_by_name("password")
password_input.send_keys('test')
self.selenium.find_element_by_xpath('//input[@value="login"]').click()
self.selenium.save_screenshot('mysite/media/images/login_passed.png')
class Auth(TestCase):
def test_view(self):
response = self.client.get(reverse('login'))
self.assertEqual(response.status_code, 200)
class AccountTestCase(TestCase):
UserModel = User
user_credentials = {'username': 'test', 'password': 'test'}
def setUp(self):
self.user = User.objects.create_user(**self.user_credentials)
Account.objects.create(acc_name='test1', acc_balance=0, acc_currency='RUB', user=self.user)
#Account.objects.create(acc_name='test2', acc_balance=100, acc_currency='RUB', user='test')
#Account.objects.create(acc_name='test3', acc_balance=-100, acc_currency='RUB', user='test')
def test_acc_view(self):
#authenticate(**self.user_credentials)
''' default behavior '''
response = self.client.get('/pfm/')
self.assertRedirects(response, '/pfm/login/?next=/pfm/')
self.assertEqual(authenticate(**self.user_credentials), self.user)
#self.assertEqual(response.status_code, 200)
self.assertContains(response, "test1")