Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #32 from brandonsavage/fixbouncerform

Fixes Bug 922281 - Fixes the API to accept and load an existing alias and then update it from the POST data, preventing an unknown error from occurring.
  • Loading branch information...
commit 897ab227cef9437c0ff6345f472008f838e1dc3f 2 parents 533ebf1 + 6d00b82
@brandonsavage brandonsavage authored
Showing with 16 additions and 3 deletions.
  1. +10 −2 apps/api/tests/test_products.py
  2. +6 −1 apps/api/views.py
View
12 apps/api/tests/test_products.py
@@ -174,13 +174,21 @@ def test_product_language_delete_all(self):
def test_create_update_alias(self):
Product.objects.create(name='MyTestProduct')
-
+ Product.objects.create(name='MyTestProduct2')
+
response = self.c.post(reverse('api.views.create_update_alias'),
{'alias': 'my-test-alias',
'related_product': 'MyTestProduct'})
self.assertEqual(response.status_code, 200,
'Status code should be 200 when alias created')
+
+ response = self.c.post(reverse('api.views.create_update_alias'),
+ {'alias': 'my-test-alias',
+ 'related_product': 'MyTestProduct2'})
+
+ self.assertEqual(response.status_code, 200,
+ 'Updating a product should produce a 200 status code')
def test_create_update_alias_requires_alias_name(self):
Product.objects.create(name='MyTestProduct')
@@ -224,7 +232,7 @@ def test_create_update_alias_requires_valid_product_name(self):
Product.objects.create(name='MyTestProduct')
response = self.c.post(reverse('api.views.create_update_alias'),
- {'alias': 'myMyTestProduct',
+ {'alias': 'MyTestProduct',
'related_product': 'MyTestProduct'})
xmldoc = minidom.parseString(response.content)
View
7 apps/api/views.py
@@ -368,7 +368,12 @@ def create_update_alias(request):
xml = XMLRenderer()
- form = ProductAliasForm(request.POST)
+ try:
+ instance = ProductAlias.objects.get(alias=request.POST.get('alias'))
+ form = ProductAliasForm(request.POST, instance=instance)
+ except ProductAlias.DoesNotExist:
+ form = ProductAliasForm(request.POST)
+
if not form.is_valid():
if 'alias' in form.errors:
if 'required' in form.errors['alias'][0]:
Please sign in to comment.
Something went wrong with that request. Please try again.