chore: cleanup config override in infrastructure/tests.py
ci/woodpecker/push/woodpecker Pipeline failed Details

wip-infra-tests
Aravinth Manivannan 2022-06-27 04:37:56 +05:30
parent ca8ffba55e
commit 8997d0ff0f
Signed by: realaravinth
GPG Key ID: AD9F0F08E855ED88
2 changed files with 15 additions and 24 deletions

View File

@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from pathlib import Path
import shutil
from django.test import TestCase, Client, override_settings
from django.conf import settings
@ -24,6 +25,16 @@ from accounts.tests import register_util, login_util
from dash.tests import create_configurations, create_instance_util
def custom_config(test_name: str):
c = settings.HOSTEA
path = Path(f"/tmp/hostea/dashboard/{c}/repo")
if path.exists():
print(f"[!] {path} exists, deleting.")
shutil.rmtree(path)
c["INFRA"]["HOSTEA_REPO"]["PATH"] = str(path)
return c
class InfraUtilTest(TestCase):
"""
Tests billing system
@ -34,17 +45,7 @@ class InfraUtilTest(TestCase):
register_util(t=self, username=self.username)
create_configurations(t=self)
@override_settings(
HOSTEA={
"INFRA": {
"HOSTEA_REPO": {
"PATH": "/tmp/hostea/dashboard/test_path_util/repo/",
"REMOTE": "git@git.batsense.net:realaravinth/dummy-hostea-dash-test",
"SSH_KEY": "/src/atm/.ssh/aravinth",
},
}
}
)
@override_settings(HOSTEA=custom_config(test_name="test_path_util"))
def test_path_utils(self):
infra = Infra()
subdomain = "foo"
@ -75,17 +76,7 @@ class InfraUtilTest(TestCase):
infra._hostscript_path(subdomain=subdomain),
)
@override_settings(
HOSTEA={
"INFRA": {
"HOSTEA_REPO": {
"PATH": "/tmp/hostea/dashboard/test_add_vm/repo/",
"REMOTE": "git@git.batsense.net:realaravinth/dummy-hostea-dash-test",
"SSH_KEY": "/src/atm/.ssh/aravinth",
},
}
}
)
@override_settings(HOSTEA=custom_config(test_name="test_add_vm"))
def test_add_vm(self):
infra = Infra()
c = Client()
@ -101,4 +92,4 @@ class InfraUtilTest(TestCase):
instance = Instance.objects.get(name=subdomain)
woodpecker_agent_secret = infra.add_vm(instance=instance)
# infra.remove_vm(instance=instance)
infra.remove_vm(instance=instance)

View File

@ -36,7 +36,7 @@ class Infra:
if not self.repo_path.exists():
os.makedirs(self.repo_path)
self.ssh_cmd = f"ssh -i {conf['SSH_KEY']}"
self.ssh_cmd = f"/usr/bin/ssh -oStrictHostKeyChecking=no -i {conf['SSH_KEY']}"
try:
self.repo = Repo(path=self.repo_path)
except InvalidGitRepositoryError: