I want to test my function, where I add a new object to a database and then (still in this function) the object is being sent to a server. The problem is that to send the object to a server I need to run VPN. I'm wondering is there a way to run this function in my test, but skip the line responsible for sending the object to the server, or somehow simulate this behavior? Currently, I'm not able to run my test because I'm getting Failed to establish a new connection: [Errno 110] Connection timed out
My test looks like this:
def test_create_ticket_POST_adds_new_ticket(self):
response = self.client.post(self.create_ticket_url, {
'title': 'test title',
'description': 'test description',
'grant_id': 'test grant id',
})
result_title = Ticket.objects.filter(owner=self.user).order_by('-last_update').first().title
result_count = Ticket.objects.filter(owner=self.user).count()
self.assertEquals(response.status_code, 302)
self.assertEquals(result_title, 'test title')
self.assertEquals(result_count, 1)
And the post request is calling this function:
@login_required
@transaction.atomic
def create_ticket(request):
if request.method == 'POST':
ticket_form = TicketForm(request.POST)
tags_form = TagsForm(request.POST)
attachments = AttachmentForm(request.POST, request.FILES)
if ticket_form.is_valid() and attachments.is_valid() and tags_form.is_valid():
jira = JIRA(server=JIRA_URL, basic_auth=(jira_user, jira_password))
new_issue = add_issue(request, jira, ticket_form)
add_attachments(request, jira, new_issue)
set_tags(request, new_issue, tags_form)
messages.info(request, _(f"Ticket {new_issue} has been created."))
return redirect(f'/tickets/{new_issue}/')
else:
ticket_form = TicketForm()
tags_form = TagsForm()
attachments = AttachmentForm(request.POST, request.FILES)
return render(request, "client_interface/ticketform.html",
{'ticket_form': ticket_form, 'attachments': attachments, 'tags_form': tags_form})
And this is all about JIRA_URL
in my view function.
Aucun commentaire:
Enregistrer un commentaire