forked from Hostea/dashboard
78 lines
2.5 KiB
Python
78 lines
2.5 KiB
Python
# Create your tests here.
|
|
|
|
# Copyright © 2022 Aravinth Manivannan <realaravinth@batsense.net>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# 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/>.
|
|
import time
|
|
import os
|
|
from io import StringIO
|
|
from urllib.parse import urlparse, urlunparse
|
|
|
|
import requests
|
|
|
|
from django.core import mail
|
|
from django.contrib.auth import get_user_model
|
|
from django.core.management import call_command
|
|
from django.urls import reverse
|
|
from django.test import TestCase, Client, override_settings
|
|
from django.utils.http import urlencode
|
|
from django.contrib.auth import authenticate
|
|
from django.conf import settings
|
|
|
|
|
|
from accounts.tests import register_util
|
|
from dash.models import Instance
|
|
from infrastructure.models import InstanceCreated, InstanceConfiguration
|
|
|
|
|
|
class VMCommands(TestCase):
|
|
"""
|
|
Test command: manage.py create_oidc
|
|
"""
|
|
|
|
def setUp(self):
|
|
self.username = "hosteacustomer"
|
|
register_util(t=self, username=self.username)
|
|
self.vm_name = "MyHosteaVM"
|
|
|
|
def test_cmd(self):
|
|
|
|
Application = get_application_model()
|
|
|
|
stdout = StringIO()
|
|
stderr = StringIO()
|
|
|
|
redirect_uri = "http://example.org"
|
|
app_name = "test_cmd_oidc"
|
|
|
|
self.assertEqual(Instance.objects.filter(name=vm_name).exists(), False)
|
|
# username exists
|
|
call_command(
|
|
"vm", "create", self.vm_name, f"--owner={self.username}", "==flavor=medium"
|
|
)
|
|
out = stdout.getvalue()
|
|
|
|
self.assertIn(f"Instance created", out)
|
|
|
|
instance = Instance.objects.get(name=self.vm_name)
|
|
self.assertEqual(instance.owned_by, self.user)
|
|
self.assertEqual(
|
|
instance.configuration_id, InstanceConfiguration.objects.get(name="s1-4")
|
|
)
|
|
|
|
instance_created = InstanceCreated.objects.get(name=self.vm_name)
|
|
self.assertEqual(instance_created.instance, instance)
|
|
|
|
self.assertEqual(instance_created.created, True)
|