James Williams
More tests at the bottom, fewer at the top
# test_models.py
import pytest
from django.contrib.auth.models import User
from blog.models import Post
@pytest.mark.django_db
def test_post_creation():
user = User.objects.create(username='test')
post = Post.objects.create(
title='Test Post',
content='Content',
author=user
)
assert post.title == 'Test Post'
assert post.author == user
# Run: pytest
// Counter.test.js
import { render, screen, fireEvent } from '@testing-library/react';
import Counter from './Counter';
test('increments counter on button click', () => {
render(<Counter />);
const button = screen.getByText('Increment');
const count = screen.getByText('0');
fireEvent.click(button);
expect(screen.getByText('1')).toBeInTheDocument();
});
// Run: npm test
# test_views.py
from django.test import TestCase, Client
from django.urls import reverse
class PostViewTests(TestCase):
def setUp(self):
self.client = Client()
self.user = User.objects.create_user('test', password='pass')
def test_post_list_view(self):
response = self.client.get(reverse('post_list'))
self.assertEqual(response.status_code, 200)
self.assertContains(response, 'Blog Posts')
def test_create_post_authenticated(self):
self.client.login(username='test', password='pass')
response = self.client.post(reverse('post_create'), {
'title': 'New Post',
'content': 'Content'
})
self.assertEqual(response.status_code, 302)
// e2e/login.spec.js
const { test, expect } = require('@playwright/test');
test('user can login successfully', async ({ page }) => {
await page.goto('http://localhost:3000/login');
await page.fill('input[name="username"]', 'testuser');
await page.fill('input[name="password"]', 'password123');
await page.click('button[type="submit"]');
await expect(page).toHaveURL('http://localhost:3000/dashboard');
await expect(page.locator('h1')).toContainText('Welcome');
});
// Run: npx playwright test
Aim for 80%+ coverage, but quality > quantity
Implement full test suite for your project
# locustfile.py
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(1, 3)
@task(3)
def view_posts(self):
self.client.get("/api/posts/")
@task(1)
def view_post_detail(self):
self.client.get("/api/posts/1/")
# Run: locust -f locustfile.py
# Project Title
Brief description of your project.
## Features
- Feature 1
- Feature 2
## Tech Stack
- Frontend: React, Tailwind CSS
- Backend: Django, PostgreSQL
- Deployment: Heroku
## Installation
\`\`\`bash
git clone https://github.com/user/project.git
cd project
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver
\`\`\`
## Usage
Visit http://localhost:8000
## Testing
\`\`\`bash
pytest
\`\`\`
## License
MIT
Options: Heroku, Railway, Render, PythonAnywhere
Pros: Easy setup, managed infrastructure, auto-scaling
Cons: Less control, more expensive at scale
Options: AWS EC2, DigitalOcean, Google Cloud, Azure
Pros: Full control, cost-effective at scale
Cons: More setup, requires DevOps knowledge
Options: Vercel, Netlify (frontend), AWS Lambda (backend)
Pros: Auto-scaling, pay per use, zero maintenance
Cons: Cold starts, limited execution time
# .github/workflows/django.yml
name: Django CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Install dependencies
run: pip install -r requirements.txt
- name: Run tests
run: pytest
- name: Deploy
if: github.ref == 'refs/heads/main'
run: # deployment command
Deploy your application to a live production environment
Project name, your name, date
What problem? Why does it matter? Your solution
System diagram, tech stack
Screenshots, key functionality
What was hard? How did you solve it?
Coverage, performance, security
Achievements, lessons learned, future work
🎉
Remember:
Contact: JWilliams@Staff.newman.ac.uk
Good luck with your projects and future careers!