Refactor PHP tests dropping legacy controller (backend)

This commit is contained in:
Santiago L 2021-03-30 13:35:00 +02:00
parent 58395147c9
commit 14fbd98e33
2 changed files with 23 additions and 36 deletions

View File

@ -63,9 +63,9 @@ class StaticWebAppMixin(object):
) )
class PHPFcidWebAppMixin(StaticWebAppMixin): class PHPFPMWebAppMixin(StaticWebAppMixin):
backend = backends.phpfcgid.PHPFcgidBackend backend = backends.php.PHPController
type_value = 'php5.2' type_value = 'php5.5'
token = random_ascii(100) token = random_ascii(100)
page = ( page = (
'index.php', 'index.php',
@ -74,11 +74,6 @@ class PHPFcidWebAppMixin(StaticWebAppMixin):
) )
class PHPFPMWebAppMixin(PHPFcidWebAppMixin):
backend = backends.phpfpm.PHPFPMBackend
type_value = 'php5.5'
class RESTWebAppMixin(object): class RESTWebAppMixin(object):
def setUp(self): def setUp(self):
super(RESTWebAppMixin, self).setUp() super(RESTWebAppMixin, self).setUp()
@ -120,10 +115,6 @@ class StaticRESTWebAppTest(StaticWebAppMixin, RESTWebAppMixin, WebAppMixin, Base
pass pass
class PHPFcidRESTWebAppTest(PHPFcidWebAppMixin, RESTWebAppMixin, WebAppMixin, BaseLiveServerTestCase):
pass
class PHPFPMRESTWebAppTest(PHPFPMWebAppMixin, RESTWebAppMixin, WebAppMixin, BaseLiveServerTestCase): class PHPFPMRESTWebAppTest(PHPFPMWebAppMixin, RESTWebAppMixin, WebAppMixin, BaseLiveServerTestCase):
pass pass

View File

@ -6,7 +6,7 @@ import requests
from orchestra.contrib.domains.models import Domain, Record from orchestra.contrib.domains.models import Domain, Record
from orchestra.contrib.domains.backends import Bind9MasterDomainController from orchestra.contrib.domains.backends import Bind9MasterDomainController
from orchestra.contrib.orchestration.models import Server, Route from orchestra.contrib.orchestration.models import Server, Route
from orchestra.contrib.webapps.tests.functional_tests.tests import StaticWebAppMixin, RESTWebAppMixin, WebAppMixin, PHPFcidWebAppMixin, PHPFPMWebAppMixin from orchestra.contrib.webapps.tests.functional_tests.tests import StaticWebAppMixin, RESTWebAppMixin, WebAppMixin, PHPFPMWebAppMixin
from orchestra.utils.tests import BaseLiveServerTestCase, random_ascii, save_response_on_error from orchestra.utils.tests import BaseLiveServerTestCase, random_ascii, save_response_on_error
from ... import backends from ... import backends
@ -22,7 +22,7 @@ class WebsiteMixin(WebAppMixin):
'orchestra.contrib.webapps', 'orchestra.contrib.webapps',
'orchestra.contrib.systemusers', 'orchestra.contrib.systemusers',
) )
def add_route(self): def add_route(self):
super(WebsiteMixin, self).add_route() super(WebsiteMixin, self).add_route()
server = Server.objects.get() server = Server.objects.get()
@ -30,11 +30,11 @@ class WebsiteMixin(WebAppMixin):
Route.objects.get_or_create(backend=backend, match=True, host=server) Route.objects.get_or_create(backend=backend, match=True, host=server)
backend = Bind9MasterDomainController.get_name() backend = Bind9MasterDomainController.get_name()
Route.objects.get_or_create(backend=backend, match=True, host=server) Route.objects.get_or_create(backend=backend, match=True, host=server)
def validate_add_website(self, name, domain): def validate_add_website(self, name, domain):
url = 'http://%s/%s' % (domain.name, self.page[0]) url = 'http://%s/%s' % (domain.name, self.page[0])
self.assertEqual(self.page[2], requests.get(url).content) self.assertEqual(self.page[2], requests.get(url).content)
def test_add(self): def test_add(self):
# TODO domains with "_" bad name! # TODO domains with "_" bad name!
domain_name = '%sdomain.lan' % random_ascii(10) domain_name = '%sdomain.lan' % random_ascii(10)
@ -55,7 +55,7 @@ class RESTWebsiteMixin(RESTWebAppMixin):
@save_response_on_error @save_response_on_error
def save_domain(self, domain): def save_domain(self, domain):
self.rest.domains.retrieve().get().save() self.rest.domains.retrieve().get().save()
@save_response_on_error @save_response_on_error
def add_website(self, name, domain, webapp, path='/'): def add_website(self, name, domain, webapp, path='/'):
domain = self.rest.domains.retrieve(name=domain).get() domain = self.rest.domains.retrieve(name=domain).get()
@ -65,11 +65,11 @@ class RESTWebsiteMixin(RESTWebAppMixin):
'path': path 'path': path
}] }]
self.rest.websites.create(name=name, domains=[domain], contents=contents) self.rest.websites.create(name=name, domains=[domain], contents=contents)
@save_response_on_error @save_response_on_error
def delete_website(self, name): def delete_website(self, name):
self.rest.websites.retrieve(name=name).delete() self.rest.websites.retrieve(name=name).delete()
@save_response_on_error @save_response_on_error
def add_content(self, website, webapp, path): def add_content(self, website, webapp, path):
website = self.rest.websites.retrieve(name=website).get() website = self.rest.websites.retrieve(name=website).get()
@ -101,20 +101,7 @@ class StaticRESTWebsiteTest(RESTWebsiteMixin, StaticWebAppMixin, WebsiteMixin, B
self.add_website(website, domain, webapp) self.add_website(website, domain, webapp)
self.addCleanup(self.delete_website, website) self.addCleanup(self.delete_website, website)
self.validate_add_website(website, domain) 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.type_value = PHPFPMWebAppMixin.type_value
self.backend = PHPFPMWebAppMixin.backend self.backend = PHPFPMWebAppMixin.backend
self.page = PHPFPMWebAppMixin.page self.page = PHPFPMWebAppMixin.page
@ -124,14 +111,23 @@ class StaticRESTWebsiteTest(RESTWebsiteMixin, StaticWebAppMixin, WebsiteMixin, B
self.addCleanup(self.delete_webapp, webapp) self.addCleanup(self.delete_webapp, webapp)
self.upload_webapp(webapp) self.upload_webapp(webapp)
path = '/%s' % webapp path = '/%s' % webapp
self.add_content(website, webapp, path) self.add_content(website, webapp, path)
url = 'http://%s%s/%s' % (domain.name, path, self.page[0]) url = 'http://%s%s/%s' % (domain.name, path, self.page[0])
self.assertEqual(self.page[2], requests.get(url).content) 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
class PHPFcidRESTWebsiteTest(RESTWebsiteMixin, PHPFcidWebAppMixin, WebsiteMixin, BaseLiveServerTestCase): self.add_content(website, webapp, path)
pass url = 'http://%s%s/%s' % (domain.name, path, self.page[0])
self.assertEqual(self.page[2], requests.get(url).content)
class PHPFPMRESTWebsiteTest(RESTWebsiteMixin, PHPFPMWebAppMixin, WebsiteMixin, BaseLiveServerTestCase): class PHPFPMRESTWebsiteTest(RESTWebsiteMixin, PHPFPMWebAppMixin, WebsiteMixin, BaseLiveServerTestCase):