Basic removal of duplicate code through using a base class

This commit is contained in:
James Kasten
2015-09-15 17:58:31 -07:00
parent c170a7a16b
commit 0b8009529b
3 changed files with 32 additions and 50 deletions
+1 -1
View File
@@ -38,7 +38,7 @@ load-plugins=linter_plugin
# --enable=similarities". If you want to run only the classes checker, but have # --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes # no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W" # --disable=W"
disable=fixme,locally-disabled,abstract-class-not-used,duplicate-code disable=fixme,locally-disabled,abstract-class-not-used
# abstract-class-not-used cannot be disabled locally (at least in pylint 1.4.1) # abstract-class-not-used cannot be disabled locally (at least in pylint 1.4.1)
+6 -34
View File
@@ -6,14 +6,13 @@ import traceback
import tempfile import tempfile
import unittest import unittest
import configobj
import mock import mock
from letsencrypt import account from letsencrypt import account
from letsencrypt import configuration from letsencrypt import configuration
from letsencrypt import errors from letsencrypt import errors
from letsencrypt import storage
from letsencrypt.tests import renewer_test
from letsencrypt.tests import test_util from letsencrypt.tests import test_util
@@ -166,40 +165,13 @@ class DetermineAccountTest(unittest.TestCase):
self.assertEqual("other email", self.args.email) self.assertEqual("other email", self.args.email)
class DuplicativeCertsTest(unittest.TestCase): class DuplicativeCertsTest(renewer_test.BaseRenewableCertTest):
"""Test to avoid duplicate lineages."""
def setUp(self): def setUp(self):
# The stuff below is taken from renewer_test.py super(DuplicativeCertsTest, self).setUp()
self.tempdir = tempfile.mkdtemp() self.config.write()
self.cli_config = configuration.RenewerConfiguration( self._write_out_ex_kinds()
namespace=mock.MagicMock(config_dir=self.tempdir))
os.makedirs(os.path.join(self.tempdir, "live", "example.org"))
os.makedirs(os.path.join(self.tempdir, "archive", "example.org"))
os.makedirs(os.path.join(self.tempdir, "configs"))
config = configobj.ConfigObj()
for kind in storage.ALL_FOUR:
config[kind] = os.path.join(self.tempdir, "live", "example.org",
kind + ".pem")
config.filename = os.path.join(self.tempdir, "configs",
"example.org.conf")
config.write()
self.config = config
self.defaults = configobj.ConfigObj()
self.test_rc = storage.RenewableCert(
self.config, self.defaults, self.cli_config)
for kind in storage.ALL_FOUR:
where = getattr(self.test_rc, kind)
os.symlink(os.path.join("..", "..", "archive", "example.org",
"{0}12.pem".format(kind)), where)
with open(where, "w") as f:
f.write(kind)
os.unlink(where)
os.symlink(os.path.join("..", "..", "archive", "example.org",
"{0}11.pem".format(kind)), where)
with open(where, "w") as f:
f.write(kind)
# Here we will use test_rc to create duplicative stuff
def tearDown(self): def tearDown(self):
shutil.rmtree(self.tempdir) shutil.rmtree(self.tempdir)
+25 -15
View File
@@ -32,9 +32,8 @@ def fill_with_sample_data(rc_object):
f.write(kind) f.write(kind)
class RenewableCertTests(unittest.TestCase): class BaseRenewableCertTest(unittest.TestCase):
# pylint: disable=too-many-public-methods
"""Tests for letsencrypt.renewer.*."""
def setUp(self): def setUp(self):
from letsencrypt import storage from letsencrypt import storage
self.tempdir = tempfile.mkdtemp() self.tempdir = tempfile.mkdtemp()
@@ -52,10 +51,30 @@ class RenewableCertTests(unittest.TestCase):
kind + ".pem") kind + ".pem")
config.filename = os.path.join(self.tempdir, "configs", config.filename = os.path.join(self.tempdir, "configs",
"example.org.conf") "example.org.conf")
self.config = config
self.defaults = configobj.ConfigObj() self.defaults = configobj.ConfigObj()
self.test_rc = storage.RenewableCert( self.test_rc = storage.RenewableCert(
config, self.defaults, self.cli_config) self.config, self.defaults, self.cli_config)
def _write_out_ex_kinds(self):
for kind in ALL_FOUR:
where = getattr(self.test_rc, kind)
os.symlink(os.path.join("..", "..", "archive", "example.org",
"{0}12.pem".format(kind)), where)
with open(where, "w") as f:
f.write(kind)
os.unlink(where)
os.symlink(os.path.join("..", "..", "archive", "example.org",
"{0}11.pem".format(kind)), where)
with open(where, "w") as f:
f.write(kind)
class RenewableCertTests(BaseRenewableCertTest):
# pylint: disable=too-many-public-methods
"""Tests for letsencrypt.renewer.*."""
def setUp(self):
super(RenewableCertTests, self).setUp()
def tearDown(self): def tearDown(self):
shutil.rmtree(self.tempdir) shutil.rmtree(self.tempdir)
@@ -341,17 +360,8 @@ class RenewableCertTests(unittest.TestCase):
"""Test should_autodeploy() and should_autorenew() on the basis """Test should_autodeploy() and should_autorenew() on the basis
of expiry time windows.""" of expiry time windows."""
test_cert = test_util.load_vector("cert.pem") test_cert = test_util.load_vector("cert.pem")
for kind in ALL_FOUR: self._write_out_ex_kinds()
where = getattr(self.test_rc, kind)
os.symlink(os.path.join("..", "..", "archive", "example.org",
"{0}12.pem".format(kind)), where)
with open(where, "w") as f:
f.write(kind)
os.unlink(where)
os.symlink(os.path.join("..", "..", "archive", "example.org",
"{0}11.pem".format(kind)), where)
with open(where, "w") as f:
f.write(kind)
self.test_rc.update_all_links_to(12) self.test_rc.update_all_links_to(12)
with open(self.test_rc.cert, "w") as f: with open(self.test_rc.cert, "w") as f:
f.write(test_cert) f.write(test_cert)