From 19a3b217a59d719e2215b19e27bc7c10e20c53ab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Mon, 1 Mar 2021 05:04:54 +0100
Subject: [PATCH] software/repman: extend a bit test coverage

test we can actually log in to repman and that hte monitoring API report
a cluster as up
---
 software/repman/test/setup.py |  3 --
 software/repman/test/test.py  | 57 ++++++++++++++++++++++++-----------
 2 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/software/repman/test/setup.py b/software/repman/test/setup.py
index 1dc3cd3e6..5c558972e 100644
--- a/software/repman/test/setup.py
+++ b/software/repman/test/setup.py
@@ -43,9 +43,6 @@ setup(
     install_requires=[
         'slapos.core',
         'slapos.libnetworkcache',
-        'erp5.util',
-        'supervisor',
-        'pexpect',
         'requests',
     ],
     zip_safe=True,
diff --git a/software/repman/test/test.py b/software/repman/test/test.py
index d2fe0a4fe..d723a6472 100644
--- a/software/repman/test/test.py
+++ b/software/repman/test/test.py
@@ -24,16 +24,10 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #
 ##############################################################################
-from __future__ import unicode_literals
 
 import os
-import textwrap
-import logging
-import tempfile
-import time
-from six.moves.urllib.parse import urlparse, urljoin
+from six.moves.urllib.parse import urljoin
 
-import pexpect
 import requests
 
 from slapos.testing.testcase import makeModuleSetUpAndTestCaseClass
@@ -44,17 +38,46 @@ setUpModule, SlapOSInstanceTestCase = makeModuleSetUpAndTestCaseClass(
 
 
 class TestRepman(SlapOSInstanceTestCase):
-  __partition_reference__ = 'R'  # solve path too long for postgresql and unicorn
-
-  @classmethod
-  def getInstanceSoftwareType(cls):
-    return 'default'
+  __partition_reference__ = 'R'
 
   def setUp(self):
-    self.backend_url = self.computer_partition.getConnectionParameterDict(
-    )['backend-url']
+    self.url = self.computer_partition.getConnectionParameterDict()['url']
 
   def test_http_get(self):
-    resp = requests.get(self.backend_url, verify=False)
-    self.assertTrue(
-      resp.status_code in [requests.codes.ok, requests.codes.found])
+    connection_parameter_dict = \
+        self.computer_partition.getConnectionParameterDict()
+    resp = requests.get(self.url, verify=False)
+    self.assertEqual(resp.status_code, requests.codes.ok)
+
+    resp = requests.post(
+        urljoin(self.url, '/api/login'),
+        json={
+            'username': connection_parameter_dict['username'],
+            'password': connection_parameter_dict['repman-password'],
+        },
+        verify=False,
+    )
+    self.assertEqual(resp.status_code, requests.codes.ok)
+
+    token = resp.json()['token']
+    headers = {"authorization": "Bearer " + token}
+    resp = requests.get(
+        urljoin(self.url, '/api/monitor'),
+        headers=headers,
+        verify=False,
+    )
+    self.assertEqual(resp.status_code, requests.codes.ok)
+
+    resp = requests.get(
+        urljoin(self.url, '/api/clusters'),
+        params={
+            'query': '{"method":"GET","isArray":false}',
+        },
+        headers=headers,
+        verify=False,
+    )
+    self.assertEqual(resp.status_code, requests.codes.ok)
+    cluster, = resp.json()
+    self.assertTrue(cluster['isProvision'])
+    self.assertTrue(cluster['isFailable'])
+    self.assertFalse(cluster['isDown'])
-- 
2.30.9