Skip to content

Instantly share code, notes, and snippets.

@prcutler
Created September 17, 2018 13:18
Show Gist options
  • Save prcutler/fb7d4ff30561e17a85edfd71e9135293 to your computer and use it in GitHub Desktop.
Save prcutler/fb7d4ff30561e17a85edfd71e9135293 to your computer and use it in GitHub Desktop.
NFLPool Account unittest
import unittest
import unittest.mock
import pyramid.testing
class AccountControllerTests(unittest.TestCase):
def test_register_validation_no_email(self):
# Arrange
from nflpool.viewmodels.register_viewmodel import RegisterViewModel
request = pyramid.testing.DummyRequest()
request.POST = {
'first_name': 'Paul',
'last_name': 'Cutler',
'email': 'paul.r.cutler@gmail.com',
'password': '',
'confirm_password': ''
}
# noinspection PyTypeChecker
vm = RegisterViewModel(request)
# Act
vm.validate()
# Assert:
self.assertIsNotNone(vm.error)
self.assertTrue('password' in vm.error)
@prcutler
Copy link
Author

Testing started at 8:14 AM ...
/Users/pcutler/workspace/nflpool/.env/bin/python /Applications/PyCharm.app/Contents/helpers/pycharm/_jb_unittest_runner.py --path /Users/pcutler/workspace/nflpool/nflpool/tests/account_tests2.py
Launching unittests with arguments python -m unittest /Users/pcutler/workspace/nflpool/nflpool/tests/account_tests2.py in /Users/pcutler/workspace/nflpool/nflpool/tests


Ran 1 test in 0.293s

FAILED (errors=1)

Error
Traceback (most recent call last):
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 59, in testPartExecutor
    yield
  File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/unittest/case.py", line 605, in run
    testMethod()
  File "/Users/pcutler/workspace/nflpool/nflpool/tests/account_tests2.py", line 20, in test_register_validation_no_email
    vm = RegisterViewModel(request)
TypeError: __init__() takes 1 positional argument but 2 were given


Process finished with exit code 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment