├── .gitignore ├── Unit-01 ├── 01-flask-intro │ ├── app.py │ ├── readme.md │ └── test.py ├── 02-flask-routing │ ├── app.py │ ├── readme.md │ └── test.py ├── 03-templating │ ├── app.py │ ├── readme.md │ └── test.py ├── 04-flask-crud │ ├── app.py │ ├── readme.md │ ├── snack.py │ └── test.py ├── 05-sql-flask │ ├── app.py │ ├── db.py │ ├── readme.md │ └── test.py ├── 06-sql-alchemy-1 │ ├── readme.md │ └── test.py ├── 07-sql-alchemy-2 │ ├── readme.md │ └── test.py ├── 08-testing │ └── readme.md └── 09-forms │ ├── readme.md │ └── test.py ├── Unit-02 ├── 01-blueprints │ ├── readme.md │ └── test.py ├── 02-many-to-many │ ├── readme.md │ └── test.py ├── 03-hashing-sessions │ ├── readme.md │ └── test.py ├── 04-flask-login │ ├── readme.md │ └── test.py └── 05-oauth │ └── readme.md └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | __pycache__ 3 | *.db 4 | -------------------------------------------------------------------------------- /Unit-01/01-flask-intro/app.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rithmschool/python_curriculum_exercises/f68dacf80e1ee5688ff64973f9d875a1b0c82111/Unit-01/01-flask-intro/app.py -------------------------------------------------------------------------------- /Unit-01/01-flask-intro/readme.md: -------------------------------------------------------------------------------- 1 | # Flask Basics 2 | 3 | For this assignment you will be creating a very small flask application. Your application should: 4 | 5 | - have a route for `/welcome`, which responds with the string "welcome" 6 | - have a route for `/welcome/home`, which responds with the string "welcome home" 7 | - have a route for `/welcome/back`, which responds with the string "welcome back" 8 | 9 | ### Bonus 10 | 11 | Add another route to `/sum` and inside the function which sends a response, create a variable called `sum` which is equal to 5+5. Respond with the sum variable. 12 | -------------------------------------------------------------------------------- /Unit-01/01-flask-intro/test.py: -------------------------------------------------------------------------------- 1 | from app import app 2 | import unittest 3 | 4 | class TestSimpleRoutes(unittest.TestCase): 5 | 6 | def test_welcome(self): 7 | tester = app.test_client(self) 8 | response = tester.get('/welcome', content_type='html/text') 9 | self.assertIn(b'welcome', response.data) 10 | self.assertEqual(response.status_code, 200) 11 | 12 | def test_welcome_home(self): 13 | tester = app.test_client(self) 14 | response = tester.get('/welcome/home', content_type='html/text') 15 | self.assertIn(b'welcome home', response.data) 16 | self.assertEqual(response.status_code, 200) 17 | 18 | def test_welcome_back(self): 19 | tester = app.test_client(self) 20 | response = tester.get('/welcome/back', content_type='html/text') 21 | self.assertIn(b'welcome back', response.data) 22 | self.assertEqual(response.status_code, 200) 23 | 24 | def test_sum(self): 25 | tester = app.test_client(self) 26 | response = tester.get('/sum', content_type='html/text') 27 | self.assertIn(b'10', response.data) 28 | self.assertEqual(response.status_code, 200) 29 | 30 | if __name__ == '__main__': 31 | unittest.main() -------------------------------------------------------------------------------- /Unit-01/02-flask-routing/app.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rithmschool/python_curriculum_exercises/f68dacf80e1ee5688ff64973f9d875a1b0c82111/Unit-01/02-flask-routing/app.py -------------------------------------------------------------------------------- /Unit-01/02-flask-routing/readme.md: -------------------------------------------------------------------------------- 1 | # Flask Routing 2 | 3 | Build a simple calculator! You should have routes that can perform addition, subtraction, multiplication and division with two numbers so if a request is made to `/add/2/2` the server should respond with `4`. 4 | 5 | ### Bonus 6 | 7 | Refactor your code so that all of these operations can be done in a single route called `/math` 8 | 9 | 10 | -------------------------------------------------------------------------------- /Unit-01/02-flask-routing/test.py: -------------------------------------------------------------------------------- 1 | from app import app 2 | import unittest 3 | 4 | class TestCalculator(unittest.TestCase): 5 | 6 | def test_add(self): 7 | tester = app.test_client(self) 8 | response = tester.get('/add/2/2', content_type='html/text') 9 | self.assertIn(b'4', response.data) 10 | self.assertEqual(response.status_code, 200) 11 | 12 | def test_subtract(self): 13 | tester = app.test_client(self) 14 | response = tester.get('/subtract/2/2', content_type='html/text') 15 | self.assertIn(b'0', response.data) 16 | self.assertEqual(response.status_code, 200) 17 | 18 | def test_multiply(self): 19 | tester = app.test_client(self) 20 | response = tester.get('/multiply/20/2', content_type='html/text') 21 | self.assertIn(b'40', response.data) 22 | self.assertEqual(response.status_code, 200) 23 | 24 | def test_division(self): 25 | tester = app.test_client(self) 26 | response = tester.get('/divide/2/2', content_type='html/text') 27 | self.assertIn(b'1', response.data) 28 | self.assertEqual(response.status_code, 200) 29 | 30 | def test_all_in_one(self): 31 | tester = app.test_client(self) 32 | response = tester.get('/math/add/2/2', content_type='html/text') 33 | self.assertIn(b'4', response.data) 34 | self.assertEqual(response.status_code, 200) 35 | 36 | response = tester.get('/math/subtract/2/2', content_type='html/text') 37 | self.assertIn(b'0', response.data) 38 | self.assertEqual(response.status_code, 200) 39 | 40 | response = tester.get('/math/multiply/2/20', content_type='html/text') 41 | self.assertIn(b'40', response.data) 42 | self.assertEqual(response.status_code, 200) 43 | 44 | response = tester.get('/math/divide/2/2', content_type='html/text') 45 | self.assertIn(b'1', response.data) 46 | self.assertEqual(response.status_code, 200) 47 | 48 | 49 | if __name__ == '__main__': 50 | unittest.main() -------------------------------------------------------------------------------- /Unit-01/03-templating/app.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rithmschool/python_curriculum_exercises/f68dacf80e1ee5688ff64973f9d875a1b0c82111/Unit-01/03-templating/app.py -------------------------------------------------------------------------------- /Unit-01/03-templating/readme.md: -------------------------------------------------------------------------------- 1 | # Flask Templating 2 | 3 | Create a new Flask application with the following: 4 | 5 | ### Part 1 6 | 7 | - A `base.html` template for others to inherit from 8 | - A route for `/person//` which renders a template that displays the name and age entered for the URL. That template should inherit from `base.html` 9 | 10 | ### Part 2 11 | 12 | Refactor your calculator application from before! 13 | 14 | - have a route for `/calculate` which renders a template called `calc.html` 15 | - in `calc.html`, build a form which has two inputs (one with a name of `num1` and another with the name of `num2`for numbers and a select field with the name of `calculation` with options for "add", "subract", "multiply" and "divide". 16 | - When the form is submitted it should make a request to a route called `/math` 17 | - In your python file, accept the values from the form and depending on what the request contains, respond with the sum, difference, product or quotient. 18 | 19 | ### Part 3 20 | 21 | Create a small application which grabs headlines from Google News by keyword. (This application is based on the [Google News web scraper](https://www.rithmschool.com/courses/python-fundamentals-part-2/python-web-scraping-exercises) from the web scraping exercises.) 22 | 23 | - This application should consist of two routes, `/` and `/results` 24 | - When the server receives a request to `/`, it should render an HTML page with a form prompting the user for a keyword (e.g. "California"). Submitting the form should result in a request to `/results`, with the form input passed in the [query string](https://en.wikipedia.org/wiki/Query_string). 25 | - When the server receives a request to `/results`, it should do the following: 26 | 1. Grab the keyword from the query string; 27 | 2. Make a request to `https://news.google.com`, and scrape the respose HTML for all news articles (links and headlines); 28 | 3. Filter out articles whose headlines do not match the keyword passed in from the query string; 29 | 4. Render an HTML page with matching articles (links and headlines) in a list. 30 | 31 | -------------------------------------------------------------------------------- /Unit-01/03-templating/test.py: -------------------------------------------------------------------------------- 1 | from app import app 2 | import unittest 3 | 4 | class TestTemplateRoutes(unittest.TestCase): 5 | 6 | def test_welcome(self): 7 | tester = app.test_client(self) 8 | response = tester.get('/person/bob/20', content_type='html/text') 9 | self.assertIn(b'bob', response.data) 10 | self.assertIn(b'20', response.data) 11 | 12 | response = tester.get('/person/bob/20', content_type='html/text') 13 | self.assertEqual(response.status_code, 200) 14 | 15 | response = tester.get('/person/bob', content_type='html/text') 16 | self.assertEqual(response.status_code, 404) 17 | 18 | response = tester.get('/person', content_type='html/text') 19 | self.assertEqual(response.status_code, 404) 20 | 21 | def test_calculate(self): 22 | tester = app.test_client(self) 23 | response = tester.get('/calculate', content_type='html/text') 24 | self.assertIn(b'add', response.data) 25 | self.assertIn(b'subtract', response.data) 26 | self.assertIn(b'multiply', response.data) 27 | self.assertIn(b'divide', response.data) 28 | self.assertEqual(response.status_code, 200) 29 | 30 | def test_math(self): 31 | tester = app.test_client(self) 32 | response = tester.get('/math?num1=10&num2=20&calculation=add', content_type='html/text') 33 | self.assertIn(b'30', response.data) 34 | self.assertEqual(response.status_code, 200) 35 | 36 | response = tester.get('/math?num1=10&num2=20&calculation=subtract', content_type='html/text') 37 | self.assertIn(b'-10', response.data) 38 | self.assertEqual(response.status_code, 200) 39 | 40 | response = tester.get('/math?num1=10&num2=120&calculation=multiply', content_type='html/text') 41 | self.assertIn(b'1200', response.data) 42 | self.assertEqual(response.status_code, 200) 43 | 44 | response = tester.get('/math?num1=20&num2=20&calculation=divide', content_type='html/text') 45 | self.assertIn(b'1', response.data) 46 | self.assertEqual(response.status_code, 200) 47 | 48 | def test_index(self): 49 | tester = app.test_client(self) 50 | response = tester.get('/', content_type='html/text') 51 | self.assertIn(b'