-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_rest.py
83 lines (75 loc) · 2.72 KB
/
test_rest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
This module has been created to the the REST API for the plugins module, in order to
check if it is possible to trigger an Event or a Script.
For authentication purposes it is necessary to create a User called "root".
"""
from core.plugins.models import Plugin, Script, Event
from django.conf import settings
from django.contrib.auth.models import User
from django.test import TestCase
from rest_framework.test import APIClient, force_authenticate
from rest_framework.authtoken.models import Token
from rest_framework import status
import os
class ItemsTest(TestCase):
def setUp(self):
"""
Method used to setup the test database
"""
# create a new user
user = User.objects.create_user('root', 'root@gmail.com', 'root')
user.is_superuser = True
user.save()
token = Token.objects.create(user=user)
# create a new Plugin
plugin = Plugin()
plugin.title = 'My test plugin'
plugin.description = ''
plugin.active_version = '1.0.0'
plugin.plugin_version = '1.0.0'
plugin.url_info = 'http://active.crs4.it'
plugin.authors = 'John Doe'
plugin.save()
# create a new Script
script = Script()
script.title = 'Test script for image items'
script.details = ''
script.path = 'mytestplugin.utils.script1'
script.job_name = 'job_manager.job.job.PlainJob'
script.plugin = plugin
script.item_type = 'image'
script.save()
# create a new Event
event = Event()
event.name = 'ITEM_CREATED'
event.description = 'Must be used when a new Item is uploaded on the platform'
event.save()
def test_trigger_1(self):
"""
Trigger the execution of an Event
"""
user = User.objects.all()[0]
client = APIClient()
client.force_authenticate(user=user)
data = {
'func_params' : {},
'auth_params' : {}
}
response = client.post('/api/triggers/event/1/', data)
self.assertEqual(response.status_code, status.HTTP_200_OK)
def test_trigger_2(self):
"""
Trigger the execution of a Script
"""
user = User.objects.all()[0]
client = APIClient()
client.force_authenticate(user=user)
data = {
'func_params' : {},
'auth_params' : {}
}
response = client.post('/api/triggers/script/1/', data)
self.assertEqual(response.status_code, status.HTTP_200_OK)