Blame view

src/routine_manager/tests.py 2.48 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):

ddf59dd4   haribo   Remaniement :
9
    fixtures = ["tests/routine_mgr_test.json"]
fd99569d   haribo   Date: 22/06/2016
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

    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"
984e74ea   haribo   Moving non-app di...
32
        with open(SAVED_REQUESTS_FOLDER + "request_unittest.xml") as file:
fd99569d   haribo   Date: 22/06/2016
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
            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...
52
        file_path = SAVED_REQUESTS_FOLDER + "request" + str(req.id) + ".xml"
fd99569d   haribo   Date: 22/06/2016
53
54
        self.assertTrue(os.path.isfile(file_path), "There should be a new file %s" % (file_path,))
        os.remove(file_path)