From 448ac21880e7cf838a19121e641ee875c8d2a801 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Mar 16 2016 20:57:52 +0000 Subject: event: convert some page attributes to properties doing these in __init__ meant that instantiating an event required two remote trips, which is slow and awkward for unit testing. Make them into properties instead. --- diff --git a/wikitcms/event.py b/wikitcms/event.py index f047049..29db0ef 100644 --- a/wikitcms/event.py +++ b/wikitcms/event.py @@ -58,8 +58,6 @@ class ValidationEvent(object): self.compose = str(compose) self.version = "{0} {1} {2}".format( self.release, self.milestone, self.compose) - self.parent_category_page = listing.ValidationCategory(site, release) - self.download_page = page.DownloadPage(self.site, self) # Sorting helpers. sortname is a string, sorttuple is a # 4-tuple. sorttuple is more reliable. See the function docs. self.sortname = helpers.fedora_release_sort(self.version) @@ -80,6 +78,13 @@ class ValidationEvent(object): """ pass + @abc.abstractproperty + def category_page(self): + """The category page for this event. Is a property because + page instantiation requires a remote trip. + """ + pass + @property def result_pages(self): """A list of wikitcms page objects for currently-existing @@ -91,6 +96,20 @@ class ValidationEvent(object): return [p for p in pages if isinstance(p, page.ValidationPage)] @property + def download_page(self): + """The DownloadPage for this event. Is a property because page + instantiation requires a remote trip. + """ + return page.DownloadPage(self.site, self) + + @property + def parent_category_page(self): + """The parent category page for this event. Is a property for + the same reason as download_page. + """ + return listing.ValidationCategory(self.site, self.release) + + @property def valid_pages(self): """A list of the expected possible result pages (as page.ValidationPage objects) for this test event, derived from @@ -223,8 +242,14 @@ class ComposeEvent(ValidationEvent): super(ComposeEvent, self).__init__( site, release, milestone=milestone, compose=compose) self.shortver = "{0} {1}".format(self.milestone, self.compose) - self.category_page = listing.ValidationCategory( - site, self.release, self.milestone) + + @property + def category_page(self): + """The category page for this event. Is a property because + page instantiation requires a remote trip. + """ + return listing.ValidationCategory( + self.site, self.release, self.milestone) @property def _current_content(self): @@ -272,11 +297,17 @@ class NightlyEvent(ValidationEvent): super(NightlyEvent, self).__init__( site, release, milestone=milestone, compose=compose) self.shortver = self.compose - self.category_page = listing.ValidationCategory( - site, self.release, nightly=True) self.creation_date = compose.split('.')[0] @property + def category_page(self): + """The category page for this event. Is a property because + page instantiation requires a remote trip. + """ + return listing.ValidationCategory( + self.site, self.release, nightly=True) + + @property def _current_content(self): """The content for the CurrentFedoraCompose template for this test event.