Skip to content

Commit

Permalink
move check class -> create url dict into function to somehow fix brok…
Browse files Browse the repository at this point in the history
…en django magic
  • Loading branch information
Aloshi committed Oct 1, 2018
1 parent 901634e commit 0517568
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cabot/cabotapp/tests/test_revisions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from urlparse import urlsplit

import reversion
from django.core.urlresolvers import reverse, resolve

from cabot.cabotapp.models import Service, StatusCheck, HttpStatusCheck, TCPStatusCheck, JenkinsStatusCheck
from cabot.cabotapp.tests.utils import LocalTestCase
from cabot.cabotapp.revision_utils import get_revisions
from cabot.cabotapp.views import ServiceForm, HttpStatusCheckForm, JenkinsStatusCheckForm, TCPStatusCheckForm

import reversion


def get_post_data(obj, form_class, changed_fields):
form = form_class(instance=obj)
Expand All @@ -19,11 +20,14 @@ def get_post_data(obj, form_class, changed_fields):
old_fields[field_name] = val
return dict(old_fields.items() + changed_fields.items())

_create_check_urls = {
HttpStatusCheck: reverse('create-http-check'),
JenkinsStatusCheck: reverse('create-jenkins-check'),
TCPStatusCheck: reverse('create-tcp-check'),
}

def _create_check_url(check_cls):
urls = {
HttpStatusCheck: reverse('create-http-check'),
JenkinsStatusCheck: reverse('create-jenkins-check'),
TCPStatusCheck: reverse('create-tcp-check'),
}
return urls[check_cls]


def _edit_check_url(check):
Expand Down Expand Up @@ -60,7 +64,7 @@ def _delete_check(self, check):

def _create_check(self, model, fields):
data = get_post_data(None, _check_form_classes[model], fields)
response = self.client.post(_create_check_urls[model], data=data)
response = self.client.post(_create_check_url(model), data=data)
self.assertEqual(response.status_code, 302)
pk = resolve(urlsplit(response.url).path).kwargs['pk']
return model.objects.get(pk=pk)
Expand Down

0 comments on commit 0517568

Please sign in to comment.