-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding tests and logic #104
Open
rimonsh
wants to merge
4
commits into
redhat-beyond:main
Choose a base branch
from
rimonsh:poll_suggestion_logic
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,82 @@ | ||
# from django.test import TestCase | ||
|
||
# Create your tests here. | ||
# from django.test import TestCase | ||
|
||
# Create your tests here. | ||
from poll.models import Poll, get_default_end_date | ||
from .models import PollSuggestion | ||
from datetime import datetime, timedelta | ||
from django.utils import timezone | ||
from event.models import Event | ||
from category.models import Category | ||
from location.models import Location | ||
from category_location.models import CategoryLocation | ||
import pytest | ||
|
||
EVENT_NAME = "weight lifting" | ||
CATEGORY = "Gym1" | ||
LOCATION = "Holmes place Netanya" | ||
MAX_PART = 10 | ||
IS_PRIVATE = False | ||
DATETIME = datetime.now() | ||
MAX_SUGEGSTIONS = 5 | ||
DATETIME = timezone.now() | ||
|
||
|
||
@pytest.fixture | ||
def setup_category_location(): | ||
loc = Location( | ||
name=LOCATION, | ||
city="test city", | ||
street="test street", | ||
street_number=1, | ||
indoor=False, | ||
description="test description", | ||
) | ||
loc.save() | ||
cat = Category(name=CATEGORY) | ||
cat.save() | ||
cat_loc = CategoryLocation(location=loc, category=cat) | ||
cat_loc.save() | ||
return cat_loc | ||
|
||
|
||
@pytest.fixture | ||
def setup_event(setup_category_location): | ||
event = Event( | ||
category=setup_category_location.category, | ||
location=setup_category_location.location, | ||
poll=None, | ||
name=EVENT_NAME, | ||
max_participants=MAX_PART, | ||
start_time=DATETIME + timedelta(days=2), | ||
end_time=DATETIME + timedelta(days=3), | ||
is_private=IS_PRIVATE, | ||
) | ||
event.save() | ||
return event | ||
|
||
|
||
@pytest.fixture | ||
def setup_poll(setup_event): | ||
poll = Poll(event_id=setup_event, max_suggestions=MAX_SUGEGSTIONS, end_time=get_default_end_date()) | ||
poll.save() | ||
return poll | ||
|
||
|
||
@pytest.fixture | ||
def set_up_poll_suggestion(setup_poll): | ||
poll_s = PollSuggestion.objects.create(time=datetime.now() + timedelta(days=3), poll_id=setup_poll) | ||
rimonsh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
poll_s.save() | ||
return poll_s | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestPollSuggestionModel: | ||
|
||
def test_create_poll_suggestion(self, set_up_poll_suggestion): | ||
poll_suggestion1 = PollSuggestion.objects.get(id=set_up_poll_suggestion.id) | ||
poll = poll_suggestion1.poll_id | ||
poll_s_from_db = poll.show_suggestions() | ||
return poll_s_from_db == poll_suggestion1 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe consider to add a field that tracks the number of votes each suggestion receives. This addition can provide valuable data for evaluating the popularity for each suggestion. Or you thought of alternative way for determining the chosen suggestion?