Home / MAD1 / Week 10 / Real questions
60 questions pulled from past papers whose wording matches this week's topics, newest first, duplicates removed. Pick your answers, then press Check answers. Figures and answer keys are the originals.

File name: test_cases.py
```python
def square(n):
return n*n
def test1():
assert square(5)==25
def test2():
assert square(square(2))==16
def test3():
assert square(square(2))==8
```
Assume that the above code is executed using the command “**pytest -v test_cases.py**”. What is the output of the tested code?
``` test_cases.py::test1 PASSED test_cases.py::test2 PASSED test_cases.py::test3 FAILED ```

``` test_cases.py::test1 PASSED test_cases.py::test2 FAILED test_cases.py::test3 FAILED ```

``` test_cases.py::test1 PASSED test_cases.py::test2 FAILED test_cases.py::test3 PASSED ```

``` test_cases.py::test1 PASSED test_cases.py::test2 PASSED test_cases.py::test3 PASSED ```

``` curl -X POST -d "email=user@test.com&password=secret" https://auth/signin ```
Which of these is the correct output when the command
is run in the terminal?```
test_users.py
```
test_users.py
```python
import pytest
@pytest.fixture
def users():
return { "emails": ["alice@test.com", "bob@test.com"], "roles":
["admin", "user"]}
def test_email(users):
assert "alice@test.com" in users['emails']
def test_role(users):
assert users['roles'][0] == "admin"
```
```
"pytest -k email"
```
allows code to be tested without a server, which of the following statements is correct?

```
test_request_context()
```
```python
from flask import Flask, url_for
app = Flask(__name__)
@app.route('/api')
def api():
return 'API Response'
@app.route('/data/<category>')
def data(category):
return f'Data for {category}'
with app.test_request_context():
#== print statement ==#
```
is replaced by
, the output on the terminal will be 
```python
#=== print statement ===#
```
```python
print(url_for('data', category='sales'))
```
```
/data?category=sales
```
is replaced by
, the output on the terminal will be 
```python
#=== print statement ===#
```
```python
print(url_for('data', category='sales', format='json'))
```
```
/data/sales/json
```
is replaced by
, the output on the terminal will be 
```python
#=== print statement ===#
```
```python
print(url_for('api', category='sales'))
```
```
/api?category=sales
```
is replaced by
, the output on the terminal will be 
```python
#=== print statement ===#
```
```python
print(url_for('api'))
```
/api

```python
def generate_series(n):
seq = []
for i in range(1, n+1):
seq.append(i * 3)
return seq
def test_case1():
assert 9 in generate_series(3)
def test_case2():
assert 21 in generate_series(6)
def test_case3():
assert 30 in generate_series(8)
```
What will be the summary of the output for the command `pytest file.py` on the terminal?
``` =========== 1 failed, 2 passed in 0.30s =========== ```

``` ========== 2 failed, 1 passed in 0.30s ========== ```

``` =================================== 3 failed in 0.30s =================================== ```

```text ============================= 1 failed, 1 passed in 0.30s ============================= ```

Given the following test code:
```python
def test_about(client):
response = client.get('/about')
assert response.status_code == 200
assert b'This is the about page.' in response.data
```
Assume the client fixture works correctly and you are testing a Flask route `/about` that should return the text "This is the about page.". Which of the following options would cause this test to fail?
The route `/about` is missing in `app.py`.

The route `/about` exists but returns "About us page" instead.

The route `/about` returns `<p>this is the about page.</p>` instead of plain text.
Which of the following assertion test case throws the exception?```python
def max_value(nums):
if not nums:
return None
return max(nums)
def test_max_value():
##Assertions to test max_value function##
```
Given the following pytest test structure:
```python
@pytest.fixture
def sample_data():
return {"name": "John", "age": 30}
def test_name(sample_data):
assert sample_data["name"] == "John"
def test_age(sample_data):
assert sample_data["age"] == 30
```
When running `pytest -v`, how many times will the sample_data fixture be executed?
Consider test file with markers:
```python
@pytest.mark.slow
def test_database():
pass
@pytest.mark.unit
def test_calculation():
pass
@pytest.mark.slow
@pytest.mark.unit
def test_complex():
pass
```
Running `pytest -m "unit and not slow"` will execute which tests?
Consider the following Python code
File name: main_test.py
```python
import pytest
class TestGroup:
def do_something(self, x, y):
return x % y
def test_one(self):
assert self.do_something(10, 5) == 0, " Is 5 factor of 10? "
def test_two(self):
assert self.do_something(32, 5) == 0, " Is 5 factor of 32 "
```
What will be the output of running the above python script using command line "pytest -v main_test.py"?
``` ==================== short test summary info ==================== FAILED test6.py::TestGroup::test_two - AssertionError: Is 5 factor of 32 ========== 1 failed, 1 passed in 0.12s ========================== ```

```text ==================== short test summary info ==================== test6.py::TestGroup::test_one PASSED [ 50%] test6.py::TestGroup::test_two PASSED [100%] ==================== 2 passed in 0.02s==================== ```

```text ==================== short test summary info ==================== test6.py::TestGroup::test_one FAILED [ 50%] test6.py::TestGroup::test_two FAILED [100%] ==================== 2 failed in 0.02s==================== ```

``` ==================== short test summary info ==================== FAILED test6.py::TestGroup::test_two - AssertionError: Is 5 factor of 10 FAILED test6.py::TestGroup::test_two - AssertionError: Is 5 factor of 32 ==================== 2 failed in 0.12s ==================== ```

Consider the table and match each type of software testing with its correct focus area. | Test Type | Focus Area | |---|---| | 1. Unit Testing | a. Simulated end-user browser-based interaction | | 2. Integration Testing | b. Whole app in full environment including server | | 3. System Testing | c. Real-world verification by actual users before release | | 4. System Testing Automation | d. Multiple components/modules working together | | 5. User Acceptance Testing | e. Smallest logical units (functions/methods) |

Which of these are true about unit tests in Flask using pytest?

Tests must start with test_ prefix

You must import `FlaskClient` from `flask.testing`

You cannot test routes using `client.get()`

Fixtures help simulate isolated environments

Examine the following Python test file:
Filename: math_tests.py
```python
import pytest
def multiply(a, b):
return a * b
def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b
@pytest.mark.unit
def test_multiply_positive():
assert multiply(3, 4) == 12
@pytest.mark.integration
def test_divide_normal():
assert divide(10, 2) == 5.0
@pytest.mark.slow
@pytest.mark.integration
def test_complex_calculation():
result = divide(multiply(6, 7), 2)
assert result == 21.0
@pytest.mark.unit
def test_multiply_negative():
assert multiply(-2, 3) == -6
```
Consider the following pytest command output:
========= 1 passed, 3 deselected in 0.02s =========
Which of the following pytest commands would produce the output shown above?
``` pytest math_tests.py -m unit ```

``` pytest math_tests.py -m integration ```

``` pytest math_tests.py -m "not sLow" ```

``` pytest math_tests.py -m "slow and integration" ```

None of these

What will be the output of the following HTML code?
```html
<!DOCTYPE html>
<html>
<head>
<title>Test List</title>
</head>
<body>
<dl>
<dt>Flask</dt>
<dd>A Python web framework.</dd>
<dt>SQLAlchemy</dt>
<dd>A database toolkit for Python.</dd>
</dl>
</body>
</html>
```
Flask
A Python web framework.
SQLAlchemy
A database toolkit for Python.
Flask A Python web framework. SQLAlchemy A database toolkit for Python.

Flask - A Python web framework. SQLAlchemy - A database toolkit for Python.

Flask A Python web framework. SQLAlchemy A database toolkit for Python.

What will be the output of the following Jinja2 template when rendered in Flask?
```html
{% macro greet(name) %}
Hello, {{ name }}!
{% endmacro %}
<!DOCTYPE html>
<html>
<head>
<title>Jinja2 Macro Test</title>
</head>
<body>
{{ greet("Alice") }}
{{ greet("Bob") }}
</body>
</html>
```
Hello, Alice! Hello, Bob!

``` jinja2.exceptions.UndefinedError: 'greet' is undefined ```

Hello, Alice! Hello, Bob!

```
{{ greet("Alice") }}
{{ greet("Bob") }}
```
Consider the following flask app. Given that **test_request_context()** allows text
to be printed on the terminal, which of the following statements is correct?
```python
from flask import Flask, url_for
app = Flask(__name__)
@app.route('/hello')
def hello():
return 'Hello World!'
@app.route('/user/<username>')
def user(username):
return f'Welcome {username}!'
with app.test_request_context():
#== print statement ==#
```
If `print statement` is replaced by `print(url_for('user', username='John'))`, the output on the terminal will be `/user?username=John`
If `print statement` is replaced by `print(url_for('user', username='John', id='101'))`, the output on the terminal will be
`/user/John/101`
If `print statement` is replaced by `print(url_for('hello', username='John'))`, the output on the terminal will be Hello World!
If `#== print statement ==#` is replaced by `print(url_for('hello', username='John'))`,
the output on the terminal will be `/hello?username=John`.
Consider the code below in a file called test_students.py.
test_students.py
```python
import pytest
@pytest.fixture
def students():
return {"names": ["ravi", "raj"], "ages": [12, 9]}
@pytest.mark.check
def test_name(students):
assert "ravi" in students['names']
@pytest.mark.check
def test_age(students):
assert students['ages'][0] > 9
def test_check(students):
assert "raj" not in students['names']
```
What will be the output on the terminal on running the command "pytest -m check"? (assume that the tests ran in 0.03s and that the markers have been registered)
``` ======== 2 passed, 1 deselected in 0.03s ======== ```

``` ======== 2 passed in 0.03s======== ```

```text ======== 1 passed, 1 failed in 0.03s ======== ```

``` ========2 passed, 1 failed in 0.03s======== ```

You are given a project with three files: `conftest.py`, `test_multiples_of_3_and_6.py`, and `test_multiples_of_13.py`. The purpose of the tests is to verify if numbers generated by each function are divisible by 39. However, there is a setup issue in this project.
* `conftest.py` contains a fixture that provides test data.
* `test_multiples_of_3_and_6.py` has two functions: one checks divisibility by 3, and the other by 6.
* `test_multiples_of_13.py` contains a function to check divisibility by 13.
Here is the content of each file:
`conftest.py`
```python
import pytest
@pytest.fixture
def divisible_by_39():
return 39 # Fixture providing the number to be tested
```
`test_multiples_of_3_and_6.py`
```python
import pytest
def test_divisible_by_3(divisible_by_39):
assert divisible_by_39 % 3 == 0 # Checks if divisible by 3
def test_divisible_by_6(divisible_by_39):
assert divisible_by_39 % 6 == 0 # Checks if divisible by 6
```
`test_multiples_of_13.py`
```python
import pytest
def test_divisible_by_13(divisible_by_39):
assert divisible_by_39 % 13 == 0 # Checks if divisible by 13
```
When you run `pytest -k divisible`, which of the following is **true**?
``` ========== 1 passed in 0.02s ========== ```

``` ========== 3 passed in 0.02s ========== ```

``` ========== 1 failed, 2 passed in 0.06s ========== ```

``` ========== 3 errors in 0.02s ========== ```


The marks of any student object, <student> can be retrieved using the command "<student>.tests".

We cannot insert a new record into the "**test_marks**" table for a non-existent student object.

If a test marks record is deleted from the “**test_marks**” table, the related student record is also deleted from the “**student**” table.

We can insert a new record in the “**student**” table for a non-existent “**test_marks**” object.


```python >>>t1=TestMarks(id=1, test_name="quiz_1",marks=65, student_id=101) >>>db.add(t1) >>>db.commit() >>>s1=Student(id=101, 'RAM') >>>db.add(s1) >>>db.commit() ```

```python >>>s1=Student(id=101,name='RAM') >>>db.add(s1) >>>db.commit() >>>t1=TestMarks(id=1,test_name="quiz_1",marks=65,student_id=101) >>>db.add(t1) >>>db.commit() ```

```python >>>t1=TestMarks(id=1,test_name="quiz_1",marks=65,student_id=101) >>>s1=Student(id=101,name='RAM') >>>db.add(t1) >>>db.commit() >>>db.add(s1) >>>db.commit() ```

```python >>>t1=TestMarks(id=1,test_name="quiz_1",marks=65,student_id=101) >>>s1=Student(id=101,'RAM') >>>db.add(t1) >>>db.add(s1) >>>db.commit() ```

Consider the code below in a file called test_students.py
```python
test_students.py
import pytest
@pytest.fixture
def students():
return { "names": ["ravi", "raj"], "ages": [12, 9]}
def test_name(students):
assert "ravi" in students['names']
def test_age(students):
assert students['ages'][0] > 9
```
Which of these is the correct output when the command "pytest -k name" is run in the terminal?
``` ===== 1 passed, 1 deselected in 0.02s ===== ```

``` ======== 1 passed, 2 deselected in 0.02s ======== ```

```text ======== 1 failed, 1 deselected in 0.02s ======== ```

``` ======== 1 failed, 2 deselected in 0.02s ======== ```

Consider the following function to be tested and test functions given in the Python code snippet below.
file.py
```python
def sample_function(x):
var = []
for i in range(x):
var.append((i)**3)
return var
def test_func1():
assert 125 in sample_function(6)
def test_func2():
assert 64 in sample_function(8)
def sample_test3():
assert 125 in sample_function(5)
```
What will be the summary of the output for the command
`pytest file.py` on the terminal?
``` =========== 1 failed, 2 passed in 0.06s =========== ```

``` ========== 2 failed, 1 passed in 0.06s ========== ```

``` ============================= 3 passed in 0.06s ============================= ```

``` ============================= 2 passed in 0.06s ============================= ```

Refer to the project with three files: `conftest1.py`, `test_multiples_of_3_and_6.py`, and `test_multiples_of_13.py`.
The purpose of the tests is to verify if numbers generated by each function are divisible by 39. However, there is a setup issue in this project.
* `conftest1.py` contains a fixture that provides test data.
* `test_multiples_of_3_and_6.py` has two functions: one checks divisibility by 3, and the other by 6.
* `test_multiples_of_13.py` contains a function to check divisibility by 13.
Here is the content of each file:
**conftest1.py**
```python
import pytest
@pytest.fixture
def divisible_by_39():
return 39 # Fixture providing the number to be tested
```
**test_multiples_of_3_and_6.py**
```python
import pytest
def test_divisible_by_3(divisible_by_39):
assert divisible_by_39 % 3 == 0 # Checks if divisible by 3
def test_divisible_by_6(divisible_by_39):
assert divisible_by_39 % 6 == 0 # Checks if divisible by 6
```
**test_multiples_of_13.py**
```python
import pytest
def test_divisible_by_13(divisible_by_39):
assert divisible_by_39 % 13 == 0 # Checks if divisible by 13
```
When you run `pytest -k divisible`, which of the following is **true**?
``` ========== 1 passed in 0.02s ========== ```

``` ========== 3 passed in 0.02s ========== ```

``` ========= 1 failed, 2 passed in 0.06s ========= ```

``` ========== 3 errors in 0.02s ========== ```

Consider the following flask app. Given that `test_request_context()` allows text to be printed on the terminal, which of the following statements is/are correct?
```python
from flask import Flask, url_for
app = Flask(__name__)
@app.route('/products')
def products():
return 'Product List'
@app.route('/product/<int:product_id>/<string:name>')
def product_detail(product_id, name):
return f'Product ID: {product_id}, Name: {name}'
with app.test_request_context():
#== print statement ==#
```
If `print statement` is replaced by:
```python
print(url_for('products', category="electronics"))
```
the output on the terminal will be;
`/products?category=electronics`
If #== *print statement* ==# is replaced by:
```python
print(url_for('products', category="electronics")),
```
the output on the terminal will be;
/products/electronics
If #== print statement ==# is replaced by:
```python
print(url_for('product_detail', product_id=101, name="Gadget", discount=20))
```
the output on the terminal will be;
/product/101/Gadget?discount=20
If #== print statement ==# is replaced by:
```python
print(url_for('product_detail', product_id=101, name="Gadget", discount=20))
```
the output on the terminal will be;
/product/101/Gadget/20
Consider the following Python code snippet. File name: main.py
```python
import sys
def func1(x):
return x > 0
def func2(x):
return x % 2 == 0
def test_fun3(x):
assert func1(x) == True, str(x) + " is not even/odd"
assert func2(x) == True, str(x) + " is even number"
assert x % 2 != 0, str(x) + " is odd number"
x = int(sys.argv[1])
test_fun3(x)
```
Which of the following is the correct combinations of “command line argument” and “assertion error”?
Command: python main.py 9 AssertionError: 9 is even number

Command: python main.py 90 AssertionError: 90 is odd number

``` Command: python main.py 0 AssertionError: 0 is not even/odd ```

Command: python main.py 9 AssertionError: 9 is odd number

Command: python main.py 90 AssertionError: 90 is even number

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 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. ```

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 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 a function remainder, and a set of test cases given below.
Filename: test_file.py
```python
def remainder(numerator, denominator):
rem = numerator % denominator
return rem
def test_func0():
assert remainder(5,7) == 5
def test_function1():
assert remainder(20,4) == 0
def test_func2():
assert remainder(31,8) == 6
def test_function3():
assert remainder(19,3) == 1
```
What will be the output on the terminal for the command `pytest test_file.py -k func`?
```text ========= 1 failed, 1 passed, 2 deselected in 0.41s ========= ```

``` =========== 3 passed, 1 deselected in 0.41s ============ ```

``` ============================= 1 failed, 3 passed in 0.41s ============================= ```

```text ========== 2 failed, 2 deselected in 0.41s ========== ```

Consider the following Python code snippet.
Filename: code.py
```python
import logging
import sys
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
logging.warning('This is only for testing.')
if sys.argv[1] == 'info':
logging.info('This code is working as expected.')
if sys.argv[1] == 'debug':
logging.debug('This code may have issues, debugging...')
logging.warning('code execution complete!')
```
What will be output on the terminal is the above code snippet is run on the terminal using command: `python code.py debug`
``` WARNING:This is only for testing. INFO: This code is working as expected WARNING:code execution complete! ```

``` WARNING:This is only for testing. DEBUG: This code may have issues, debugging... WARNING:code execution complete! ```

``` WARNING:This is only for testing. WARNING:code execution complete! ```

``` INFO: This code is working as expected DEBUG: This code may have issues, debugging... ```

Match the following types of testing with their functionality. | | | |---|---| | A. Regression testing | 1. Beta Testing | | B. User Acceptance testing | 2. Considers internal functioning of the system | | C. White Box 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?

A → 1, B → 2, C → 3, D → 4

A -> 4, B -> 3, C -> 2, D -> 1

A → 4, B → 1, C → 2, D → 3

A → 3, B → 2, C → 1, D → 4

Match the following types of testing with their functionality. | | | |---|---| | A. White Box Testing | 1. Beta Testing | | B. User Acceptance testing | 2. One step beyond integration Testing | | C. System testing | 3. Simulates actual user interaction, allows to script browser | | D. System testing Automation | 4. Considers internal functioning of the system | Which of the following is the correct matching?

A → 1, B → 2, C → 3, D → 4

A → 4, B → 3, C → 2, D → 1

A -> 4, B -> 1, C -> 2, D -> 3

A → 3, B → 2, C → 1, D → 4

Software packages A and B of complexity O(nlogn) and O(n^2), respectively, spend exactly T_A(n) = C_A nlog_10(n) and T_B(n) = C_B n^2 milliseconds to process n data items. During a test, the average time of processing n = 10^7 data items with the package A and B is 420 milliseconds and 350 milliseconds, respectively. The time taken (in milliseconds) by software package A and B to process 10^8 data items, respectively will be?

Consider the following api resources created using flask_restful. Assume that the app is connected to the database and is running on one terminal. Select the correct option(s).
```python
class TestApi(Resource):
def get(self, admin):
# retrieves admin data from database and returns it.
return {
"name": "mad1_admin",
"role": "admin",
}
def post(self):
# fetches user data from request body and stores in the
# database.
return {
"message": "user added successfully"
}, 201
api.add_resource(TestApi, "/api/<string:admin>", "/<admin>",
"/user_data", "/")
app.run()
```
The base URL for the app is mapped with GET HTTP method.

If we run the command: `curl http://127.0.0.1:5000/api/user -X GET` on a new terminal; it will return;
```json
{
"name": "mad1_admin",
"role": "admin"
}
```
The endpoint, `/admin` is mapped with GET HTTP method.

If we run the command: `curl http://127.0.0.1:5000/user-data -X POST`
on a new terminal; it will return;
```json
{
"message": "user added successfully"
}
```
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(13) == 144
@pytest.mark.marker2
def testcase_2():
assert square(6) == 6
@pytest.mark.marker3
def testcase_3():
assert square(3) == 9
```
On running this file on the terminal using pytest, the summary of the output is;
============================= 1 passed, 2 deselected, 3 warnings in 0.02s =============================
What command will result into the outcome given above?
``` pytest test_file.py -k marker1 ```

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

``` pytest test_file.py -m marker3 ```

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

Consider the following function to be tested and test functions given in the Python code snippet below.
test_file.py
```python
powers = []
for i in range(1,5):
def powers_of_x(x):
return x**i
powers.append(powers_of_x)
powers_of_3 = [x(3) for x in powers]
def testcase_1():
assert 9 in powers_of_3
def testcase_2():
assert 27 in powers_of_3
def testcase_3():
assert 64 in powers_of_3
```
For the command `pytest test_file.py`, what will be the output on the terminal?
``` ============================= 1 failed, 2 passed in 0.02s ============================= ```


``` ======================================== 3 failed in 0.02s ======================================== ```

``` ============================= 2 failed, 1 passed in 0.02s ============================= ```
Consider the following two code snippets. Which of the following is/are correct options if the above snippets are run as view functions of a flask application ?Snippet 1
```python
@app.route("/base")
@app.route("/home")
def homepage():
return "Welcome to MAD I!"
```
Snippet 2
```python
@app.route("/mad1")
def homepage():
return "Welcome to MAD I!"
@app.route("/mad2")
def homepage():
return "Welcome to MAD II!"
```
Consider the following function to be tested and test functions given in the Python code snippet below.
```python
# test_file.py
powers = []
for i in range(1,5):
def powers_of_x(x):
return x**i
powers.append(powers_of_x)
powers_of_4 = [x(4) for x in powers]
def testcase_1():
assert 12 in powers_of_4
def testcase_2():
assert 64 in powers_of_4
def testcase_3():
assert 256 in powers_of_4
```
For the command `pytest test_file.py`, what will be the output on the terminal?
``` ======== 1 failed, 2 passed in 0.02s ======== ```

======================================== 3 passed in 0.02s ========================================

========== 3 Failed in 0.02s ==========

``` ========================= 2 failed, 1 passed in 0.02s ========================= ```
Consider the following HTML Document. How will the browser render the HTML document given above?```html
<!DOCTYPE html>
<html>
<head>
<title>Test Document</title>
<style>
h4, span {
display: inline-block;
width: 200px;
}
</style>
</head>
<body>
<h4>Statement 1 from Document.</h4>
<h4>Statement 2 from Document.</h4>
<span>Statement 3 from Document.</span>
<span>Statement 4 from Document.</span>
</body>
</html>
```
Statement 1 from Document. Statement 2 from Document. Statement 3 from Document. Statement 4 from Document.

Statement 1 from Document. Statement 2 from Document. **Statement 3 from Document.** **Statement 4 from Document.**

Statement 1 from Document. Statement 2 from Document. Statement 3 from Document. Statement 4 from Document.

Statement 1 from Document. Statement 2 from Document. Statement 3 from Document. Statement 4 from Document.
Consider the code below and match the conditions in Column A with respect to the coverage types in Column B. ```c
int foo(int x, int y)
{
int z = 0;
if((x > 0) && (y > 0))
{
z = x;
}
return z;
}
```
| Column A | Column B |
|---|---|
| 1. Test invokes foo() at least once | a. Condition coverage |
| 2. foo(1,1) | b. Branch coverage |
| 3. foo(1,1) and foo(1,0) | c. Function coverage |
| 4. foo(0,1) and foo(1,0) | d. Statement coverage |
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 | | 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 a function func, and a set of test cases given below.
Filename: test_file.py
```python
import pytest
def func(x,y):
out = x+y**2
return out
class Test_class0():
def test_case1(self):
assert func(1,2) == 5
def case_test2(self):
assert func(2,3) == 10
def test_case3(self):
assert func(6,2) == 8
class Test_class1():
def test_case1(self):
assert func(5,2) == 9
def case_test2(self):
assert func(4,3) == 14
```
What will be the output on the terminal for the command below?
`pytest test_file.py -k Test_class0`
``` == 2 failed, 1 passed in 0.17s === ```

```text == 1 failed, 1 passed, 1 deselected in 0.17s === ```

``` == 2 failed, 1 deselected in 0.17s === ```

``` == 1 failed, 2 passed in 0.17s ==== ```
Match the following types of testing with their functionality. Which of the following is the correct matching?| A. Regression testing | 1. Beta Testing | |---|---| | B. User Acceptance testing | 2. One step beyond integration Testing | | 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. |

Consider the following flask application and select the correct option if the application is running locally on http://127.0.0.1:5000.
```python
from flask import Flask
app = Flask(__name__)
@app.route('/work')
@app.route('/home')
def my_task():
return "<h1>Hello! Reporting for my task</h1>"
app.run()
```
The application will return 200 OK status code for /home endpoint only

The application will return 200 OK status code for /work endpoint only

The application will return 200 OK status code for both the endpoints

The application will throw an AssertionError for both the endpoints

Which of the following statements about OpenAPI Specification (OAS) is true?
Consider the following code snippet. Which of the following is correct regarding the coverage of the test?```python
def foo(x,y):
if x < 0:
y += 1
if y > 0:
x -= 1
return x + y
```
Test:
```
foo(-1, 1)
foo(1, -1)
```
Match the following types of testing with their functionality. | | | |---|---| | A. Black box testing | 1. Focuses primarily on input and output of the software application. | | B. Unit testing | 2. Tests individual pieces of source code. | | C. Grey box testing | 3. Analyzes the internal structures, the data structures, internal design, code structure, and the working of the software. | | D. White box testing | 4. Testing the functionality of the software. In the event of errors, they can access the software code. | Which of the following is correct matching?

Software packages A and B of complexity O(n²logn) and O(n³), respectively, spend exactly T_A(n) = C_A n²log₁₀(n) and T_B(n) = C_B n³ milliseconds to process n data items. During a test, the average time of processing n = 10⁵ data items with the package A and B is 600 milliseconds and 300 milliseconds, respectively. Which of two software packages defined above will work better to process 10⁶ data items?
If the given python program is executed using pytest, then identify the status of the test code. File name: test1.py
```python
def dec(x):
return x-1
def test_answer():
assert dec(3) == 2
```
If the given python program is executed using pytest, then identify the status of the test code. File name: test1.py ```python
def dec(x):
return x-1
def test_answer():
assert dec(3) == 3
```
How will the browser render the output of the following Python code snippet? ```python
from jinja2 import Template
styles=[
'.text{color: purple}\n #heading{color:red}\n #subhead{color:blue}',
'.text{color: purple}\n #subhead{color:green}\n #main{color:blue}',
'.text{color: purple}\n #main{color:red}\n #heading{color:blue}'
]
template = """
<!DOCTYPE html>
<style>
div{border: 2px solid black;
width: 300px;
background-color: rgb(247, 247, 230)}
{{styles[0]}}
</style>
<body>
<div>
<h2 style="color:brown;" class="text" id="heading">
Programming Degree</h2>
<h3 class="text" id="subhead">Modern Application 1</h3>
<p class="text" id="main">This is a course on Application
Development</p>
</div>
</body>
"""
test_render = Template(template)
output = test_render.render(styles = styles)
print(output)
```
Programming Degree Modern Application 1 This is a course on Application Development

Programming Degree Modern Application 1 This is a course on Application Development

Programming Degree Modern Application 1 This is a course on Application Development

Programming Degree Modern Application 1 This is a course on Application Development

What will be the output of the following python code if method
test_request_context() allows flask app to print statements on the terminal?
```python
from flask import Flask, url_for
app = Flask(__name__)
@app.route('/')
def home():
return 'base url'
@app.route('/subscribe')
def subscribe():
return 'Please subscribe to this page.'
@app.route('/new_course/<coursename>')
def course(coursename):
return f'The course {coursename} gives basics of web development.'
with app.test_request_context():
print(url_for('home'))
print(url_for('subscribe'))
print(url_for('subscribe', username = 'user_one'))
print(url_for('course', coursename = 'MAD_I'))
```
``` base url Please subscribe to this page Please subscribe to this page user one. The course MAD_I gives basics of web development. ```

``` / /subscribe /subscribe/user_one /new_course/MAD_I ```

``` / /subscribe /subscribe?username=user_one /new_course/MAD_I ```

``` / /subscribe /subscribe?username=user_one /new_course?coursename=MAD_I ```