-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Changes from 9 commits
92e5142
33048cb
0a542dd
f600593
662c2ca
1c31395
0b0e939
d35cfe0
6653e2e
0294e95
a0d8816
8a252b7
567be81
fc04ac0
886a513
728c9d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
||
|
@@ -90,7 +91,13 @@ def __init__(self, *args, **kwargs): | |
|
||
def clean(self): | ||
cleaned_data = super(GoldProjectForm, self).clean() | ||
project_slug = cleaned_data.get('project', "") | ||
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(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this fits better on a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeahh... that will be better. |
||
return cleaned_data | ||
if project_slug: | ||
self.add_error(None, "No project found.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.') |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to have an assert about that |
||
self.assertFormError( | ||
resp, form='form', field=None, errors='No project found.' | ||
) | ||
|
||
def test_too_many_projects(self): | ||
self.project2 = get(Project, slug='test2') | ||
|
||
|
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.
please use single quotes