Home / Past papers / MAD1 End Term / this paper
Consider the following Python code snippet. file.py
```python
from jinja2 import Template
import sys
input_list = sys.argv
var_a, var_b = input_list[1], input_list[2]
if input_list[1]=="Meera":
var_b = "Data Analyst"
elif input_list[1]=="Radha":
var_b = "Scientist"
else:
pass
template = "{{{var_a}}} is {{{var_b}}}"
t = Template(template)
print(t.render(var_a = var_a, var_b = var_b))
```
Map the commands in column A with the output on the terminal in column B.
| Column A | Column B |
| :------------------------------------- | :------------------------ |
| a) python file.py Radha Data Analyst | 1) Meera is Scientist |
| b) python file.py Meera Scientist | 2) Sneha is Web |
| c) python file.py Sneha Web Developer | 3) Meera is Data Analyst |
| | 4) Radha is Data Analyst |
| | 5) Radha is Scientist |
| | 6) Sneha is Web developer |
Consider the following HTML document. ```html
<!DOCTYPE html>
<html>
<head>
<style>
span {
background-color: yellow;
color: red;
}
#id {
border: 2px solid purple;
color:blue ;
display: inline-block;
}
.class {
background-color: aqua;
color: red;
display: block;
width:20%;
}
</style>
</head>
<body>
<span class="class" id="id">SPAN</span>
<span class="class" >SPAN</span>
<span>SPAN</span>
</body>
</html>
```
How will the browser render above HTML file?
The image displays three rectangular boxes arranged horizontally. 1. The first box is wide, filled with a bright cyan color, and has a dark purple border. Inside, the word "SPAN" is written in blue text. 2. The second box is narrower, filled with a bright cyan color, and has no visible border. Inside, the word "SPAN" is written in red text. 3. The third box is also narrower, filled with a bright yellow color, and has no visible border. Inside, the word "SPAN" is written in orange text.

The image displays three rectangular blocks, each containing the text "SPAN". 1. The first block has a cyan background with a purple border. The text "SPAN" is dark blue. 2. The second block has a cyan background with no visible border. The text "SPAN" is red with a slight shadow effect. 3. The third block has a yellow background with no visible border. The text "SPAN" is orange.

The image displays three horizontal rectangular blocks stacked vertically. The top block has a cyan background with the word "SPAN" in blue text. It has a purple border around it. The middle block has a cyan background with the word "SPAN" in red text. The bottom block has a yellow background with the word "SPAN" in orange text.

The image displays three horizontal rectangular blocks, stacked vertically. 1. The top block has a light blue background with a purple border. Inside, the word "SPAN" is written in blue text. 2. The middle block has a light blue background. Inside, the word "SPAN" is written in red text. 3. The bottom block has a yellow background. Inside, the word "SPAN" is written in orange text.
Consider the following flask application. app.py
```python
from flask import Flask, request
app = Flask(__name__)
@app.route('/calculate')
def calculate():
a = request.args.get('a')
b = request.args.get('b')
operator = request.args.get('operator')
if a and b and operator:
if operator == 'one':
return f'{a} + {b} = {int(a)+int(b)}'
elif operator == 'two':
return f'{a} - {b} = {int(a) - int(b)}'
elif operator == 'three':
return f'{a} x {b} = {int(a)*int(b)}'
else:
return 'Error: Insufficient arguments'
app.run(debug=True)
```
If the application is running locally on http://127.0.0.1:5000 then match the URLs with their rendered output?
| | URLs | | Output |
|---|---|---|---|
| 1 | http://localhost:5000/calculate?a=4&b=2&operator=two | a | 4 x 2 = 8 |
| 2 | http://localhost:5000/calculate?a=4&b=2&operator=three | b | 4 + 2 = 6 |
| 3 | http://localhost:5000/calculate?a=4&b=2&operator=one | c | 4 - 2 = 2 |
| | | d | 4 + 2 = 42 |
| | | e | 4 x 2 = 2222 |
Which of the following flask view functions will return a 200 OK for the URL: http://127.0.0.1:5000/details/1001/Michael ?

```python
@app.route('/details/<int:id>/<string:name>')
def show(id, name):
details = {'student_id': id, 'student_name': name}
return details
```
```python
@app.route('/details/<string:id>/<string:name>')
def show(id, name):
details = {'student_id': id, 'student_name': name}
return details
```
```python
@app.route('/details/<id>/<name>')
def show(id, name):
details = {'student_id': id, 'student_name': name}
return details
```
All of these

Consider a function func, and a set of test cases given below.
Filename: test_file.py
```python
import pytest
def func(x,y):
out = x**2+y**2
return out
class Test_class0():
def test_case1(self):
assert func(1,2) == 5
def case_test2(self):
assert func(2,3) == 13
def case_test3(self):
assert func(6,2) == 38
class Test_class1():
def test_case1(self):
assert func(5,2) == 29
def case_test2(self):
assert func(1,1) == 2
```
What will be the output on the terminal for the command below?
pytest test_file.py -k Test_class
``` == 1 failed, 4 passed in 0.17s === ```

``` == 2 passed, 3 deselected in 0.17s === ```

```text == 2 passed in 0.07s === ```

``` == 3 failed, 2 passed in 0.17s === ```

Consider the below two python files code snippets *app.py* and *test_app_route.py*.
**app.py**
```python
from flask import Flask
app = Flask(__name__)
@app.route("/greet/<string:name>")
def home(name):
return "Hello, " + name
if __name__ == "__main__":
app.run()
```
**test_app_route.py:**
```python
import pytest, requests
@pytest.fixture
def get_response():
resp = requests.get("http://127.0.0.1:5000/greet/IITM")
return resp
def test_response(get_response):
assert get_response.text == "Hello, IITM"
```
Assume that *app.py* and *test_app_route.py* are running on two different terminals. And also all required modules are installed. Which of the below statement(s) are True?
i) Executing the command `pytest test_app_route.py` on the terminal returns
`========== 1 passed ==========`
ii) Executing the command `pytest test_app_route.py` on the terminal returns
`========== 1 failed ==========`
iii) Executing the command `pytest test_app_route.py` on the terminal returns
`========== 1 selected, 1 passed ==========`
iv) Executing the command `pytest test_app_route.py` on the terminal returns
`========== 1 deselected ==========`
Consider the following flask resource created using flask_restful.
```python
from flask import Flask, request
from flask_restful import Api, Resource, reqparse
app = Flask(__name__)
api = Api(app)
parser = reqparse.RequestParser()
parser.add_argument("val")
class RestApi(Resource):
def post(self, val):
arg1 = parser.parse_args()
arg2 = request.args
return {
"Course_1": arg1["val"],
"Course_2": arg2["val"],
"Course_3": val
}
api.add_resource(RestApi, "/api/courses/<val>")
app.run(debug = True)
```
If the application is running locally on http://127.0.0.1:5000, What will be the output on the terminal for the command:
```bash
curl http://127.0.0.1:5000/api/courses/DBMS?val=JAVA -d "{\"val\":\"PDSA\"}" -X POST -H "Content-Type: application/json"
```
```json
{
"Course_1": "JAVA",
"Course_2": "PDSA",
"Course_3": "DBMS"
}
```
```json
{
"Course_1": "DBMS",
"Course_2": "JAVA",
"Course_3": "PDSA"
}
```
```json
{
"Course_1": "PDSA",
"Course_2": "JAVA",
"Course_3": "DBMS"
}
```
```json
{
"Course_1": "PDSA",
"Course_2": "DBMS",
"Course_3": "JAVA"
}
```

A flask application shown below is running locally on http://127.0.0.1:5000.
```python
from flask import Flask, request, session, abort
app = Flask(__name__)
app.config['SECRET_KEY'] = "yekterces"
@app.route('/login')
def log_in():
user = request.args['user']
role = request.args['role'] if 'role' in request.args else \
'general'
session['user'], session['role'] = user, role
return "Logged in successfully!"
@app.route('/home')
def land():
if 'user' in session:
if session['role'] == 'admin':
return f"Welcome {session['user']}"
return abort(401)
return abort(404)
@app.route('/logout')
def log_out():
session.pop('user', None)
session.pop('role', None)
return "Logged out sucessfully!"
app.run(debug=True)
```
If the application is running locally on http://127.0.0.1:5000. What will be the correct sequence of response status codes if the client visits the URLs one by one in the sequence given below?
1. http://127.0.0.1:5000/home
2. http://127.0.0.1:5000/login/admin
3. http://127.0.0.1:5000/login?user=admin
4. http://127.0.0.1:5000/home
5. http://127.0.0.1:5000/logout
401 401 200 404 200

404 200 200 200 200

404 404 200 401 200

404 200 404 200 200

Consider the following flask application.
Python file: app.py
```python
from flask import Flask, render_template, request
app = Flask(__name__)
emp = {'admin':'manoj', 'user':'sumit'}
@app.route('/profile/<user>')
def profile(user):
access = request.args.get('access')
if emp[access] != user:
return render_template("profile.html", user = user,
access = access, error = True)
return render_template("profile.html", user = user,
access = access, error = False)
app.run()
```
Template file: profile.html
```html
<body>
<div>
{% if error %}
<h3>Hi {{user}}, {{access}} access denied</h3>
{% else %}
<h3>Hi {{user}}, you are logged in as {{access}}.</h3>
{% endif %}
</div>
</body>
```
If the application is running locally on http://127.0.0.1:5000, then what will be rendered by the browser for URL,
http://127.0.0.1:5000/profile/sumit?access=admin ?
Hi sumit, you are logged in as admin.

Hi sumit, you are logged in as user.

Hi sumit, admin access denied.

Hi sumit, user access denied.

Consider the following models Library and Book corresponding to tables
library and book in SQLite database.
```python
class Library(db.Model):
id = db.Column(db.Integer(), primary_key = True)
name = db.Column(db.String(), unique = True)
class Book(db.Model):
id = db.Column(db.Integer(), primary_key = True)
name = db.Column(db.String(), unique = True)
library = db.Column(db.Integer(), db.ForeignKey("library.id"))
```
Based on the model schemas, what relationship do the classes Library and Book
share?
Consider the following Python code snippet.
log.py
```python
import logging
import sys
logging.basicConfig(level=logging.WARNING,
format='%(asctime)s - %(levelname)s - %(message)s')
def check_val(value):
if value < 0:
raise ValueError("Invalid value: Please enter a positive value.")
else:
logging.info("Value added: %s", value)
try:
input_value = -int(sys.argv[1])
check_val(input_value)
except ValueError as ve:
logging.exception("Exception occurred: %s", str(ve))
```
What will be the output on the terminal for the command: `python log.py -12`?
2023-08-14 21:01:05,684 - INFO - Value added: 12

2023-08-14 21:01:05,684 - WARNING - Value added: -12

Error: Exception occurred: Invalid value: Please enter a positive value.

None of these
Consider the following graph that represents the variation in bandwidth of a network for an entire day (24 hours). Three users were connected to the network at three different times of the day. What is the total data consumed in GigaBytes by all the users in 24 hrs? This is a line graph titled "Megabits/s" on the y-axis. The x-axis is labeled "Time (Hours)" and ranges from 0 to 24, with major ticks at 0, 4, 8, 12, 14, 16, 20, and 24. The y-axis is labeled "BandWidth" and ranges from 0 to 12, with major ticks at 0, 2, 4, 6, 8, 10, and 12. There is an orange step-function line representing bandwidth over time. - From Time 0 to 4, BandWidth is 8. - From Time 4 to 8, BandWidth is 10. - From Time 8 to 12, BandWidth is 6. - From Time 12 to 14, BandWidth is 8. - From Time 14 to 16, BandWidth is 2. - From Time 16 to 20, BandWidth is 2. - From Time 20 to 24, BandWidth is 10. There are three horizontal colored lines above the main graph, each labeled with a user. These lines indicate time intervals. - A blue line labeled "user 1" extends from Time 0 to Time 4. - A yellow line labeled "user 2" extends from Time 8 to Time 14. - A green line labeled "user 3" extends from Time 16 to Time 24.

Consider the below flask application.
```python
from flask_sqlalchemy import SQLAlchemy
from flask import Flask
app = Flask (__name__)
app.config ['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///testdb.sqlite3'
db = SQLAlchemy(app)
app.app_context().push()
class Material(db.Model):
m_id = db.Column('m_id', db.Integer, primary_key = True)
name = db.Column('name', db.String(100), unique = True)
db.create_all()
material1 = Material(name = 'Steel')
db.session.add(material1)
material2 = Material(name = 'Iron')
material3 = Material(name = 'Aluminium')
db.session.add(material2)
db.session.commit()
db.session.add(material3)
all_material = Material.query.all()
print([(x.m_id, x.name) for x in all_material])
```
If you run the flask application using a terminal. What will be the output in the terminal?
``` [(1, 'Steel'), (2, 'Iron')] will be displayed in the terminal and two records will be added in the "testdb" database. ```

``` [(1, 'Steel'), (2, 'Iron'), (3, 'Aluminium')] will be displayed in the terminal and three records will be added in the "testdb" database. ```

``` [(1, 'Steel'), (2, 'Iron'), (3, 'Aluminium')] will be displayed in the terminal and two records will be added in the "testdb" database. ```

``` [(1, 'Steel', 2, 'Iron', 3, 'Aluminium')] will be displayed in the terminal and two records will be added in the "testdb" database. ```

A client machine C is 18000 kms away from the server machine S. A router R is situated somewhere in between the client C and the server S and is connected to client C with cable and makes aerial connection with the server S. What will be the round-trip latency (milliseconds) of the network if the router is placed at exactly midway from the client and the server? [Assume: The speed of light on cable is 1.5 x 10⁸ m/s and in air is 3 x 10⁸ m/s. The client, server and the router lie on a straight line]
Consider the following flask app and Jinja2 template. app.py
```python
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index.html", data=['Harry', 'Karl', 'John',
'Jason', 'Ros'])
app.run()
```
index.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Macro</title>
</head>
<body>
{% macro unordered_list(items)%}
<ul>
{% for item in items %}
{% if item|length >= 5 %}
<li>{{item}}</li>
{% endif %}
{% endfor %}
</ul>
{% endmacro %}
{{ unordered_list(data) }}
</body>
</html>
```
If the flask app is running locally on http://127.0.0.1:5000. What will be the output on the browser for the base URL?
- Harry - Karl - John - Jason - Ros

- Karl - John

- Harry - Jason

- Karl - John - Ros

Match the following types of testing with their functionality. | | | |---|---| | A. Regression testing | 1. Beta Testing | | B. User Acceptance testing | 2. one step beyond integration testing, includes server and environment | | C. System Testing | 3. Simulates actual user interaction, allows to script browser | | D. System testing Automation | 4. Type of testing that runs after every change to ensure that the change introduces no unintended breaks. | Which of the following is the correct matching?

Consider the following python code snippet app.py, the HTML files, base.html and home.html residing in "templates" folder.
app.py
```python
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
app.run(debug=True)
```
home.html
```html
{% extends "base.html" %}
{% block content %}
<p>MAD I</p>
<span>MAD II</span>
<p>DBMS</p>
{% endblock %}
```
base.html
```html
<!DOCTYPE html>
<html lang="en">
<head>
<title>IITM</title>
</head>
<body>
<h2 style="color: violet;"> Diploma Courses </h2>
{% block content %}
{% endblock %}
</body>
</html>
```
What will be the rendered output for base URL if flask app is running locally on http://localhost:5000 ?
MAD I MAD II DBMS

Diploma Courses MAD I MAD II DBMS

Diploma Courses MAD I MAD II DBMS

MAD I MAD II DBMS

The hexadecimal equivalent of the IPv4 address 172.16.254.10 would be ________.
Consider the following Python code snippet “code.py”. Filename: code.py
```python
import sys
from jinja2 import Template
vars = sys.argv
course_technologies = {'python': 'backend', 'javascript': 'frontend'}
template = Template("This course focuses on {{ technology }} development.")
if len(vars) > 2 and vars[2] in course_technologies:
course = vars[1]
technology = course_technologies[course]
print(template.render(technology=technology))
else:
print("Please specify a valid course name!")
```
Which of the following will be the correct command line input to the terminal to get the output: This course focuses on backend development. ?
python code.py course python

python code.py python javascript

python code.py python python

``` python code.py python backend ```
Consider the following flask application. app.py
```python
from flask import Flask, abort, request
app = Flask(__name__)
data = {"CS2001":"DBMS", "CS2003":"MAD-I", "CS2006":"MAD-II"}
@app.route('/login')
def login():
username = request.args.get('uname')
if username not in data:
abort(400, "Bad Request: Invalid Username")
return f'<h1>Welcome to {data[username]} course!</h1>'
app.run(debug=True)
```
Which of the following statements is/are true if the application is running locally on http://127.0.0.1:5000 ?
For URL http://127.0.0.1:5000?uname=CS2001 the browser will render **Welcome to DBMS course!**

For URL http://127.0.0.1:5000/login the browser will render **Welcome to MAD-I course!**

For URL http://127.0.0.1:5000/login?uname the browser will render Bad Request: Invalid Username

For URL http://127.0.0.1:5000/login?uname=CS2006 the browser will render **Welcome to MAD-II course!**
Consider the following flask application. ```python
from flask import Flask, request
app = Flask(__name__)
@app.route('/home')
def home():
var_a = request.args.get('method')
if var_a == "GET":
return "Hello from GET method"
elif var_a == "POST":
return "Hello from POST method"
else:
return "Invalid Method"
app.run(debug=True)
```
If the application is running locally on http://127.0.0.1:5000 then which of the following statements are correct?
The command `curl -X GET http://127.0.0.1:5000/home?method=GET` will give output as `Hello from GET method` on terminal

The command `curl -X POST http://127.0.0.1:5000/home?method=POST` will give output as `Method not Allowed` on terminal

The command `curl -X POST http://127.0.0.1:5000/home?method=POST` will give output as `Hello from POST method` on terminal

The command `curl -X POST http://127.0.0.1:5000/home?method` will give output as `Invalid Method` on terminal

Consider the following flask_sqlalchemy data models "User" and "Role".
```python
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(), unique=True, nullable=False)
password = db.Column(db.String(), nullable=False)
email = db.Column(db.String())
roles = db.relationship("Role", backref="bearer")
class Role(db.Model):
id = db.Column(db.Integer, primary_key=True)
r_name = db.Column(db.String(), unique=True, nullable=False)
user = db.Column(db.Integer, db.ForeignKey("user.id"))
```
python shell:
```python
>>> from app import *
>>> db.create_all()
>>> user1 = User(username="Rakesh",password="1234",email="user1@gmail.com")
>>> user2 = User(username="Suresh",password="123",email="user2@gmail.com")
>>> db.session.add_all([user1,user2])
>>> db.session.commit()
>>> r1=Role(r_name="instructor",user=1)
>>> r2=Role(r_name="admin",user=1)
>>> r3=Role(r_name="ops",user=2)
>>> r4=Role(r_name="student",user=2)
>>> db.session.add_all([r1,r2,r3,r4])
>>> db.session.commit()
>>> users = User.query.all()
>>> roles = Role.query.all()
```
If the above commands are run in the python shell then which of the following options is
/are correct with respect to these models?
Command: >>> users Output: ["Ramesh", "Suresh"]

Command: ``` >>> u1 = users[1] >>> u1.roles ``` Output: ``` [<Role 3>, <Role 4>] ```

Command: ``` >>> roles[2].user ``` Output: ``` ["Suresh"] ```

Command: >>> roles[3].user Output: 2

``` Command: >>> roles[0].bearer Output: <User 1> ```

Suppose a request `https://xyz.com?name=amey&age=34` generates the below response on the browser's console,
```
Name : amey
```
The definition of the flask endpoint which handles the above request is given below,
```python
@app.route(code1)
def getData():
data = code2
print("Name :", data)
```
Which of the following options should be used to fill the placeholders "code1" and "code2", to achieve the desired result as shown above?
``` Code1: "/" Code2: request.form['name'] ```

``` Code1: "/", methods = ['GET'] Code2: request.form['name'] ```

```python Code1: "/", methods = ['GET', 'POST'] Code2: request.args['name'] ```

```
Code1: "/"
Code2: request.args.get('name')
```
Consider the following function to be tested and test functions given in the Python code snippet below.
test_file.py
```python
import pytest
def square(x):
sum = 0
for counter in range(x):
sum += x
return sum
@pytest.mark.marker1
def testcase_1():
assert square(10) == 100
@pytest.mark.marker2
def testcase_2():
assert square(4) == 4
@pytest.mark.marker3
def testcase_3():
assert square(5) == 25
@pytest.mark.marker4
def testcase_4():
assert square(6) == 6
```
On running this file on the terminal using pytest, the summary of the output is;
`========= 1 passed, 3 deselected, 4 warnings in 0.04s =========`
What command will result into the outcome given above?
``` pytest test_file.py -m marker4 ```

``` pytest test_file.py -m marker1 ```

``` pytest test_file.py -m marker2 ```

``` pytest test_file.py -m marker3 ```
Consider the following flask application. ```python
from flask import Flask, abort
app = Flask(__name__)
modules = ['python', 'react', 'node']
@app.route('/home/modules/')
def all_modules():
return f"<h3>List of modules: {modules}</h3>"
@app.route('/get/<string:module_1>')
def get_module(module_1):
if module_1 in modules:
return f"<h3>One module found: {module_1}.</h3>"
else:
abort(400)
@app.errorhandler(400)
def module_error(error):
return "<h3>Cannot find module</h3>"
@app.errorhandler(404)
def module_error(error):
return "<h3>Incorrect Path</h3>"
app.run(debug=True)
```
If the application is running locally on http://127.0.0.1:5000, select the correct statement(s).
For the URL, http://127.0.0.1:5000/home/modules, the browser will render, List of modules: ['python', 'react', 'node']

For the URL, http://127.0.0.1:5000/home/modules, the browser will render, **Incorrect Path**

For the URL, http://127.0.0.1:5000/get/vuejs, the browser will render; Cannot find module

For the URL, http://127.0.0.1:5000/get/react/, the browser will render, **One module found: react.**

Consider the following code snippet.
```python
@app.route('/student/<student_id>')
def profile(student_id):
# CODE_BLOCK_HERE
```
Assume the database has a "student" table which has a TEXT column "student_id". If we want the server to return a 404 status code when a user goes to the route '/student/<student_id>' with a student_id that does not exist in the database, which of the following lines would give us the desired output?
```python
student = Student.query.filter_by(student_id=student_id).first()
if student is None:
abort(404)
return render_template('profile.html', student=student)
```
```python
student = Student.query.filter_by(student_id=student_id).first()
if student is None:
return render_template("404.html")
return render_template('profile.html', student=student)
```
```python
student = Student.query.filter_by(student_id=student_id).first_or_404()
return render_template('profile.html', student=student)
```
```python
student = Student.query.filter_by(student_id=student_id).first()
if student is None:
return render_template("404.html"), 404
return render_template('profile.html', student=student)
```

What should be the code to run the application, and what should be the URL respectively such that the browser gives output as: Welcome to Application Development! ?

Code: python app.py Application Development DBMS URL: http://127.0.0.1:5000/course?course=Application Development

Code: python app.py "Application Development" Java URL: http://127.0.0.1:5000/course?course=Application

Code: ``` python app.py Application Development DBMS ``` URL: ``` http://127.0.0.1:5000/course?course=Application ```

Code: ``` python app.py "Application Development" DBMS ``` URL: ``` http://127.0.0.1:5000/course?course=Application Development ```

What will be the output given by browser if the application is run with command ``` python app.py Application Development DBMS ``` on terminal with URL: ``` http://127.0.0.1:5000/course?course=Application Development ? ```

Welcome to Application Development!

Welcome to DBMS!

Invalid Data

Not Found
Auto-generated summary from the source site. Handy as a checklist; the lessons above explain each idea from scratch.
Here’s a structured summary of core topics, concepts, principles, and equations essential for the exam, followed by Mermaid knowledge graphs to visualize relationships.
Flask Routing & Dynamic URLs:
@app.route('/path/<variable_type:variable_name>')int, string, float, path, uuid.Example:
@app.route('/user/<int:user_id>')
def show_user(user_id):
return f"User ID: {user_id}"HTTP Methods (GET/POST):
request.args (for GET query parameters).request.form (for POST form data).Example:
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']Error Handling:
abort(404) (returns 404 error).@app.errorhandler(404).Jinja2 Templating:
render_template("file.html", var=value).{% if condition %} ... {% endif %}.{% for item in list %} ... {% endfor %}.{% extends "base.html" %}, {% block content %}).Sessions & Cookies:
session['key'] = value (requires app.secret_key).session.pop('key') (clears session data).Flask Testing:
pytest for unit testing.requests.get().Example test:
def test_home_page():
response = app.test_client().get('/')
assert response.status_code == 200Bandwidth Calculation (Q7, Q21):
CSS Specificity:
!important > Inline styles > IDs > Classes > Elements.#id overrides .class.Display Properties:
inline (no width/height), block (full width), inline-block (mix).Box Model:
margin, border, padding, content.Selectors:
span), Class (.class), ID (#id).Latency Calculation (Q17):
Bandwidth vs. Data Consumption (Q15):
| Testing Type | Description |
|---|---|
| Regression Testing | Ensures new changes don’t break existing functionality. |
| User Acceptance Testing | Validates software with end-users (e.g., beta testing). |
| System Testing | Tests the complete system (hardware + software + environment). |
| Test Automation | Uses tools (e.g., Selenium) to simulate user interactions. |
1 passed: Test succeeded.1 failed: Test assertion failed.1 deselected: Test skipped (e.g., missing dependencies).404: Resource not found (Flask abort(404)).Relationships:
User → Posts).Students ↔ Courses).Flask-SQLAlchemy:
Model.query.filter_by(field=value).first().first_or_404() (returns 404 if not found).Convert each decimal octet to hex:
172 → AC, 16 → 10, 254 → FE, 10 → 0A.AC.10.FE.0A (or AC10FE0A without dots).Stateless Protocol (HTTP):