Skip to content

Commit

Permalink
tests: Reduce code duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
Synss committed Feb 17, 2020
1 parent 72e3036 commit e8bd9b7
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions tests/test_tls.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ class _TestBaseConfiguration(Chain):
def conf(self):
raise NotImplementedError

@pytest.fixture
def version(self):
raise NotImplementedError

@pytest.mark.parametrize("validate", [True, False])
def test_set_validate_certificates(self, conf, validate):
conf_ = conf.update(validate_certificates=validate)
Expand Down Expand Up @@ -177,6 +181,14 @@ def test_set_inner_protocols(self, conf, inner_protocols):
NextProtocol(_) for _ in inner_protocols
)

def test_lowest_supported_version(self, conf, version):
conf_ = conf.update(lowest_supported_version=version)
assert conf_.lowest_supported_version is version

def test_highest_supported_version(self, conf, version):
conf_ = conf.update(highest_supported_version=version)
assert conf_.highest_supported_version is version

@pytest.mark.parametrize("store", [TrustStore.system()])
def test_trust_store(self, conf, store):
conf_ = conf.update(trust_store=store)
Expand All @@ -193,31 +205,19 @@ class TestTLSConfiguration(_TestBaseConfiguration):
def conf(self):
return TLSConfiguration()

@pytest.mark.parametrize("version", TLSVersion)
def test_lowest_supported_version(self, conf, version):
conf_ = conf.update(lowest_supported_version=version)
assert conf_.lowest_supported_version is version

@pytest.mark.parametrize("version", TLSVersion)
def test_highest_supported_version(self, conf, version):
conf_ = conf.update(highest_supported_version=version)
assert conf_.highest_supported_version is version
@pytest.fixture(params=TLSVersion)
def version(self, request):
return request.param


class TestDTLSConfiguration(_TestBaseConfiguration):
@pytest.fixture
def conf(self):
return DTLSConfiguration()

@pytest.mark.parametrize("version", DTLSVersion)
def test_lowest_supported_version(self, conf, version):
conf_ = conf.update(lowest_supported_version=version)
assert conf_.lowest_supported_version is version

@pytest.mark.parametrize("version", DTLSVersion)
def test_highest_supported_version(self, conf, version):
conf_ = conf.update(highest_supported_version=version)
assert conf_.highest_supported_version is version
@pytest.fixture(params=DTLSVersion)
def version(self, request):
return request.param

@pytest.mark.parametrize("anti_replay", [True, False])
def test_set_anti_replay(self, conf, anti_replay):
Expand Down

0 comments on commit e8bd9b7

Please sign in to comment.