Booth Module#

The Booth module is responsible for various functionalities. This section documents the components of the Booth module, including models, views, and more.

views.py#

class booth.views.BoothView[source]#

Bases: TemplateView

View for rendering the booth template with voting information.

This view retrieves voting information based on the provided ‘voting_id’ parameter and renders the ‘booth/booth.html’ template with the voting details.

Variables:

template_name (str) – The name of the HTML template to be rendered.

get_context_data(**kwargs)[source]#

Get the context data for rendering the template.

Retrieves voting information based on the ‘voting_id’ parameter and prepares the context data to be used in the template.

Parameters:

kwargs (dict) – Keyword arguments passed to the view.

Returns:

A dictionary containing the context data.

Return type:

dict

Raises:

Http404 – If there is an issue retrieving voting information.

template_name = 'booth/booth.html'#

test_selenium.py#

class booth.test_selenium.CommentBoothTestCase[source]#

Bases: StaticLiveServerTestCase

Selenium-based test case for the Comment Booth in the voting app.

This test case covers the behavior of the Comment Booth, including the setup, user creation, and interaction with the web interface.

Variables:
  • base (BaseTestCase) – An instance of BaseTestCase for common test setup and teardown.

  • v (Voting) – The Voting instance created for testing.

  • driver (webdriver.Chrome) – The Selenium WebDriver instance for browser automation.

create_voting()[source]#

Create a test voting with a text-type question.

Returns:

The created Voting instance.

Return type:

Voting

get_or_create_user(pk)[source]#

Get or create a test user.

Parameters:

pk (int) – The primary key for the user.

Returns:

The User instance.

Return type:

User

setUp()[source]#

Set up the test environment before each test method is run.

This method is called before each test method in the test case.

Returns:

None

tearDown()[source]#

Clean up the test environment after each test method is run.

This method is called after each test method in the test case.

Returns:

None

test_commentquestion()[source]#

Test the behavior of submitting a comment in a text-type question booth.

This test navigates to the booth for a specific voting, logs in as a user, submits a comment, and verifies the success alert indicating that the vote has been sent.

Returns:

None

class booth.test_selenium.MultipleChoiceQuestionBoothTest[source]#

Bases: StaticLiveServerTestCase

Selenium-based test case for the Multiple Choice Question booth in the voting app.

This test case covers the behavior of the Multiple Choice Question booth, including the setup, user creation, and the interaction with the web interface.

Variables:
  • base (BaseTestCase) – An instance of BaseTestCase for common test setup and teardown.

  • v (Voting) – The Voting instance created for testing.

  • driver (webdriver.Chrome) – The Selenium WebDriver instance for browser automation.

create_voting()[source]#

Create a test voting with a multiple-choice question and options.

Returns:

The created Voting instance.

Return type:

Voting

get_or_create_user(pk)[source]#

Get or create a test user.

Parameters:

pk (int) – The primary key for the user.

Returns:

The User instance.

Return type:

User

setUp()[source]#

Set up the test environment before each test method is run.

This method is called before each test method in the test case.

Returns:

None

tearDown()[source]#

Clean up the test environment after each test method is run.

This method is called after each test method in the test case.

Returns:

None

test_testquestionmultipleoptions()[source]#

Test the behavior of selecting multiple options in a multiple-choice question booth.

This test navigates to the booth for a specific voting, logs in as a user, selects multiple options, submits the form, and then verifies that the correct number of options is selected and that the form count is as expected.

Returns:

None

class booth.test_selenium.PreferenceBoothTest[source]#

Bases: StaticLiveServerTestCase

Selenium-based test case for the Preference Question booth in the voting app.

This test case covers the behavior of the Preference Question booth, including the setup, user creation, and interaction with the web interface.

Variables:
  • base (BaseTestCase) – An instance of BaseTestCase for common test setup and teardown.

  • v (Voting) – The Voting instance created for testing.

  • driver (webdriver.Chrome) – The Selenium WebDriver instance for browser automation.

create_voting()[source]#

Create a test voting with a Preference type question.

Returns:

The created Voting instance.

Return type:

Voting

get_or_create_user(pk)[source]#

Get or create a test user.

Parameters:

pk (int) – The primary key for the user.

Returns:

The User instance.

Return type:

User

login_user(username, password)[source]#

Log in a user with the provided username and password.

Parameters:
  • username (str) – The username of the user.

  • password (str) – The password of the user.

Returns:

None

perform_preference(preferences, expected_values)[source]#

Perform a preference vote with the given preferences and verify the results.

Parameters:
  • preferences (list) – List of preferences to be voted.

  • expected_values (dict) – Dictionary containing expected values for each preference.

Returns:

None

select_preferences(preferences)[source]#

Select preferences based on the provided list.

Parameters:

preferences (list) – List of preferences to be selected.

Returns:

None

setUp()[source]#

Set up the test environment before each test method is run.

This method is called before each test method in the test case.

Returns:

None

tearDown()[source]#

Clean up the test environment after each test method is run.

This method is called after each test method in the test case.

Returns:

None

test_preference_booth_no_fullfile_all_preferences()[source]#

Test the preference voting with some preferences not fully filled.

Returns:

None

test_preference_booth_same_preference()[source]#

Test the preference voting with the same preference for multiple options.

Returns:

None

test_question_preference()[source]#

Test the preference voting with a list of preferences.

Returns:

None

class booth.test_selenium.YesNoBoothTestCase[source]#

Bases: StaticLiveServerTestCase

Selenium-based test case for the Yes/No Question booth in the voting app.

This test case covers the behavior of the Yes/No Question booth, including the setup, user creation, and interaction with the web interface.

Variables:
  • base (BaseTestCase) – An instance of BaseTestCase for common test setup and teardown.

  • v (Voting) – The Voting instance created for testing.

  • driver (webdriver.Chrome) – The Selenium WebDriver instance for browser automation.

create_voting()[source]#

Create a test voting with a Yes/No type question.

Returns:

The created Voting instance.

Return type:

Voting

get_or_create_user(pk)[source]#

Get or create a test user.

Parameters:

pk (int) – The primary key for the user.

Returns:

The User instance.

Return type:

User

setUp()[source]#

Set up the test environment before each test method is run.

This method is called before each test method in the test case.

Returns:

None

tearDown()[source]#

Clean up the test environment after each test method is run.

This method is called after each test method in the test case.

Returns:

None

test_testquestionyesno()[source]#

Test the behavior of submitting a Yes/No response in a Yes/No type question booth.

This test navigates to the booth for a specific voting, logs in as a user, submits a Yes response, and verifies the success alert indicating that the vote has been sent.

Returns:

None

tests.py#

class booth.tests.BoothTestCase[source]#

Bases: BaseTestCase

Test case for the BoothView in the booth app.

This test case includes methods to test the behavior of the BoothView under different scenarios.

Variables:

client (Client) – The Django test client used to simulate HTTP requests.

setUp()[source]#

Set up the test environment before each test method is run.

This method is called before each test method in the test case.

Returns:

None

tearDown()[source]#

Clean up the test environment after each test method is run.

This method is called after each test method in the test case.

Returns:

None

testBoothNotFound()[source]#

Test the behavior when trying to access a non-existing booth.

The view should return a 404 status code when attempting to access a booth with a voting ID that does not exist.

Returns:

None

testBoothRedirection()[source]#

Test the behavior when accessing a booth without a trailing slash.

The view should return a 301 (permanent redirect) status code when accessing a booth with a voting ID without a trailing slash.

Returns:

None