Ticket #6175: scriptrepositorytest.py

File scriptrepositorytest.py, 4.3 KB (added by Gesner Passos, 8 years ago)

Step by step test of script repository for the tester

Line 
1## Before testing make sure your Mantid.user.properties does not
2## have a wrong definition for these variables:
3##  - UploaderWebServer
4##  - ScriptLocalRepository
5##  - ScriptRepository
6
7#creation of the ScriptRepository instance
8from mantid.api import ScriptRepositoryFactory as srf
9repo = srf.Instance().create("ScriptRepositoryImpl")
10
11REPO_PATH = '/tmp/myrep/'
12
13#double check what is available inside ScriptRepository
14# I hope you can use the script repository with this example and the
15#information on help
16help(repo)
17
18
19
20# In order to test the ScriptRepository we must check its requirements.
21
22
23# Requirement 1 : Be able to install without network problems
24# Requirement 2: Create a Local folder that will be the local repository
25repo.install(REPO_PATH) 
26# TEST: check that a folder was created in REPO_PATH, and two files are there .local.json .repository.json (hidden files)
27
28# Requirement 3: List Files (remotelly and locally)
29list = repo.listFiles()
30print '\n'.join(list)
31#TEST: check that inside this list you find any file available at https://github.com/mantidproject/scripts.git
32#TEST: create a new file and folders inside the REPO_PATH, execute again repo.listFiles() and check
33# that these new files are listed as well.
34
35
36# Requirement 4: Ability to ignore some file patterns
37# By default we set to ignore pyc files, but the pattern is available at ScriptRepositoryIgnore inside the properties file.
38# You may override this property and check if it works well.
39#  So, create a file pyc inside the REPO_PATH, execute repo.listFiles() and make sure it does not appear in the list
40print  ('file.pyc' not in repo.listFiles() )  FAILED
41
42# Requirement 5: Download files or folders recursively
43repo.download('TofConv/TofConverter/Ui_MainWindow.py') 
44# TEST: check REPO_PATH/TofConv/TofConverter/Ui_MainWindow.py was created
45repo.download('other')
46#TEST: check REPO_PATH/other/PyMcp/guassfit.py was created
47
48# Requirement 6: Provide general information for files (Description, Author, Last Modified date, version id)
49print repo.fileInfo('TofConv/TofConverter/Ui_MainWindow.py')
50#TEST: check that it provides the description, last modified date, version id, author is not implemented yet
51
52# Requirement 7: Manage the versions of a file instance: up-to-date, locally modified, new version available, new version available and locally modified, local only.
53# Any file may have the following states:
54#   LOCAL_ONLY
55#   REMOTE_ONLY
56#   LOCAL_CHANGED
57#   REMOTE_CHANGED
58#   BOTH_UNCHANGED
59#   BOTH_CHANGED
60# NOTE: after changing a file locally, or remotely, it is necessary to execute listFiles again.
61repo.listFiles() 
62print repo.fileStatus('TofConv/TofConverter/Ui_MainWindow.py')
63#TEST: should be BOTH_UNCHANGED -  we have just downloaded
64print repo.fileStatus('TofConv/TofConverter/converter.ui')
65#TEST: should be REMOTE_ONLY
66#TEST: open TofConv/TofConverter/Ui_MainWindow.py, make some changes, close it, run listFiles, and than
67# run print repo.fileInfo('TofConv/TofConverter/Ui_MainWindow.py'), should return LOCAL_CHANGED
68#TEST: test if a file is LOCAL_ONLY,
69# TEST: update a file at the repository, (wait at least one minute - time for the mantidweb to update), run listFiles,
70#    check the status is REMOTE_CHANGED
71
72# Requirement 8: Allow files to be marked for automatically updates. (NOT IMPLEMENTED YET)
73
74# Requirement 9: Never override local changes. If the user decides to download a new version of a file he has changed, a backup of his own copy must be produced.
75# TEST: download one file repo.download('file')
76#            change it locally (open it, and edit it)
77#            change the same file remotelly (push your commit to the repository)
78#            go, take one coffee  (wait some minutes to mantidweb to recognize the change)
79#            run listFiles()
80#            check that the file is marked as BOTH_CHANGED repo.fileStatus('file')
81#            execute download file : repo.download('file')
82#            check that the file is inside your REPO_PATH and a backup file is created as well.
83#example:
84repo.download('README.md')
85f = open(REPO_PATH+ '/README.md','w')
86f.write("local change")
87f.close()
88import time
89time.sleep(1)
90repo.listFiles() 
91print repo.fileStatus('README.md') #MUST BE LOCAL_CHANGED
92#chage the file and upload, wait , and check4update
93repo.update()
94print repo.fileStatus('README.md') #Wait till BOTH_CHANGED
95repo.download('README.md')
96#check taht README.md_bck was created.