-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from edx/ri/EDUCATOR-1672-org-short-name-valid…
…ation-django-admin EDUCATOR-1672 validate org short_name field and add help_text in django admin to prohibit unicode
- Loading branch information
Showing
4 changed files
with
73 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('organizations', '0004_auto_20170413_2315'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='organization', | ||
name='short_name', | ||
field=models.CharField(help_text="Please do not use any spaces or special characters in short name. This short name will be used in the course's course key.", max_length=255, verbose_name=b'Short Name', db_index=True), | ||
), | ||
] |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# coding=utf-8 | ||
""" | ||
Tests for Organization Model. | ||
""" | ||
|
||
import ddt | ||
from django.core.exceptions import ValidationError | ||
from django.test import TestCase | ||
from organizations.tests.factories import OrganizationFactory | ||
|
||
|
||
@ddt.ddt | ||
class TestOrganizationModel(TestCase): | ||
""" OrganizationModel tests. """ | ||
def setUp(self): | ||
super(TestOrganizationModel, self).setUp() | ||
self.organization = OrganizationFactory.create() | ||
|
||
@ddt.data( | ||
"short name with space", | ||
"short_name[with,special", | ||
"shórt_name" | ||
) | ||
def test_clean_error(self, short_name): | ||
""" | ||
Verify that the clean method raises validation error if org short name | ||
consists of special characters or spaces. | ||
""" | ||
self.organization.short_name = short_name | ||
self.assertRaises(ValidationError, self.organization.clean) | ||
|
||
@ddt.data( | ||
"shortnamewithoutspace", | ||
"shortName123", | ||
"short_name" | ||
) | ||
def test_clean_success(self, short_name): | ||
""" | ||
Verify that the clean method returns None if org short name is valid | ||
""" | ||
self.organization.short_name = short_name | ||
self.assertEqual(self.organization.clean(), None) |
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,4 @@ | ||
ddt>=0.8.0,<1.1.1 | ||
coverage>=4.0.3,<5.0.0 | ||
django_nose>=1.3.0,<=2.0.0 | ||
edx-lint>=0.5.2,<1.0.0 | ||
|