tests.py
2.48 KB
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
from django.test import TestCase
from common.models import *
import os
SAVED_REQUESTS_FOLDER = "misc/saved_requests/"
class TestRoutineManager(TestCase):
fixtures = ["tests/routine_mgr_test.json"]
def setUp(self):
pass
def test_import_fake_file(self):
self.client.login(username="test@test.test", password="test")
path = "/routine_manager/import_request"
response = self.client.post(path, {"request_file": "toto.xml"}, follow=True)
self.assertTrue("error" in response.context.keys(), "There should be an error of non existant file")
self.assertEqual(Request.objects.count(), 1, "There should still be only one request")
def test_import_invalid_file(self):
self.client.login(username="test@test.test", password="test")
path = "/routine_manager/import_request"
with open("manage.py") as file:
response = self.client.post(path, {"request_file": file}, follow=True)
self.assertTrue("error" in response.context.keys(), "There should be an error of invalid file")
self.assertEqual(Request.objects.count(), 1, "There should still be only one request")
def test_import(self):
self.client.login(username="test@test.test", password="test")
path = "/routine_manager/import_request"
with open(SAVED_REQUESTS_FOLDER + "request_unittest.xml") as file:
response = self.client.post(path, {"request_file": file}, follow=True)
self.assertTrue("success" in response.context.keys(), "There should be a success message")
self.assertEqual(Request.objects.count(), 2, "There should still be two request")
def test_export_incomplete(self):
req = Request.objects.get()
req.complete = False
req.save()
self.client.login(username="test@test.test", password="test")
path = "/routine_manager/export_request/" + str(req.id)
response = self.client.get(path, follow=True)
self.assertTrue("error" in response.context.keys(), "There should be an error of incomplete request")
def test_export(self):
req = Request.objects.get()
self.client.login(username="test@test.test", password="test")
path = "/routine_manager/export_request/" + str(req.id)
response = self.client.get(path, follow=True)
file_path = SAVED_REQUESTS_FOLDER + "request" + str(req.id) + ".xml"
self.assertTrue(os.path.isfile(file_path), "There should be a new file %s" % (file_path,))
os.remove(file_path)