Intitial teams support #147
@ -226,7 +226,7 @@ class ExtensionUpdateForm(forms.ModelForm):
|
||||
|
||||
team_slug = self.cleaned_data['team']
|
||||
if team_slug == self.invalid_team_value:
|
||||
self.add_error('team', _('Please select a value'))
|
||||
self.add_error('team', _('Please select one of the valid values'))
|
||||
return
|
||||
if team_slug:
|
||||
team = self.request.user.teams.filter(slug=team_slug).first()
|
||||
|
@ -5,10 +5,13 @@ from django.test import TestCase
|
||||
|
||||
from common.tests.factories.extensions import create_approved_version, create_version
|
||||
from common.tests.factories.files import FileFactory, ImageFactory
|
||||
from common.tests.factories.teams import TeamFactory
|
||||
from common.tests.factories.users import UserFactory
|
||||
from common.tests.utils import _get_all_form_errors, CheckFilePropertiesMixin
|
||||
from extensions.models import Extension
|
||||
from files.models import File
|
||||
from reviewers.models import ApprovalActivity
|
||||
from teams.models import TeamsUsers
|
||||
|
||||
TEST_FILES_DIR = Path(__file__).resolve().parent / 'files'
|
||||
POST_DATA = {
|
||||
@ -499,3 +502,128 @@ class UpdateTest(CheckFilePropertiesMixin, TestCase):
|
||||
response3 = self.client.get(url)
|
||||
self.assertEqual(response3.status_code, 302)
|
||||
self.assertEqual(response3['Location'], extension.get_draft_url())
|
||||
|
||||
def test_team_field_in_draft_form(self):
|
||||
version = create_version(
|
||||
extension__status=Extension.STATUSES.INCOMPLETE,
|
||||
)
|
||||
extension = version.extension
|
||||
author = extension.authors.first()
|
||||
self.client.force_login(author)
|
||||
|
||||
team = TeamFactory(slug='test-team')
|
||||
TeamsUsers(team=team, user=author).save()
|
||||
|
||||
url = extension.get_draft_url()
|
||||
response = self.client.get(url)
|
||||
# a simple check that we have an input with the team option available
|
||||
self.assertContains(response, 'value="test-team"')
|
||||
|
||||
# post the form to save the team field
|
||||
response = self.client.post(
|
||||
url,
|
||||
{
|
||||
**POST_DATA,
|
||||
'team': 'test-team',
|
||||
'save_draft': '',
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 302, _get_all_form_errors(response))
|
||||
extension.refresh_from_db()
|
||||
self.assertEqual(extension.team.slug, 'test-team')
|
||||
|
||||
# can't assign an invalid team slug
|
||||
response = self.client.post(
|
||||
url,
|
||||
{
|
||||
**POST_DATA,
|
||||
'team': '-',
|
||||
'save_draft': '',
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 200, _get_all_form_errors(response))
|
||||
|
||||
# add another team member, they shouldn't see the field
|
||||
user = UserFactory()
|
||||
team2 = TeamFactory(slug='test-team2')
|
||||
TeamsUsers(team=team, user=user).save()
|
||||
TeamsUsers(team=team2, user=user).save()
|
||||
self.client.force_login(user)
|
||||
response = self.client.get(url)
|
||||
self.assertNotContains(response, 'value="test-team"')
|
||||
|
||||
response = self.client.post(
|
||||
url,
|
||||
{
|
||||
**POST_DATA,
|
||||
'team': 'test-team2',
|
||||
'save_draft': '',
|
||||
},
|
||||
)
|
||||
# the field is ignored: no error expected and the team wasn't updated
|
||||
self.assertEqual(response.status_code, 302, _get_all_form_errors(response))
|
||||
extension.refresh_from_db()
|
||||
self.assertEqual(extension.team.slug, 'test-team')
|
||||
|
||||
def test_team_field_in_update_form(self):
|
||||
"""This test is a copy-paste of the one above, only status, url and form data differ."""
|
||||
version = create_version(
|
||||
extension__status=Extension.STATUSES.APPROVED,
|
||||
)
|
||||
extension = version.extension
|
||||
author = extension.authors.first()
|
||||
self.client.force_login(author)
|
||||
|
||||
team = TeamFactory(slug='test-team')
|
||||
TeamsUsers(team=team, user=author).save()
|
||||
|
||||
url = extension.get_manage_url()
|
||||
response = self.client.get(url)
|
||||
# a simple check that we have an input with the team option available
|
||||
self.assertContains(response, 'value="test-team"')
|
||||
|
||||
# post the form to save the team field
|
||||
response = self.client.post(
|
||||
url,
|
||||
{
|
||||
**POST_DATA,
|
||||
'team': 'test-team',
|
||||
'save': '',
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 302, _get_all_form_errors(response))
|
||||
extension.refresh_from_db()
|
||||
self.assertEqual(extension.team.slug, 'test-team')
|
||||
|
||||
# can't assign an invalid team slug
|
||||
response = self.client.post(
|
||||
url,
|
||||
{
|
||||
**POST_DATA,
|
||||
'team': '-',
|
||||
'save_draft': '',
|
||||
},
|
||||
)
|
||||
self.assertEqual(response.status_code, 200, _get_all_form_errors(response))
|
||||
|
||||
# add another team member, they shouldn't see the field
|
||||
user = UserFactory()
|
||||
team2 = TeamFactory(slug='test-team2')
|
||||
TeamsUsers(team=team, user=user).save()
|
||||
TeamsUsers(team=team2, user=user).save()
|
||||
self.client.force_login(user)
|
||||
response = self.client.get(url)
|
||||
self.assertNotContains(response, 'value="test-team"')
|
||||
|
||||
response = self.client.post(
|
||||
url,
|
||||
{
|
||||
**POST_DATA,
|
||||
'team': 'test-team2',
|
||||
'save_draft': '',
|
||||
},
|
||||
)
|
||||
# the field is ignored: no error expected and the team wasn't updated
|
||||
self.assertEqual(response.status_code, 302, _get_all_form_errors(response))
|
||||
extension.refresh_from_db()
|
||||
self.assertEqual(extension.team.slug, 'test-team')
|
||||
|
Loading…
Reference in New Issue
Block a user