Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

# coding: utf-8 

 

""" 

PyLucid 

~~~~~~~ 

 

:copyleft: 2015-2018 by the PyLucid team, see AUTHORS for more details. 

:created: 2015 by JensDiemer.de 

:license: GNU GPL v3 or above, see LICENSE for more details. 

""" 

 

import os 

import sys 

from pathlib import Path 

from unittest import TestCase 

 

from django.utils.version import get_main_version 

 

from pylucid_installer.pylucid_installer import create_instance, get_python3_shebang 

from pylucid.tests.test_utils.test_cases import BaseTestCase, PageInstanceTestCase 

 

# https://github.com/jedie/django-tools 

from django_tools.unittest_utils.isolated_filesystem import isolated_filesystem 

from django_tools.unittest_utils.stdout_redirect import StdoutStderrBuffer 

from django_tools.unittest_utils.unittest_base import BaseUnittestCase 

 

# PyLucid 

from pylucid.pylucid_boot import VerboseSubprocess 

 

 

@isolated_filesystem() 

class PyLucidInstallerTest(BaseUnittestCase): 

def setUp(self): 

super().setUp() 

self.temp_path = Path().cwd() # isolated_filesystem does made a chdir to /tmp/... 

 

def test_create(self): 

destination = Path(self.temp_path, self._testMethodName) 

self.assertFalse(destination.is_dir()) 

 

output = VerboseSubprocess( 

"pylucid_admin", "create_page_instance", str(destination), self._testMethodName 

).verbose_output(check=False) 

 

print(output) 

 

self.assertIn( 

"Page instance created here: '%s'" % destination, 

output 

) 

self.assertEqual( 

set([p.name for p in destination.iterdir()]), 

{'manage.py', 'media', 'static', self._testMethodName} 

) 

 

# Check patched manage.py 

with Path(destination, "manage.py").open("r") as f: 

shebang = f.readlines(1)[0] 

 

self.assertEqual(shebang, "%s\n" % get_python3_shebang()) 

 

content = f.read() 

print(content) 

self.assertIn( 

'os.environ.setdefault("DJANGO_SETTINGS_MODULE", "%s.settings")' % self._testMethodName, 

content 

) 

 

# Check patched settings.py 

with Path(destination, self._testMethodName, "settings.py").open("r") as f: 

content = f.read() 

print(content) 

self.assertIn( 

'DOC_ROOT = "%s"' % destination, 

content 

) 

self.assertIn( 

'ROOT_URLCONF = "%s.urls"' % self._testMethodName, 

content 

) 

 

 

class ManageTest(PageInstanceTestCase): 

# def test_debug_settings(self): 

# with open(os.path.join(self.project_path, "settings.py"), "r") as f: 

# content = f.read() 

# print(content) 

 

def test_help(self): 

output = self.call_manage_py("--help") 

# print(output) 

 

self.assertIn("Type 'manage.py help <subcommand>' for help on a specific subcommand.", output) 

 

def test_check(self): 

output = self.call_manage_py("check") 

self.assertNotIn("ImproperlyConfigured", output) 

 

def test_diffsettings(self): 

# self.dont_cleanup_temp=True 

 

output = self.call_manage_py("diffsettings") 

print(output) 

self.assertNotIn("ImproperlyConfigured", output) 

# self.assertIn( 

# "DOC_ROOT = '%s'" % self.project_path, 

# output 

# ) 

self.assertIn( 

"STATIC_ROOT = '%s'" % Path(self.instance_root, "static"), 

output 

) 

self.assertIn( 

"MEDIA_ROOT = '%s'" % Path(self.instance_root, "media"), 

output 

) 

 

def test_migrate(self): 

output = self.call_manage_py("migrate", "--noinput") 

print(output) 

self.assertIn("Running migrations:", output) 

self.assertIn("Applying auth.", output) 

self.assertIn("Applying cms.", output) 

self.assertIn("Applying djangocms_blog.", output)