|
15 | 15 | from amo.urlresolvers import reverse
|
16 | 16 | from addons.models import Addon, AddonUser, Charity
|
17 | 17 | from applications.models import AppVersion
|
18 |
| -from devhub.forms import ContribForm, ProfileForm |
| 18 | +from devhub.forms import ContribForm |
| 19 | +from files.models import File, Platform |
19 | 20 | from users.models import UserProfile
|
20 | 21 | from versions.models import License, Version
|
21 | 22 |
|
@@ -157,7 +158,7 @@ def formset(*args, **kw):
|
157 | 158 | prefix and initial_count can be set in **kw.
|
158 | 159 | """
|
159 | 160 | prefix = kw.pop('prefix', 'form')
|
160 |
| - initial_count = kw.pop('initial_count', 0) |
| 161 | + initial_count = kw.pop('initial_count', len(args)) |
161 | 162 | data = {prefix + '-TOTAL_FORMS': len(args),
|
162 | 163 | prefix + '-INITIAL_FORMS': initial_count}
|
163 | 164 | for idx, d in enumerate(args):
|
@@ -353,8 +354,10 @@ def test_add_user_twice(self):
|
353 | 354 | ['An author can only be listed once.'])
|
354 | 355 |
|
355 | 356 | def test_success_delete_user(self):
|
| 357 | + # Add a new user so we have one to delete. |
356 | 358 | data = self.formset(dict(user='regular@mozilla.com', listed=True,
|
357 |
| - role=amo.AUTHOR_ROLE_OWNER, position=1)) |
| 359 | + role=amo.AUTHOR_ROLE_OWNER, position=1), |
| 360 | + initial_count=0) |
358 | 361 | self.client.post(self.url, data)
|
359 | 362 |
|
360 | 363 | one, two = self.client.get(self.url).context['user_form'].initial_forms
|
@@ -839,16 +842,90 @@ def formset(self, *args, **kw):
|
839 | 842 | defaults.update(kw)
|
840 | 843 | return formset(*args, **defaults)
|
841 | 844 |
|
| 845 | + |
| 846 | +class TestVersionEditDetails(TestVersionEdit): |
| 847 | + |
| 848 | + def setUp(self): |
| 849 | + super(TestVersionEditDetails, self).setUp() |
| 850 | + ctx = self.client.get(self.url).context |
| 851 | + compat = initial(ctx['compat_form'].forms[0]) |
| 852 | + files = initial(ctx['file_form'].forms[0]) |
| 853 | + self.initial = formset(compat, **formset(files, prefix='files')) |
| 854 | + |
| 855 | + def formset(self, *args, **kw): |
| 856 | + defaults = dict(self.initial) |
| 857 | + defaults.update(kw) |
| 858 | + return super(TestVersionEditDetails, self).formset(*args, **defaults) |
| 859 | + |
842 | 860 | def test_edit_notes(self):
|
843 |
| - f = self.client.get(self.url).context['compat_form'].initial_forms[0] |
844 |
| - d = formset(initial(f), releasenotes='xx', approvalnotes='yy', |
845 |
| - initial_count=1) |
| 861 | + d = self.formset(releasenotes='xx', approvalnotes='yy') |
846 | 862 | r = self.client.post(self.url, d)
|
847 | 863 | eq_(r.status_code, 302)
|
848 | 864 | version = self.get_version()
|
849 | 865 | eq_(unicode(version.releasenotes), 'xx')
|
850 | 866 | eq_(unicode(version.approvalnotes), 'yy')
|
851 | 867 |
|
| 868 | + def test_version_number_redirect(self): |
| 869 | + url = self.url.replace(str(self.version.id), self.version.version) |
| 870 | + r = self.client.get(url, follow=True) |
| 871 | + self.assertRedirects(r, self.url) |
| 872 | + |
| 873 | + |
| 874 | +class TestVersionEditFiles(TestVersionEdit): |
| 875 | + |
| 876 | + def setUp(self): |
| 877 | + super(TestVersionEditFiles, self).setUp() |
| 878 | + f = self.client.get(self.url).context['compat_form'].initial_forms[0] |
| 879 | + self.compat = initial(f) |
| 880 | + |
| 881 | + def formset(self, *args, **kw): |
| 882 | + compat = formset(self.compat, initial_count=1) |
| 883 | + compat.update(kw) |
| 884 | + return super(TestVersionEditFiles, self).formset(*args, **compat) |
| 885 | + |
| 886 | + def test_edit_status(self): |
| 887 | + f = self.client.get(self.url).context['file_form'].forms[0] |
| 888 | + # Public is one of the choices since the file is currently public. |
| 889 | + eq_([x[0] for x in f.fields['status'].choices], |
| 890 | + [amo.STATUS_BETA, amo.STATUS_UNREVIEWED, amo.STATUS_PUBLIC]) |
| 891 | + # Switch the status to Beta. |
| 892 | + data = initial(f) |
| 893 | + data['status'] = amo.STATUS_BETA |
| 894 | + r = self.client.post(self.url, self.formset(data, prefix='files')) |
| 895 | + eq_(r.status_code, 302) |
| 896 | + eq_(self.version.files.get().status, amo.STATUS_BETA) |
| 897 | + |
| 898 | + # Beta and unreviewed are the only choices. |
| 899 | + f = self.client.get(self.url).context['file_form'].forms[0] |
| 900 | + eq_([x[0] for x in f.fields['status'].choices], |
| 901 | + [amo.STATUS_BETA, amo.STATUS_UNREVIEWED]) |
| 902 | + |
| 903 | + def test_unique_platforms(self): |
| 904 | + for platform in amo.PLATFORMS: |
| 905 | + k, _ = Platform.objects.get_or_create(id=platform) |
| 906 | + # Move the existing file to Linux. |
| 907 | + f = self.version.files.get() |
| 908 | + f.update(platform=Platform.objects.get(id=amo.PLATFORM_LINUX.id)) |
| 909 | + # And make a new file for Mac. |
| 910 | + File.objects.create(version=self.version, |
| 911 | + platform_id=amo.PLATFORM_MAC.id) |
| 912 | + |
| 913 | + forms = map(initial, |
| 914 | + self.client.get(self.url).context['file_form'].forms) |
| 915 | + forms[1]['platform'] = forms[0]['platform'] |
| 916 | + r = self.client.post(self.url, self.formset(*forms, prefix='files')) |
| 917 | + eq_(r.status_code, 200) |
| 918 | + eq_(r.context['file_form'].non_form_errors(), |
| 919 | + ['A platform can only be chosen once.']) |
| 920 | + |
| 921 | + |
| 922 | +class TestVersionEditCompat(TestVersionEdit): |
| 923 | + |
| 924 | + def formset(self, *args, **kw): |
| 925 | + defaults = formset(prefix='files') |
| 926 | + defaults.update(kw) |
| 927 | + return super(TestVersionEditCompat, self).formset(*args, **defaults) |
| 928 | + |
852 | 929 | def test_add_appversion(self):
|
853 | 930 | f = self.client.get(self.url).context['compat_form'].initial_forms[0]
|
854 | 931 | d = self.formset(initial(f), dict(application=18, min=28, max=29),
|
|
0 commit comments