Lesson 20 - User Accounts
LEARN
Today
- Customize the basic user auth system
- User Accounts (Add, List, Detail, Edit, Delete)
- Encapsulate to reuse
- Add tests
Last Lesson
- User data model
- Basic Auth Views
- Login
- Logout
- Signup
- User info
Writing Tests
- Important for code reuse
- Use a standard pattern for tests
- First test gets the greatest return
Data Tests
- List, Detail, Create, Edit, Delete
- String representation
- Consistent naming
Example: BookDataTests
class BookDataTests(TestCase):
def test_book_list()
def test_book_detail()
def test_book_add()
def test_book_edit()
def test_book_delete()
Data Test Features
- Create data records
- List data records
- Show record fields
- Modify records
- Delete records
- Count number of records
View Tests
- List, Detail, Create, Edit, Delete
- HTTP verbs (GET, POST)
- Test for failure
Example: AccountsViewTests
class AccountsViewTests(TestCase):
def test_accounts_list_view()
def test_accounts_detail_view()
def test_accounts_add_view()
def test_accounts_edit_view()
def test_accounts_delete_view()
View Test Features
- Get all views for data records
- Post to update data (Add, Update, Delete)
- Check record changes
- Check for specific record fields
- Count records from HTML
- Check for proper redirect
- Check for URLs to views
Test User Accounts
- Test Login Form (good and bad)
- Test Signup Form
- setUp, tearDown
Django Test for Forms
class TestAccountsViews(TestCase):
def test_home_view(self):
def test_login_view(self):
def test_logout_view(self):
def test_signup_view(self):
BUILD
Linux Commands
- Automate your frequent actions
- Achieve your intent with one word
- Bury the details in scripts
- Do it the same every time
Django Operations
- serve -- Django runserver
- migrate -- Make migrations and apply them
- dt -- Run Django Tests
Git Operations
- s -- Git status
- pull -- Git pull
- push -- Git pull and Git push
- commit -- Git add and commit with comment
Directory Navigation
- l -- Directory listing
- d -- Change directory and list files
- u -- Go Up one directory
- b -- Start work for BACS 350
Automation
- Windows uses Powershell for automation (but also supports "bash")
- Commands are built into a file (load into Bash shell)
- .bashrc script
- Session start by loading the script
bash
$ source .bashrc
User Account Module
- Django app - accounts
- URLs, templates, views
- Settings, Static media
- Add Accounts to Book Builder
Add Accounts to Book Builder
- Copy accounts folder
- Copy templates folder
- Set settings and urls