django-orchestra/orchestra/contrib/websites/tests/functional_tests/tests.py

145 lines
5.5 KiB
Python
Raw Normal View History

2014-10-10 14:39:46 +00:00
import os
import socket
import requests
2015-04-05 10:46:24 +00:00
from orchestra.contrib.domains.models import Domain, Record
2016-03-08 10:16:49 +00:00
from orchestra.contrib.domains.backends import Bind9MasterDomainController
2015-04-05 10:46:24 +00:00
from orchestra.contrib.orchestration.models import Server, Route
from orchestra.contrib.webapps.tests.functional_tests.tests import StaticWebAppMixin, RESTWebAppMixin, WebAppMixin, PHPFcidWebAppMixin, PHPFPMWebAppMixin
2015-04-04 18:10:39 +00:00
from orchestra.utils.tests import BaseLiveServerTestCase, random_ascii, save_response_on_error
2014-10-10 14:39:46 +00:00
2015-04-04 18:10:39 +00:00
from ... import backends
2014-10-10 14:39:46 +00:00
class WebsiteMixin(WebAppMixin):
MASTER_SERVER = os.environ.get('ORCHESTRA_MASTER_SERVER', 'localhost')
MASTER_SERVER_ADDR = socket.gethostbyname(MASTER_SERVER)
DEPENDENCIES = (
2015-04-05 10:46:24 +00:00
'orchestra.contrib.orchestration',
'orchestra.contrib.domains',
'orchestra.contrib.websites',
'orchestra.contrib.webapps',
'orchestra.contrib.systemusers',
2014-10-10 14:39:46 +00:00
)
def add_route(self):
super(WebsiteMixin, self).add_route()
server = Server.objects.get()
2016-03-08 10:16:49 +00:00
backend = backends.apache.Apache2Controller.get_name()
Route.objects.get_or_create(backend=backend, match=True, host=server)
2016-03-08 10:16:49 +00:00
backend = Bind9MasterDomainController.get_name()
Route.objects.get_or_create(backend=backend, match=True, host=server)
2014-10-10 14:39:46 +00:00
def validate_add_website(self, name, domain):
url = 'http://%s/%s' % (domain.name, self.page[0])
self.assertEqual(self.page[2], requests.get(url).content)
def test_add(self):
# TODO domains with "_" bad name!
domain_name = '%sdomain.lan' % random_ascii(10)
domain = Domain.objects.create(name=domain_name, account=self.account)
domain.records.create(type=Record.A, value=self.MASTER_SERVER_ADDR)
self.save_domain(domain)
webapp = '%s_%s_webapp' % (random_ascii(10), self.type_value)
self.add_webapp(webapp)
self.addCleanup(self.delete_webapp, webapp)
self.upload_webapp(webapp)
2014-10-10 14:39:46 +00:00
website = '%s_website' % random_ascii(10)
self.add_website(website, domain, webapp)
self.addCleanup(self.delete_website, website)
2014-10-10 14:39:46 +00:00
self.validate_add_website(website, domain)
class RESTWebsiteMixin(RESTWebAppMixin):
@save_response_on_error
def save_domain(self, domain):
self.rest.domains.retrieve().get().save()
@save_response_on_error
def add_website(self, name, domain, webapp, path='/'):
domain = self.rest.domains.retrieve(name=domain).get()
webapp = self.rest.webapps.retrieve(name=webapp).get()
contents = [{
'webapp': webapp,
'path': path
}]
self.rest.websites.create(name=name, domains=[domain], contents=contents)
@save_response_on_error
def delete_website(self, name):
self.rest.websites.retrieve(name=name).delete()
@save_response_on_error
def add_content(self, website, webapp, path):
website = self.rest.websites.retrieve(name=website).get()
webapp = self.rest.webapps.retrieve(name=webapp).get()
website.contents.append({
'webapp': webapp,
'path': path,
})
website.save()
2014-10-15 12:47:28 +00:00
# TODO test disable
# TODO test https (refactor ssl)
# TODO test php options
# TODO read php-version /fpm/fcgid
# TODO max_processes, timeouts, memory...
class StaticRESTWebsiteTest(RESTWebsiteMixin, StaticWebAppMixin, WebsiteMixin, BaseLiveServerTestCase):
def test_mix_webapps(self):
domain_name = '%sdomain.lan' % random_ascii(10)
domain = Domain.objects.create(name=domain_name, account=self.account)
domain.records.create(type=Record.A, value=self.MASTER_SERVER_ADDR)
self.save_domain(domain)
webapp = '%s_%s_webapp' % (random_ascii(10), self.type_value)
self.add_webapp(webapp)
self.addCleanup(self.delete_webapp, webapp)
self.upload_webapp(webapp)
website = '%s_website' % random_ascii(10)
self.add_website(website, domain, webapp)
self.addCleanup(self.delete_website, website)
self.validate_add_website(website, domain)
self.type_value = PHPFcidWebAppMixin.type_value
self.backend = PHPFcidWebAppMixin.backend
self.page = PHPFcidWebAppMixin.page
self.add_route()
webapp = '%s_%s_webapp' % (random_ascii(10), self.type_value)
self.add_webapp(webapp)
self.addCleanup(self.delete_webapp, webapp)
self.upload_webapp(webapp)
path = '/%s' % webapp
self.add_content(website, webapp, path)
url = 'http://%s%s/%s' % (domain.name, path, self.page[0])
self.assertEqual(self.page[2], requests.get(url).content)
self.type_value = PHPFPMWebAppMixin.type_value
self.backend = PHPFPMWebAppMixin.backend
self.page = PHPFPMWebAppMixin.page
self.add_route()
webapp = '%s_%s_webapp' % (random_ascii(10), self.type_value)
self.add_webapp(webapp)
self.addCleanup(self.delete_webapp, webapp)
self.upload_webapp(webapp)
path = '/%s' % webapp
self.add_content(website, webapp, path)
url = 'http://%s%s/%s' % (domain.name, path, self.page[0])
self.assertEqual(self.page[2], requests.get(url).content)
2014-10-10 14:39:46 +00:00
class PHPFcidRESTWebsiteTest(RESTWebsiteMixin, PHPFcidWebAppMixin, WebsiteMixin, BaseLiveServerTestCase):
2014-10-10 17:17:20 +00:00
pass
2014-10-10 14:39:46 +00:00
class PHPFPMRESTWebsiteTest(RESTWebsiteMixin, PHPFPMWebAppMixin, WebsiteMixin, BaseLiveServerTestCase):
2014-10-10 14:39:46 +00:00
pass
#class AdminWebsiteTest(AdminWebsiteMixin, BaseLiveServerTestCase):
# pass