From 70a0becc1f43b16494ae3af53163aaa2120186d3 Mon Sep 17 00:00:00 2001
From: Anne Philipp <anne.philipp@univie.ac.at>
Date: Fri, 31 Aug 2018 19:08:15 +0200
Subject: [PATCH] added test for put_file_to_ecserver and corrected a potential
 bug; test is not perfect since it needs user password. TODO: CHANGE

---
 python/pythontest/TestTools.py | 16 +++++++++++-----
 python/tools.py                |  2 +-
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/python/pythontest/TestTools.py b/python/pythontest/TestTools.py
index 2f3ff7e..7a3fc77 100644
--- a/python/pythontest/TestTools.py
+++ b/python/pythontest/TestTools.py
@@ -4,12 +4,15 @@
 import os
 import sys
 #import unittest
+import subprocess
+import pipes
 import pytest
 
 sys.path.append('../')
 import _config
 from tools import (init128, to_param_id, my_error, read_ecenv,
-                   get_cmdline_arguments, submit_job_to_ecserver)
+                   get_cmdline_arguments, submit_job_to_ecserver,
+                   put_file_to_ecserver)
 
 
 class TestTools():
@@ -114,9 +117,13 @@ class TestTools():
     def test_make_dir(self):
         assert True
 
-    def test_put_file_to_ecserver(self):
-        assert True
-        #assert subprocess.call(['ssh', host, 'test -e ' + pipes.quote(path)]) == 0
+    def test_success_put_file_to_ecserver(self):
+        ecuid=os.environ['ECUID']#'km4a'
+        ecgid=os.environ['ECGID']#'at'
+        put_file_to_ecserver('TestData/', 'testfile.txt', 'ecgate', ecuid, ecgid)
+        assert subprocess.call(['ssh', 'km4a@ecaccess.ecmwf.int' ,
+                                'test -e ' +
+                                pipes.quote('/home/ms/'+ecgid+'/'+ecuid)]) == 0
 
     def test_fail_submit_job_to_ecserver(self):
         with pytest.raises(SystemExit) as pytest_wrapped_e:
@@ -125,7 +132,6 @@ class TestTools():
         assert pytest_wrapped_e.value.code == '... ECACCESS-JOB-SUBMIT FAILED!'
 
     def test_success_submit_job_to_ecserver(self):
-
         result = submit_job_to_ecserver('ecgate', 'TestData/testfile.txt')
         assert result == 0
 
diff --git a/python/tools.py b/python/tools.py
index 25529e7..b41036b 100644
--- a/python/tools.py
+++ b/python/tools.py
@@ -470,7 +470,7 @@ def put_file_to_ecserver(ecd, filename, target, ecuid, ecgid):
 
     try:
         subprocess.check_call(['ecaccess-file-put',
-                               ecd + '../' + filename,
+                               ecd + '/' + filename,
                                target + ':/home/ms/' +
                                ecgid + '/' + ecuid +
                                '/' + filename])
-- 
GitLab