Examen final : Compléments d’informatique

ENSAI 2A UE3

Published

September 29, 2025

Instructions

  • Written exam
  • Duration: 2 hours
  • One A4 sheet of handwritten notes (front and back) allowed
  • No calculator
ImportantRead Before Starting
  • You can answer the exercises in any order.
  • Within each exercise, the questions are not necessarily ordered by increasing difficulty.
  • Unless otherwise stated, the questions expect short answers.
  • Strictly follow the instructions. If a question seems unclear, state your assumptions on your answer sheet.
  • When code is required, follow the basic language conventions (keywords, indentation, etc.). Syntax errors due to handwriting will be tolerated. If you do not remember the exact name of a Python method, you may use pseudocode.
  • Unless explicitly requested, code documentation is not required.

1 Course Questions (7 points)

NoteInstructions

Give short answers to the following questions.

  1. List the main tools and software used during the practical sessions.
  2. Why should we write quality code?
  3. What are the benefits of dividing an application into layers?
  4. How would you define the relationships between the following classes?
  • Bicycle
  • TwoWheeledVehicle
  • Scooter
  • ElectricBicycle
  1. What is a design pattern?
  2. What principles should a good unit test follow?
  3. What is the purpose of a mock?
  4. Identify the errors and bad practices in the following code. What consequences could they have?


from dao.db_connection import DBConnection
from business_object.player import Player

class PlayerDao(metaclass=Singleton):
    def connect(self, pseudo, pwd) -> Player:
        with DBConnection().connection as connection:
            with connection.cursor() as cursor:
                query = " SELECT *                           "
                query += "  FROM player                     "
                query += " WHERE pseudo = '" + pseudo + "'   "
                query += "   AND pwd = '" + pwd + "';        "

                cursor.execute(query)
                res = cursor.fetchall()

                return res

2 Webservices (3 points)

NoteInstructions

Give short answers to the following questions.

  1. Name the different elements of the following request:

GET https://my-awesome-ws.fr/attack/8

  1. In your opinion, what could the following request do?

PUT https://my-awesome-ws.fr/pokemon/15

  1. What needs to be added for this request to work?
  2. Which HTTP methods correspond to the CRUD operations?

3 Code (6 points)

NoteInstructions

Respect the principles of layered programming throughout this exercise.

Create a Person class with the following attributes:

  • last name
  • first name
  • city
  • age
  • is_adult
  1. Create the class and its constructor. Each new person has an age of 0 and is not an adult.
  2. Add a birthday() method that increments the person’s age. When the person reaches 18 years old, they become an adult.

Write the documentation for this method.

  1. Using pytest, write the unit tests for the birthday() method.
  2. Assuming there is a database table person containing the same information as the Person class, write the SQL query that displays the number of people grouped by city.
  3. The PersonDao class provides a list_all() method returning all people.

Write a service method that returns only the adults.

  1. Bonus: Modify the service method so that it accepts an optional parameter cities (a list of cities).
  • If the parameter is provided, return only adults whose city belongs to this list.
  • Otherwise, return all adults.

4 Git and Version Control (4 points)

Your project manager asks you to update the file src/main.py in the Git repository:

https://github.com/soleil59/sustainable-cultures.git

The update consists of connecting to a database to retrieve the contents of a table named chicory.

You have never worked on this repository before, but you have the required permissions and a valid access token.

  1. How do you retrieve the repository onto your local machine?

You then modify the src/main.py file.

Following good development and security practices, you do not hardcode the database credentials. Instead, you store them in a new .env file.

  1. How do you send your modifications to the remote repository?

You followed the procedure correctly but encounter a merge conflict.

  1. After which Git command can such a conflict occur? Briefly explain.
  2. What could have caused this conflict?
  3. How do you resolve it?