Voting Module#
The Voting module contains several components including models, views, forms, and more. Below is the documentation for each of these components.
admin.py#
- class voting.admin.QuestionAdmin[source]#
Bases:
ModelAdmin
Admin interface for managing Question objects.
- list_display#
Fields to be displayed in the list view.
- list_display = ('desc', 'type')#
- property media#
- class voting.admin.QuestionOptionRankedAdmin[source]#
Bases:
ModelAdmin
Admin interface for managing ranked QuestionOption objects.
- list_display#
Fields to be displayed in the list view.
- list_display = ('question', 'number', 'option')#
- property media#
- class voting.admin.QuestionOptionYesNoAdmin[source]#
Bases:
ModelAdmin
Admin interface for managing yes/no QuestionOption objects.
- list_display#
Fields to be displayed in the list view.
- list_display = ('question', 'number', 'option')#
- property media#
- class voting.admin.VotingAdmin[source]#
Bases:
ModelAdmin
Admin interface for managing Voting objects.
- list_display#
Fields to be displayed in the list view.
- readonly_fields#
Fields that are read-only in the admin interface.
- date_hierarchy#
Field used to organize the date hierarchy.
- list_filter#
Filters to apply in the list view.
- search_fields#
Fields to search in the list view.
- actions#
Custom actions available for this model.
- actions = [<function start>, <function stop>, <function tally>]#
- date_hierarchy = 'start_date'#
- list_display = ('name', 'start_date', 'end_date', 'future_stop')#
- list_filter = (<class 'voting.filters.StartedFilter'>,)#
- property media#
- readonly_fields = ('start_date', 'end_date', 'pub_key', 'tally', 'postproc')#
- search_fields = ('name',)#
- voting.admin.start(modeladmin, request, queryset)[source]#
Admin action to start the voting process for selected items.
This action sets the start date of each selected voting to the current time.
- Parameters:
modeladmin (ModelAdmin) – The current ModelAdmin instance.
request (HttpRequest) – The HTTP request triggering this action.
queryset (QuerySet) – The queryset of selected items.
- voting.admin.stop(ModelAdmin, request, queryset)[source]#
Admin action to stop the voting process for selected items.
This action sets the end date of each selected voting to the current time.
- Parameters:
ModelAdmin (ModelAdmin) – The current ModelAdmin instance.
request (HttpRequest) – The HTTP request triggering this action.
queryset (QuerySet) – The queryset of selected items.
- voting.admin.tally(ModelAdmin, request, queryset)[source]#
Admin action to tally votes for selected items.
This action triggers vote tallying for each selected voting that has ended.
- Parameters:
ModelAdmin (ModelAdmin) – The current ModelAdmin instance.
request (HttpRequest) – The HTTP request triggering this action.
queryset (QuerySet) – The queryset of selected items.
models.py#
- class voting.models.Question[source]#
Bases:
Model
Represents a question in a voting system.
- desc#
The description of the question.
- Type:
TextField
- TYPES#
The list of possible types for a question.
- Type:
list
- type#
The type of the question, chosen from TYPES.
- Type:
CharField
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- TYPES = [('C', 'Classic question'), ('Y', 'Yes/No question'), ('M', 'Multiple choice question'), ('T', 'Text question'), ('R', 'Ranked question')]#
- desc#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_type_display(*, field=<django.db.models.fields.CharField: type>)#
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- options#
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- ranked_options#
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- save(*args, **kwargs)[source]#
Saves a Question instance and automatically creates Yes/No options if it’s a Yes/No question.
- Parameters:
args – Variable length argument list.
kwargs – Keyword arguments.
- type#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- voting#
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- yesno_options#
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.children
is aReverseManyToOneDescriptor
instance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- class voting.models.QuestionOption[source]#
Bases:
Model
Represents an option for a question in a voting system.
- question#
The question to which this option belongs.
- Type:
ForeignKey
- number#
The number of the option.
- Type:
PositiveIntegerField
- option#
The text of the option.
- Type:
TextField
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- number#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- option#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- question#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- question_id#
- class voting.models.QuestionOptionRanked[source]#
Bases:
Model
Represents a ranked option for a question in a voting system.
- question#
The question to which this ranked option belongs.
- Type:
ForeignKey
- number#
The number of the ranked option.
- Type:
PositiveIntegerField
- option#
The text of the ranked option.
- Type:
TextField
- preference#
The preference number for the option.
- Type:
PositiveIntegerField
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- number#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- option#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- preference#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- question#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- question_id#
- class voting.models.QuestionOptionYesNo[source]#
Bases:
Model
Represents a Yes/No option for a question in a voting system.
- question#
The question to which this Yes/No option belongs.
- Type:
ForeignKey
- number#
The number of the Yes/No option.
- Type:
PositiveIntegerField
- option#
The text of the Yes/No option.
- Type:
TextField
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- number#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- option#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- question#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- question_id#
- class voting.models.Voting[source]#
Bases:
Model
Represents a voting in the system.
- name#
The name of the voting.
- Type:
CharField
- desc#
The description of the voting.
- Type:
TextField
- question#
The question related to this voting.
- Type:
ForeignKey
- created_at#
The timestamp when the voting was created.
- Type:
DateTimeField
- start_date#
The start date and time of the voting.
- Type:
DateTimeField
- end_date#
The end date and time of the voting.
- Type:
DateTimeField
- future_stop#
The future stop date and time of the voting.
- Type:
DateTimeField
- pub_key#
The public key associated with the voting.
- Type:
OneToOneField
- auths#
The authorizations related to this voting.
- Type:
ManyToManyField
- tally#
The tally of votes.
- Type:
JSONField
- postproc#
The post-processing data of the voting.
- Type:
JSONField
- exception DoesNotExist#
Bases:
ObjectDoesNotExist
- exception MultipleObjectsReturned#
Bases:
MultipleObjectsReturned
- auths#
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppings
andTopping.pizzas
areManyToManyDescriptor
instances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()
defined below.
- create_pubkey()[source]#
Creates a public key for the voting if it doesn’t already have one and if it has authorizations.
- created_at#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- desc#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- end_date#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- future_stop#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- get_votes(token='')[source]#
Retrieves votes for the voting.
- Parameters:
token (str) – Authorization token for retrieving votes.
- Returns:
A list of formatted votes.
- Return type:
list
- id#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- name#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>#
- postproc#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- pub_key#
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.place
is aForwardOneToOneDescriptor
instance.
- pub_key_id#
- question#
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parent
is aForwardManyToOneDescriptor
instance.
- question_id#
- start_date#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- tally#
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
views.py#
- class voting.views.VotingUpdate[source]#
Bases:
RetrieveUpdateDestroyAPIView
View for retrieving, updating, or deleting a Voting instance.
Extends Django REST framework’s RetrieveUpdateDestroyAPIView.
- queryset#
Default queryset for Voting objects.
- serializer_class#
Serializer class for Voting objects.
- filter_backends#
Backend used for filtering the queryset.
- permission_classes#
Permission classes required for the view.
- filter_backends = (<class 'django_filters.rest_framework.backends.DjangoFilterBackend'>,)#
- permission_classes = (<class 'base.perms.UserIsStaff'>,)#
- put(request, voting_id, *args, **kwars)[source]#
Handles PUT requests to update a Voting instance.
- Parameters:
request – The incoming HTTP request containing update data.
voting_id – ID of the Voting instance to update.
args – Variable length argument list.
kwargs – Keyword arguments.
- Returns:
Response indicating the success or failure of the operation.
- queryset#
- serializer_class#
alias of
VotingSerializer
- class voting.views.VotingView[source]#
Bases:
ListCreateAPIView
View for listing and creating Voting instances.
Extends Django REST framework’s ListCreateAPIView for handling the retrieval (GET) and creation (POST) of Voting instances.
- queryset#
Default queryset for Voting objects.
- serializer_class#
Serializer class for Voting objects.
- filter_backends#
Backend used for filtering the queryset.
- filterset_fields#
Fields allowed for filtering.
- filter_backends = (<class 'django_filters.rest_framework.backends.DjangoFilterBackend'>,)#
- filterset_fields = ('id',)#
- get(request, *args, **kwargs)[source]#
Handles GET requests to retrieve Voting instances.
- Parameters:
request – The incoming HTTP request.
args – Variable length argument list.
kwargs – Keyword arguments including ‘voting_id’ if provided.
- Returns:
Response with serialized Voting data or error message.
- post(request, *args, **kwargs)[source]#
Handles POST requests to create a new Voting instance.
- Parameters:
request – The incoming HTTP request containing data for the new Voting instance.
args – Variable length argument list.
kwargs – Keyword arguments.
- Returns:
Response indicating the success or failure of the operation.
- queryset#
- serializer_class#
alias of
VotingSerializer
- voting.views.end_voting(request, voting_id)[source]#
View function to end a specific voting.
Sets the end date of the voting and saves it.
- Parameters:
request – The incoming HTTP request.
voting_id – The ID of the voting to be ended.
- Returns:
Redirects to the voting list page after ending the voting, or renders the current page if not confirmed.
- voting.views.list_votings(request)[source]#
View function for listing all votings.
Displays a list of votings. If the user is staff, all votings are shown. Otherwise, only votings related to the user are shown.
- Parameters:
request – The incoming HTTP request.
- Returns:
Rendered webpage with the list of votings.
- voting.views.start_voting(request, voting_id)[source]#
View function to start a specific voting.
Sets the start date of the voting and saves it.
- Parameters:
request – The incoming HTTP request.
voting_id – The ID of the voting to be started.
- Returns:
Redirects to the voting list page after starting the voting, or renders the current page if not confirmed.
- voting.views.tally_view(request, voting_id)[source]#
View function to tally votes for a specific voting.
Tally the votes and display the results for a specific voting.
- Parameters:
request – The incoming HTTP request.
voting_id – The ID of the voting to tally.
- Returns:
Redirects to the voting list page after tallying, or renders the current page if not confirmed.
- voting.views.update_voting(request, voting_id)[source]#
View function for updating a specific voting.
Allows updating the details of a voting through a form.
- Parameters:
request – The incoming HTTP request.
voting_id – The ID of the voting to be updated.
- Returns:
Redirects to the voting list page after updating, or renders the update form if not confirmed.
- voting.views.voting_delete(request, voting_id)[source]#
View function for deleting a specific voting.
- Parameters:
request – The incoming HTTP request.
voting_id – The ID of the voting to be deleted.
- Returns:
Redirects to the voting list page after deletion, or renders the current page if the deletion isn’t confirmed.
forms.py#
- class voting.forms.UpdateVotingForm[source]#
Bases:
ModelForm
A Django ModelForm for updating Voting instances.
This form is used to update the details of a Voting instance. It includes fields for the name, description, and associated question of the Voting.
- Meta[source]#
An inner class that provides metadata to the ModelForm class. It defines the model associated with the form and the fields to be included in the form.
- class Meta[source]#
Bases:
object
Meta class for UpdateVotingForm.
Specifies the model and fields associated with this form.
- model#
The model associated with this form.
- fields#
The fields of the model to include in this form.
- fields = ['name', 'desc', 'question']#
- base_fields = {'desc': <django.forms.fields.CharField object>, 'name': <django.forms.fields.CharField object>, 'question': <django.forms.models.ModelChoiceField object>}#
- declared_fields = {}#
- property media#
Return all media required to render the widgets on this form.
serializers.py#
- class voting.serializers.QuestionOptionRankedSerializer[source]#
Bases:
HyperlinkedModelSerializer
Serializer for QuestionOptionRanked model.
Provides serialization for QuestionOptionRanked objects with hyperlinked relationships.
- class Meta[source]#
Bases:
object
Meta class for QuestionOptionRankedSerializer.
Specifies the model and fields to be serialized.
- fields = ('number', 'option')#
- model#
alias of
QuestionOptionRanked
- class voting.serializers.QuestionOptionSerializer[source]#
Bases:
HyperlinkedModelSerializer
Serializer for QuestionOption model.
Provides serialization for QuestionOption objects with hyperlinked relationships.
- class Meta[source]#
Bases:
object
Meta class for QuestionOptionSerializer.
Specifies the model and fields to be serialized.
- fields = ('number', 'option')#
- model#
alias of
QuestionOption
- class voting.serializers.QuestionOptionYesNoSerializer[source]#
Bases:
HyperlinkedModelSerializer
Serializer for QuestionOptionYesNo model.
Provides serialization for QuestionOptionYesNo objects with hyperlinked relationships.
- class Meta[source]#
Bases:
object
Meta class for QuestionOptionYesNoSerializer.
Specifies the model and fields to be serialized.
- fields = ('number', 'option')#
- model#
alias of
QuestionOptionYesNo
- class voting.serializers.QuestionSerializer[source]#
Bases:
HyperlinkedModelSerializer
Serializer for Question model.
Provides serialization for Question objects with hyperlinked relationships. Includes a custom method for serializing related options based on the question type.
- options#
Field to serialize related options.
- Type:
SerializerMethodField
- class voting.serializers.SimpleVotingSerializer[source]#
Bases:
HyperlinkedModelSerializer
Simplified serializer for Voting model.
Provides a simpler serialization for Voting objects focusing on key details.
- question#
Nested serializer for the related question.
- Type:
- class voting.serializers.VotingSerializer[source]#
Bases:
HyperlinkedModelSerializer
Serializer for Voting model.
Provides serialization for Voting objects with hyperlinked relationships and nested serialization for related objects.
- question#
Nested serializer for the related question.
- Type:
- pub_key#
Nested serializer for the related public key.
- Type:
KeySerializer
- auths#
Nested serializer for related authorizations.
- Type:
AuthSerializer
filters.py#
- class voting.filters.StartedFilter[source]#
Bases:
SimpleListFilter
A custom filter for the Django admin interface to filter objects based on their start status.
This filter allows admin users to filter objects based on whether they have started, are running, or have finished.
- title#
The title displayed on the filter interface.
- Type:
str
- parameter_name#
The name of the parameter used in the query string.
- Type:
str
- lookups(request, model_admin)[source]#
Returns a list of tuples containing the lookup options for this filter.
- Parameters:
request (HttpRequest) – The HttpRequest object.
model_admin (ModelAdmin) – The ModelAdmin object for the model.
- Returns:
List of tuples, where each tuple represents a lookup option.
- Return type:
list
- parameter_name = 'started'#
- queryset(request, queryset)[source]#
Returns the queryset filtered based on the selected lookup option.
- Parameters:
request (HttpRequest) – The HttpRequest object.
queryset (QuerySet) – The original queryset.
- Returns:
Filtered queryset based on the selected lookup option.
- Return type:
QuerySet
- title = 'started'#
signals.py#
- voting.signals.future_stop_add_task(sender, created, instance, **kwargs)[source]#
A Django signal receiver that triggers a task manager for future stop voting events.
This function is called automatically after a Voting object is saved. It sets the ‘created_at’ attribute of the Voting instance to the current time and then calls the future stop task manager with the instance’s ID.
- Parameters:
sender (Model) – The model class that sent the signal.
created (bool) – True if a new record was created.
instance (Voting) – The instance of the Voting model that was saved.
**kwargs – Additional keyword arguments.
- Returns:
This function does not return a value, but triggers the future_stop_task_manager function.
- Return type:
None
tasks.py#
utils.py#
- voting.utils.future_stop_task_manager(voting_id)[source]#
Manages the scheduling and revocation of a future stop task for a voting event.
This function checks if a voting event has a scheduled end date and manages the Celery task associated with stopping the voting at the specified future date and time. If an existing task is found for the voting event, it is revoked and a new task is scheduled if a future stop date is set.
- Parameters:
voting_id (int) – The primary key of the voting event to be managed.
- Returns:
This function does not return anything but manages the scheduling and revocation of Celery tasks based on the voting event’s schedule.
- Return type:
None
tests.py#
- class voting.tests.FutureClosureTests[source]#
Bases:
BaseTestCase
Test case class for testing the future closure functionality of votings.
This class includes methods to test the task that handles the automatic closure of votings at a future date.
- setUp()[source]#
Sets up necessary data and schedules a future stop voting task before each test method.
- test_end_date()[source]#
Tests if the end date of the voting is set correctly after the execution of the future stop task.
Verifies if the end date of the voting matches the scheduled future stop date.
- class voting.tests.PostProcTest[source]#
Bases:
TestCase
Test case class for testing the post-processing functionalities of votings.
This class includes methods to test the post-processing of different types of votings such as comment and ranked votings.
- test_do_comment_postproc()[source]#
Tests the post-processing functionality for a text comment voting.
Verifies if the post-processing is done correctly for text comment votings.
- test_do_comment_postproc_no_votes()[source]#
Tests the post-processing functionality for a text comment voting with no votes.
Verifies if the correct exception is raised when there are no votes.
- class voting.tests.QuestionTestCases[source]#
Bases:
BaseTestCase
Test case class for Question-related functionalities.
This class includes setup and teardown methods, along with various methods to test the Question model and its related options.
- createClassicQuestionSuccess()[source]#
Creates a classic question successfully for testing purposes.
- test_question_option_comment_error_str()[source]#
Tests the string representation error for the QuestionOption model when linked to a text comment question.
- test_question_option_error()[source]#
Tests creating a QuestionOption for a non-compatible question type and expecting an error.
- test_question_option_error_str()[source]#
Tests the string representation error for the QuestionOption model when linked to a non-classic or multiple choice question.
- test_question_option_ranked()[source]#
Tests creating and saving a QuestionOptionRanked for a ranked question.
- test_question_option_ranked_error()[source]#
Tests creating a QuestionOptionRanked for a non-ranked question type and expecting an error.
- test_question_option_ranked_error_str()[source]#
Tests the string representation error for the QuestionOptionRanked model when linked to a non-ranked question.
- test_question_option_ranked_to_string()[source]#
Tests the string representation of the QuestionOptionRanked model.
- test_question_option_to_string()[source]#
Tests the string representation of the QuestionOption model for a classic question.
- test_question_option_yesno()[source]#
Tests creating and saving a QuestionOptionYesNo for a Yes/No question.
- test_question_option_yesno_error()[source]#
Tests creating a QuestionOptionYesNo for a non-Yes/No question type and expecting an error.
- test_question_option_yesno_error_str()[source]#
Tests the string representation error for the QuestionOptionYesNo model when linked to a non-Yes/No question.
- class voting.tests.VotingTestCase[source]#
Bases:
BaseTestCase
Test case class for Voting-related functionalities.
This class includes setup and teardown methods, along with various methods to test different types of votings.
- create_classic_voting()[source]#
Creates and returns a classic type voting instance.
- Returns:
The created classic voting instance.
- Return type:
- create_comment_voting()[source]#
Creates and returns a text comment type voting instance.
- Returns:
The created text comment voting instance.
- Return type:
- create_multiple_choice_voting()[source]#
Creates and returns a multiple choice type voting instance.
- Returns:
The created multiple choice voting instance.
- Return type:
- create_ranked_voting()[source]#
Creates and returns a ranked type voting instance.
- Returns:
The created ranked voting instance.
- Return type:
- create_voters(v)[source]#
Creates mock voters for a given voting.
- Parameters:
v (Voting) – The voting instance.
- create_yesno_voting()[source]#
Creates and returns a Yes/No type voting instance.
- Returns:
The created Yes/No voting instance.
- Return type:
- encrypt_msg(msg, v, bits=256)[source]#
Encrypts a message for a given voting using its public key.
- Parameters:
msg (int) – The message to encrypt.
v (Voting) – The voting instance.
bits (int) – The bit size for the encryption.
- Returns:
The encrypted message.
- Return type:
tuple
- get_or_create_user(pk)[source]#
Creates mock voters for a given voting.
- Parameters:
v (Voting) – The voting instance.
- store_classic_votes(v)[source]#
Stores mock votes for a classic type voting.
- Parameters:
v (Voting) – The voting instance.
- Returns:
A dictionary of the clear votes count.
- Return type:
dict
- store_comment_votes(v)[source]#
Stores mock comment votes for a text comment voting.
- Parameters:
v (Voting) – The voting instance.
- Returns:
A list of clear vote strings.
- Return type:
list
- store_multiple_choice_votes(v)[source]#
Stores mock votes for a multiple choice voting.
- Parameters:
v (Voting) – The voting instance.
- Returns:
A dictionary of the clear votes count.
- Return type:
dict
- store_ranked_votes(v)[source]#
Stores mock ranked votes for a ranked voting.
- Parameters:
v (Voting) – The voting instance.
- Returns:
A list of clear vote strings.
- Return type:
list
- store_yesno_votes(v)[source]#
Stores mock votes for a Yes/No type voting.
- Parameters:
v (Voting) – The voting instance.
- Returns:
A dictionary of the clear votes count.
- Return type:
dict
- test_complete_comment_voting()[source]#
Test method to verify the complete voting process for a text comment voting.
This method tests the creation of a text comment voting, storing votes, and tallying them to verify the vote count.
- test_complete_multiple_choice_voting()[source]#
Test method to verify the complete voting process for a multiple choice voting.
This method tests the creation of a multiple choice voting, storing votes, and tallying them to verify the vote count.
- test_complete_ranked_voting()[source]#
Test method to verify the complete voting process for a ranked voting.
This method tests the creation of a ranked voting, storing votes, and tallying them to verify the vote count.
- test_complete_voting()[source]#
Test method to verify the complete voting process for a classic voting.
This method tests the creation of a classic voting, storing votes, and tallying them to verify the vote count.
- test_complete_yesno_voting()[source]#
Test method to verify the complete voting process for a Yes/No voting.
This method tests the creation of a Yes/No voting, storing votes, and tallying them to verify the vote count.
- test_create_multiple_choice_voting_from_api()[source]#
Test method to verify the multiple choice voting creation process via API.
This method tests the creation of a multiple choice voting using API endpoints and different user permissions.
- test_create_voting_from_api()[source]#
Test method to verify the voting creation process via API.
This method tests the creation of a voting using API endpoints and different user permissions.
- test_create_voting_from_api_comment()[source]#
Test method to verify the text comment voting creation process via API.
This method tests the creation of a text comment voting using API endpoints and different user permissions.
tests_selenium.py#
- class voting.test_selenium.QuestionsTests[source]#
Bases:
StaticLiveServerTestCase
Test case class for testing the question creation functionalities using Selenium.
This class includes methods to test the creation of various types of questions through the admin interface.
- setUp()[source]#
Sets up necessary data and configurations before each test method. Initializes Selenium WebDriver for browser-based testing.
- test_create_classic_question()[source]#
Tests the creation of a classic question through the admin interface. Verifies if the question is successfully created and listed in the admin panel.
- test_create_classic_question_option()[source]#
Tests the creation of an option for a classic question through the admin interface. Verifies if the option is successfully created and listed in the admin panel.
- test_create_ranked_question()[source]#
Tests the creation of a ranked question through the admin interface. Verifies if the question is successfully created and listed in the admin panel.
- test_create_ranked_question_option()[source]#
Tests the creation of an option for a ranked question through the admin interface. Verifies if the option is successfully created and listed in the admin panel.
- class voting.test_selenium.VotingTests[source]#
Bases:
StaticLiveServerTestCase
Test case class for testing the voting creation functionalities using Selenium.
This class includes methods to test the creation of various types of votings through the admin interface.
- create_classic_option()[source]#
Creates an option for a classic question using the admin interface.
- setUp()[source]#
Sets up necessary data and configurations before each test method. Initializes Selenium WebDriver for browser-based testing.
test_configurator_selenium.py#
- class voting.test_configurator_selenium.ConfiguratorTests[source]#
Bases:
StaticLiveServerTestCase
Test case class for testing the configurator functionalities using Selenium.
This class includes methods to test the configuration and manipulation of votings through the web interface.
- add_user_to_census(pk)[source]#
Adds a user to the census for a particular voting.
- Parameters:
pk (int) – Primary key of the user to be added.
- Returns:
The created Census instance.
- Return type:
- create_users()[source]#
Creates user instances for testing, including admin and non-admin users. :return: Returns the non-admin user. :rtype: User
- setUp()[source]#
Sets up necessary data and configurations before each test method. Initializes Selenium WebDriver for browser-based testing.
- test_access_to_voting_lists_view_as_admin()[source]#
Tests admin access to the list of votings through the web interface. Verifies if the admin user can view the list of votings.
- test_access_to_voting_lists_view_as_user()[source]#
Tests non-admin user access to the list of votings through the web interface. Verifies if the non-admin user can view the list of votings.
- test_results_from_voting_list()[source]#
Tests viewing the results of a voting from the list of votings as an admin. Verifies if the voting results can be accessed and displayed correctly.
- test_start_voting_from_votings_list()[source]#
Tests the functionality to start a voting from the list of votings as an admin. Verifies if the voting can be started successfully.