def test_wikipedia_return(self, summary):
        """
        Tests wikipedia return by mocking wikipedia.summary

        Internet connection is disbled for this test
        """
        disable_socket()
        MOCK_INPUT_VALUE = "mock wikipedia return"
        MOCK_RETURN_VALUE = "mock|wikipedia|return"
        summary.return_value = MOCK_INPUT_VALUE
        kp = KeyboardPractice()
        lines = kp.get_text_from_wikipedia("NonexistentSearch", stats=False)
        self.assertEqual(MOCK_RETURN_VALUE, lines)
示例#2
0
def credentials(request):
    # local tests require environment variables `DHUS_USER` and `DHUS_PASSWORD`
    # for Travis CI they are set as encrypted environment variables and stored
    record_mode = request.config.getoption('--vcr-record')
    disable_vcr = request.config.getoption('--disable-vcr')
    if record_mode in ["none", None] and not disable_vcr:
        # Using VCR.py cassettes for pre-recorded query playback
        # Any network traffic will raise an exception
        disable_socket()
    elif 'DHUS_USER' not in environ or 'DHUS_PASSWORD' not in environ:
        raise ValueError("Credentials must be set when --vcr-record is not none or --disable-vcr is used. "
                         "Please set DHUS_USER and DHUS_PASSWORD environment variables.")

    return [environ.get('DHUS_USER'), environ.get('DHUS_PASSWORD')]
示例#3
0
def credentials(request):
    # local tests require environment variables `DHUS_USER` and `DHUS_PASSWORD`
    # for Travis CI they are set as encrypted environment variables and stored
    record_mode = request.config.getoption("--vcr-record")
    disable_vcr = request.config.getoption("--disable-vcr")
    if record_mode in ["none", None] and not disable_vcr:
        # Using VCR.py cassettes for pre-recorded query playback
        # Any network traffic will raise an exception
        disable_socket()
    elif "DHUS_USER" not in environ or "DHUS_PASSWORD" not in environ:
        raise ValueError(
            "Credentials must be set when --vcr-record is not none or --disable-vcr is used. "
            "Please set DHUS_USER and DHUS_PASSWORD environment variables.")

    return [environ.get("DHUS_USER"), environ.get("DHUS_PASSWORD")]
示例#4
0
def pytest_runtest_setup():
    """
    This test suite uses pytest-socket which causes tests to fail immediately if
    a call to socket.socket is made, or in other words, tries to access the
    internet. However, the boto library tries to resolve addresses by calling
    socket.getaddrinfo which will make blocking network calls but is not covered
    by pytest-socket.

    This test setup will cause tests to fail immediately if socket.getaddrinfo
    is called.
    """
    def block_lookup(*args, **kwargs):
        raise SocketBlockedError

    disable_socket()
    socket.getaddrinfo = block_lookup
示例#5
0
def pytest_runtest_setup():
    """Prepare pytest_socket and freezegun.

    pytest_socket:
    Throw if tests attempt to open sockets.

    allow_unix_socket is set to True because it's needed by asyncio.
    Important: socket_allow_hosts must be called before disable_socket, otherwise all
    destinations will be allowed.

    freezegun:
    Modified to include https://github.com/spulec/freezegun/pull/424
    """
    pytest_socket.socket_allow_hosts(["127.0.0.1"])
    pytest_socket.disable_socket(allow_unix_socket=True)

    freezegun.api.datetime_to_fakedatetime = ha_datetime_to_fakedatetime
    freezegun.api.FakeDatetime = HAFakeDatetime
示例#6
0
 def setUp(self):
     disable_socket()
示例#7
0
def test_loadBioNLP_fail():
    pytest_socket.disable_socket()
    with pytest.raises(RuntimeError) as excinfo:
        corpus = kindred.bionlpst.load('2016-BB3-event-train')
    pytest_socket.enable_socket()
    assert excinfo.value.args == ('A test tried to use socket.socket.', )
示例#8
0
import vcr
from pytest_socket import disable_socket

from .custom_serializer import BinaryContentSerializer

TESTS_DIR = dirname(abspath(__file__))
FIXTURES_DIR = join(TESTS_DIR, 'fixtures')
CASSETTE_DIR = join(FIXTURES_DIR, 'vcr_cassettes')
PROJECT_ROOT_DIR = dirname(TESTS_DIR)

vcr_option = pytest.config.getoption("--vcr")
record_mode = "none"
if vcr_option == "use":
    print("Tests will use prerecorded query responses.")
    # Guarantee that only prerecorded queries are used by blocking any network traffic
    disable_socket()
elif vcr_option == "record_new":
    print(
        "Tests will use prerecorded query responses and record any new ones.")
    record_mode = "new_episodes"
elif vcr_option == "reset":
    print("Tests will re-record query responses.")
    record_mode = "all"


def scrub_request(request):
    for header in ("Authorization", "Set-Cookie", "Cookie"):
        if header in request.headers:
            del request.headers[header]
    return request
示例#9
0
 def test_get_model_error(self):
     disable_socket()
     with self.assertRaises(ConnectionError):
         aux.get_model_from_s3(self.model_path)
示例#10
0
 def test_url_processing_error(self):
     disable_socket()
     with self.assertRaises(ConnectionError):
         OcrTable('https://project-elements-nk.s3.amazonaws.com/ocr.png')
示例#11
0
def pytest_runtest_setup():
    disable_socket()
示例#12
0
def pytest_runtest_setup():
    """
    This is run when setting up the tests.
    """
    # We don't want to allow access to sockets, to make sure we're not making calls to some website
    disable_socket()
示例#13
0
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
# ANY KIND, either express or implied. See the License for the specific
# language governing permissions and limitations under the License.
import sys

import pytest
import pytest_socket

from ebcli.core import fileoperations, io
from ebcli.core.ebrun import fix_path

pytest_socket.disable_socket()


def ensure_eb_application_has_not_been_initialized():
    if '--help' in sys.argv:
        # Allow `pytest --help` to print
        return

    if fileoperations.inside_ebcli_project():
        exception_message = ' '.join([
            'ERROR: This directory or one of its ancestors has been `eb init`-ed. Ensure that the .elasticbeanstalk',
            'directories in this directory or above it have been deleted in order for the test suite to run.'
        ])
        io.echo(exception_message)
        exit(1)
示例#14
0
def pytest_disable_socket():
    disable_socket()
示例#15
0
def no_sockets():
    disable_socket()
示例#16
0
def pytest_runtest_setup():
    """Pytest setup hook."""
    disable_socket()