Day 15 · 1 Hour
Industry Simulation
Feature branches, pull requests, pytest — your first day at a real company, simulated.
🔥 Real-World Hook (0–5 min)
Your first day at a company: senior hands you a codebase, a Jira ticket, and says "make a PR by end of day." No guidance. No step-by-step.
Today that's exactly what happens. You get a real git workflow — feature branches, pull requests, code review. You write pytest tests. You fix a deliberately broken feature. This is the gap between "I know Python" and "I'm ready to work at a company."
🌳 Git-Flow + pytest in 1 Hour (5–25 min)
💡 Industry Git Workflow
Never commit to main. Create a feature branch — git checkout -b feature/add-borrow-limit. Write code. Write tests. Push branch. Open PR. Get reviewed. Merge.
This is how every company from 5-person startups to Google works. Get used to it today.
💻 Live Coding — Testing with pytest (25–45 min)
# pip install pytest pytest-django # conftest.py (tells pytest about Django settings) import pytest from django.test import RequestFactory @pytest.fixture def api_client(): from rest_framework.test import APIClient return APIClient() @pytest.fixture def sample_student(db): from students.models import Student return Student.objects.create( name="Priya", email="p@test.com", dept="CS", gpa=3.9 )
# tests/test_students.py import pytest @pytest.mark.django_db def test_student_list(api_client, sample_student): res = api_client.get("/api/students/") assert res.status_code == 200 assert len(res.json()) == 1 @pytest.mark.django_db def test_create_student(api_client): data = {"name":"Ravi","email":"r@test.com","dept":"IT","gpa":3.2} res = api_client.post("/api/students/", data, format="json") assert res.status_code == 201 assert res.json()["name"] == "Ravi" @pytest.mark.django_db def test_gpa_validation(api_client): # GPA can't be negative data = {"name":"Bad","email":"b@test.com","dept":"CS","gpa":-1.0} res = api_client.post("/api/students/", data, format="json") assert res.status_code == 400 # should reject # Run: pytest -v # ✓ test_student_list PASSED # ✓ test_create_student PASSED # ✓ test_gpa_validation PASSED
🍴 Git Workflow — Feature Branch → PR
# Industry standard: never commit directly to main git checkout -b feature/add-borrow-limit # ... write code and tests ... git add . git commit -m "feat: add borrow limit of 3 books per member" git push origin feature/add-borrow-limit # GitHub: Create Pull Request # PR title: "feat: add borrow limit" # Description: What changed, why, how to test # Request review from a classmate # After approval: merge to main git checkout main git pull git branch -d feature/add-borrow-limit
🎯 Industry Simulation — Your Final Challenge (45–55 min)
- Create branch:
git checkout -b feature/search-enhancement - Add a custom search endpoint:
GET /api/students/search/?q=termthat searches name AND email - Write 3 pytest tests for this endpoint: empty query, matching results, no results
- Run
pytest -v— all 3 must pass - Commit with proper message:
feat: add multi-field student search endpoint - Push branch, open a PR on GitHub, assign a classmate as reviewer
- Show: PR open, green tests, reviewer assigned. You are ready for Day 1 at a company.
📄 Day 15 Cheat Sheet — pytest + Git-Flow
pytest
| pip install pytest pytest-django | Install |
| def test_name(...): | Test function |
| assert x == y | Assert equality |
| @pytest.mark.django_db | Enable DB access |
| @pytest.fixture | Reusable setup |
| pytest -v | Run verbose |
DRF Test Client
| APIClient() | Test HTTP client |
| client.get("/url/") | GET request |
| client.post("/url/", data, format="json") | POST JSON |
| client.force_authenticate(user) | Login in test |
| res.status_code | HTTP status |
| res.json() | Response body |
Git Feature Branch
| git checkout -b feature/name | Create + switch |
| git branch | List branches |
| git push origin feature/name | Push branch |
| git checkout main | Switch to main |
| git merge feature/name | Merge |
| git branch -d feature/name | Delete local |
Commit Convention
| feat: add search | New feature |
| fix: handle empty query | Bug fix |
| test: add search tests | Tests only |
| docs: update README | Documentation |
| refactor: simplify filter | Code cleanup |
| chore: update deps | Maintenance |