1

I have a special Django admin action called "run_test".

I would like to start that action from a Jenkins job on some items.

Something like this was my idea

import json
import requests


url = "http://localhost:8000/admin/app/model/"
item = { "user": "jenkins", 
         "password": "password", 
          "action": "run_test",
          "index": 0
       }
headers = {"Content-Type":"application/json","Accept": "application/json"}

resp = requests.post(url,data=json.dumps(item),headers=headers)

print(resp)

403 is the answer I got as a response.

Is there a way to run Django admin command with curl or request.post?

How can I include a queryset?

Note: manage.py command is not an option

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Nils Zenker
  • 659
  • 7
  • 11
  • Your question is not at all clear. What is that post supposed to do? What "action" is meant to be triggered? What *exact* response do you get? – Daniel Roseman Apr 15 '19 at 12:13
  • my action is called "run". Ok I see this might be misleading. I have some tests saved as a model instance. Jenkins schould run the post command to trigger some Tests inside django. I modified my question a bit – Nils Zenker Apr 15 '19 at 12:41
  • But what is "run"? What kind of thing is it? Where is the code? How is it related to the URL /admin/app/model/? – Daniel Roseman Apr 15 '19 at 12:49
  • as mentiond in my fisrt sentence: "django admin action called "run"". Admin actions are normally "delete all selected items". You can performthem by goind to localhost/app/admin -> and then click your model. I created a new one which made some stuf with the selected items (index = 0) For example my query would start the "run" command on Item with index = 0, so the first item. the run command itself is something like take that instance and add some values or delete some values. Nothing special. To be precise: https://docs.djangoproject.com/fr/2.1/ref/contrib/admin/actions/ – Nils Zenker Apr 15 '19 at 12:57

1 Answers1

0

This requires a bit of stateful shell scripting -- login to admin area, obtain a magic cookie and then shoot your custom requests with the magic cookie included. Details in this answer.

Anton Kraievyi
  • 4,182
  • 4
  • 26
  • 41