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

############################################################################### 

# (c) Copyright 2016 CERN # 

# # 

# This software is distributed under the terms of the GNU General Public # 

# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". # 

# # 

# In applying this licence, CERN does not waive the privileges and immunities # 

# granted to it by virtue of its status as an Intergovernmental Organization # 

# or submit itself to any jurisdiction. # 

############################################################################### 

''' 

Test of the version path manager functionality in the model classes. 

 

@author: Stefan-Gabriel CHITIC 

''' 

 

import json 

import logging 

import shutil 

import subprocess 

import unittest 

 

import os 

 

from lbCVMFSTools.TaskHandlers.GitMirrorTask.GitMirrorTask \ 

import GitMirrorTask 

 

from lbCVMFSTools.tests.MockLogger import MockLoggingHandler 

 

 

class TestGitMirror(unittest.TestCase): 

 

def setUp(self): 

self.handler = MockLoggingHandler() 

logging.getLogger().addHandler(self.handler) 

if os.path.exists("/tmp/toto"): 

shutil.rmtree("/tmp/toto") 

if os.path.exists("/tmp/foo"): 

shutil.rmtree("/tmp/foo/") 

os.mkdir("/tmp/toto/") 

os.mkdir("/tmp/toto/cvmfstest.cern.ch/") 

os.mkdir("/tmp/toto/cvmfstest.cern.ch/test1.git/") 

os.mkdir("/tmp/toto/cvmfstest.cern.ch/test2.git/") 

os.mkdir("/tmp/toto/cvmfstest.cern.ch/test3.git/") 

with open( 

"/tmp/toto/cvmfstest.cern.ch/test1.git/FETCH_HEAD", 

'w') as f: 

f.write("1234\n") 

with open( 

"/tmp/toto/cvmfstest.cern.ch/test2.git/FETCH_HEAD", 

'w') as f: 

f.write("1234\n") 

with open( 

"/tmp/toto/cvmfstest.cern.ch/test3.git/FETCH_HEAD", 

'w') as f: 

f.write("1234\n") 

self.GitMirrorTaskI = GitMirrorTask( 

repodir='/tmp/toto/cvmfstest.cern.ch/') 

self.args = None 

self.kwargs = None 

self.mocked_return_code = 0 

subprocess.call = self.mocked_call 

 

def tearDown(self): 

if os.path.exists("/tmp/toto"): 

shutil.rmtree("/tmp/toto") 

 

def mocked_call(self, *a, **kw): 

self.args = a 

self.kwargs = kw 

return self.mocked_return_code 

 

def test_md5(self): 

md5 = self.GitMirrorTaskI._md5( 

'/tmp/toto/cvmfstest.cern.ch/test3.git/FETCH_HEAD') 

self.assertEqual('e7df7cd2ca07f4f1ab415d457a6e1c13', md5) 

 

def test_get_list_of_tasks(self): 

# Test with all slots not install 

todos = self.GitMirrorTaskI.get_list_of_tasks() 

parsed_slots = [[ 

{'md5': 'e7df7cd2ca07f4f1ab415d457a6e1c13', 

'path': '/tmp/toto/cvmfstest.cern.ch/test1.git'}, 

{'md5': 'e7df7cd2ca07f4f1ab415d457a6e1c13', 

'path': '/tmp/toto/cvmfstest.cern.ch/test2.git'}, 

{'md5': 'e7df7cd2ca07f4f1ab415d457a6e1c13', 

'path': '/tmp/toto/cvmfstest.cern.ch/test3.git'} 

]] 

self.assertEqual(todos, parsed_slots) 

 

def test_task_no_update(self): 

# Test with all slots not install 

todos = self.GitMirrorTaskI.get_list_of_tasks() 

try: 

self.GitMirrorTaskI.perform_task(todos[0]) 

self.fail("Should returned with transaction abort") 

except Exception as e: 

pass 

 

def test_task_update(self): 

todos = self.GitMirrorTaskI.get_list_of_tasks() 

with open( 

"/tmp/toto/cvmfstest.cern.ch/test3.git/FETCH_HEAD", 

'w') as f: 

f.write("1244434\n") 

try: 

self.GitMirrorTaskI.perform_task(todos[0]) 

except Exception as e: 

self.fail("Should publish the transaction %s " % str(e)) 

 

if __name__ == "__main__": 

unittest.main()