Skip to content

Fix the form for adopting a project #4721

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

Merged
merged 16 commits into from
Oct 17, 2018
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions readthedocs/gold/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django import forms

from readthedocs.payments.forms import StripeModelForm, StripeResourceMixin
from readthedocs.projects.models import Project

from .models import LEVEL_CHOICES, GoldUser

Expand Down Expand Up @@ -90,7 +91,13 @@ def __init__(self, *args, **kwargs):

def clean(self):
cleaned_data = super(GoldProjectForm, self).clean()
project_slug = cleaned_data.get('project', "")
Copy link
Member

Choose a reason for hiding this comment

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

please use single quotes

if self.projects.count() < self.user.num_supported_projects:
return cleaned_data

self.add_error(None, 'You already have the max number of supported projects.')
# Checking if the project with the entered slug
# is present in the database or not
if Project.objects.filter(slug=project_slug).exists():
Copy link
Member

Choose a reason for hiding this comment

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

Maybe this fits better on a clean_project method?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeahh... that will be better.
I have implemented it.

return cleaned_data
if project_slug:
self.add_error(None, "No project found.")
Copy link
Member

Choose a reason for hiding this comment

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

Single quotes

else:
self.add_error(None, 'You already have the max number of supported projects.')
7 changes: 7 additions & 0 deletions readthedocs/rtd_tests/tests/test_gold.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def test_adding_projects(self):
self.assertEqual(self.golduser.projects.count(), 1)
self.assertEqual(resp.status_code, 302)

def test_incorrect_input_when_adding_projects(self):
self.assertEqual(self.golduser.projects.count(), 0)
resp = self.client.post(reverse('gold_projects'), data={'project': 'random-incorrect-slug'})
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to have an assert about that random-incorrect-slug doesn't exists on the db

self.assertFormError(
resp, form='form', field=None, errors='No project found.'
)

def test_too_many_projects(self):
self.project2 = get(Project, slug='test2')

Expand Down