Skip to content

Conversation

@stiffneckjim
Copy link
Contributor

Single user vote function, now with unit and view tests.

kyc-wip and others added 17 commits April 15, 2022 14:45
Update to vote > views.py > vote_for_track for correct vote functionality but requires testing with multiple users:
         # If the upvote already exists, then unset upvote
        # If the downvote already exists, then unset downvote
        # If upvote already exists and then downvote is clicked, unset upvote and set downvote
        # If downvote already exists and then upvote is clicked, unset downvote and set upvote
Update to vote > views.py > vote_for_track for correct vote functionality but requires testing with multiple users:
         # If the upvote already exists, then unset upvote
        # If the downvote already exists, then unset downvote
        # If upvote already exists and then downvote is clicked, unset upvote and set downvote
        # If downvote already exists and then upvote is clicked, unset downvote and set upvote
Vote view re-factoring (work in progress) with aim of vote model unit testing
finish moving the vote calculation to
`models.py`.
Moved logic to `models.py`.
Added a `utils.py` with vote logic.
Renamed voting methods from `spotify_up_vote`/`spotify_down_vote` to
just `up_vote`/`down_vote`
Working on getting the view tests to work with login.
pylance from reformatting .env files.
including testing two users voting.
variables rather than class variables.
build-backend = "poetry.core.masonry.api"

[tool.pyright]
exclude = [".env", "env.example"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we using pyright?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pyright is apparently used by VS Code. However, the problem with the .env file doesn't appear to be related to pyright misbehaving so this change doesn't seem to help.

Comment on lines +25 to +56
# Voting the same way twice resets the vote
# If the user has already voted up...
if self.track_vote > 0:
# And the user votes up...
if vote_type == 1:
# Then reset the vote
self.track_vote = 0
# Otherwise if the user votes down...
else:
# Then record a down vote
self.track_vote = -1
# If the user has already voted down...
elif self.track_vote < 0:
# And the user votes up...
if vote_type == 1:
# Then record an up vote
self.track_vote = 1
# Otherwise if the user votes down...
else:
# Then reset the vote
self.track_vote = 0
# Otherwise the user has not voted yet
else:
# So if the user votes up...
if vote_type == 1:
# Record an up vote
self.track_vote = 1
# So if the user votes down...
else:
# Record a down vote
self.track_vote = -1
self.save()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider:

 def update_vote(self, vote_type):
        vote_upwards = 1 if vote_type > 0 else -1
        same_direction = -1 if vote_upwards == self.track_vote else 1
        self.track_vote += vote_upwards * same_direction
        assert -1 <= self.track_vote <= 1
        self.save()

Comment on lines 150 to 151
else:
pass
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider removing else: pass

@stiffneckjim stiffneckjim merged commit 9042e2d into main Jun 11, 2022
@stiffneckjim stiffneckjim deleted the TG-13--KYC--vote_on_playlist branch June 11, 2022 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants