Blame view

src/routine_manager/tests.py 2.52 KB
3df2d31a   haribo   #3430 : dates are...
1
from django.test import TestCase
ddf59dd4   haribo   Remaniement :
2
from common.models import *
fd99569d   haribo   Date: 22/06/2016
3
import os
3df2d31a   haribo   #3430 : dates are...
4

984e74ea   haribo   Moving non-app di...
5
6
SAVED_REQUESTS_FOLDER = "misc/saved_requests/"

fd99569d   haribo   Date: 22/06/2016
7
8
class TestRoutineManager(TestCase):

f49b7078   Etienne Pallier   Bugfix tests and ...
9
10
    fixtures = ['tests/routine_mgr_test.json']

fd99569d   haribo   Date: 22/06/2016
11
12

    def setUp(self):
f49b7078   Etienne Pallier   Bugfix tests and ...
13
        #print("Routine Manager test")
fd99569d   haribo   Date: 22/06/2016
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
        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"
984e74ea   haribo   Moving non-app di...
34
        with open(SAVED_REQUESTS_FOLDER + "request_unittest.xml") as file:
fd99569d   haribo   Date: 22/06/2016
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
            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)
984e74ea   haribo   Moving non-app di...
54
        file_path = SAVED_REQUESTS_FOLDER + "request" + str(req.id) + ".xml"
fd99569d   haribo   Date: 22/06/2016
55
56
        self.assertTrue(os.path.isfile(file_path), "There should be a new file %s" % (file_path,))
        os.remove(file_path)