Updated SaveSSHKeyTestCase to include add/remove ssh keys

This commit is contained in:
M.Ravi 2017-09-14 15:05:28 +02:00
parent bd45577c90
commit a4fe2e2db9
2 changed files with 36 additions and 4 deletions

View file

@ -585,6 +585,9 @@ if ENABLE_DEBUG_LOGGING:
}, },
} }
TEST_MANAGE_SSH_KEY_PUBKEY = env('TEST_MANAGE_SSH_KEY_PUBKEY')
TEST_MANAGE_SSH_KEY_HOST = env('TEST_MANAGE_SSH_KEY_HOST')
DEBUG = bool_env('DEBUG') DEBUG = bool_env('DEBUG')
if DEBUG: if DEBUG:

View file

@ -8,6 +8,7 @@ from django.conf import settings
from django.http.request import HttpRequest from django.http.request import HttpRequest
from django.test import Client from django.test import Client
from django.test import TestCase, override_settings from django.test import TestCase, override_settings
from unittest import skipIf
from model_mommy import mommy from model_mommy import mommy
from datacenterlight.models import StripePlan from datacenterlight.models import StripePlan
@ -250,11 +251,39 @@ class SaveSSHKeyTestCase(TestCase):
task_always_eager=True, task_always_eager=True,
) )
def setUp(self): def setUp(self):
self.public_key = ["This is a test", ] self.public_key = settings.TEST_MANAGE_SSH_KEY_PUBKEY
self.hosts = ['localhost'] self.hosts = settings.TEST_MANAGE_SSH_KEY_HOST
def test_save_ssh_key(self): @skipIf(settings.TEST_MANAGE_SSH_KEY_PUBKEY is None or
async_task = save_ssh_key.delay(self.hosts, self.public_key) settings.TEST_MANAGE_SSH_KEY_PUBKEY == "" or
settings.TEST_MANAGE_SSH_KEY_HOST is None or
settings.TEST_MANAGE_SSH_KEY_HOST is "",
"""Skipping test_save_ssh_key_add because either host
or public key were not specified or were empty""")
def test_save_ssh_key_add(self):
async_task = save_ssh_key.delay([self.hosts],
[{'value': self.public_key,
'state': True}])
save_ssh_key_result = None
for i in range(0, 10):
sleep(5)
res = AsyncResult(async_task.task_id)
if type(res.result) is bool:
save_ssh_key_result = res.result
break
self.assertIsNotNone(save_ssh_key, "save_ssh_key_result is None")
self.assertTrue(save_ssh_key_result, "save_ssh_key_result is False")
@skipIf(settings.TEST_MANAGE_SSH_KEY_PUBKEY is None or
settings.TEST_MANAGE_SSH_KEY_PUBKEY == "" or
settings.TEST_MANAGE_SSH_KEY_HOST is None or
settings.TEST_MANAGE_SSH_KEY_HOST is "",
"""Skipping test_save_ssh_key_add because either host
or public key were not specified or were empty""")
def test_save_ssh_key_remove(self):
async_task = save_ssh_key.delay([self.hosts],
[{'value': self.public_key,
'state': False}])
save_ssh_key_result = None save_ssh_key_result = None
for i in range(0, 10): for i in range(0, 10):
sleep(5) sleep(5)