test_fetch.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env python2
  2. # -*- coding: utf-8 -*-
  3. from library.python import resource
  4. import pytest
  5. import ssl
  6. # import urllib2
  7. class TestRequest(object):
  8. @pytest.fixture
  9. def ctx(self):
  10. r = resource.find("/builtin/cacert")
  11. # ssl.create_default_context expects unicode string for pem-coded certificates
  12. r = r.decode('ascii', errors='ignore')
  13. return ssl.create_default_context(cadata=r)
  14. def test_certs(self, ctx):
  15. assert any(
  16. any(item[0] == ("commonName", "YandexInternalRootCA") for item in cert["subject"])
  17. for cert in ctx.get_ca_certs()
  18. )
  19. assert any(
  20. any(item[0] == ("commonName", "Certum Trusted Network CA") for item in cert["subject"])
  21. for cert in ctx.get_ca_certs()
  22. )
  23. # def test_internal(self, ctx):
  24. # connection = urllib2.urlopen("https://nanny.yandex-team.ru/", context=ctx)
  25. # assert connection.read()
  26. # def test_external(self, ctx):
  27. # connection = urllib2.urlopen("https://docs.python.org/", context=ctx)
  28. # assert connection.read()