Example #1
0
def test_pypi_read_server_error():
    with mock.patch('xmlrpc.client.ServerProxy') as proxy:
        proxy().changelog_since_serial.side_effect = (
            xmlrpc.client.ProtocolError('Something else went wrong', 500, '',
                                        ''))
        events = PyPIEvents()
        assert list(events) == []
Example #2
0
def test_pypi_read_improper_state():
    with mock.patch('xmlrpc.client.ServerProxy') as proxy:
        proxy().changelog_since_serial.side_effect = (
            http.client.ImproperConnectionState(
                'Something went horribly wrong'))
        events = PyPIEvents()
        assert list(events) == []
Example #3
0
def test_pypi_read_client_error():
    with mock.patch('xmlrpc.client.ServerProxy') as proxy:
        proxy().changelog_since_serial.side_effect = (
            xmlrpc.client.ProtocolError('Client did something stupid', 400, '',
                                        ''))
        events = PyPIEvents()
        with pytest.raises(xmlrpc.client.ProtocolError):
            list(events)
Example #4
0
def test_pypi_read_normal():
    with mock.patch('xmlrpc.client.ServerProxy') as proxy:
        proxy().changelog_since_serial.return_value = [
            ('foo', '0.1', 1531327388, 'create', 0),
            ('foo', '0.1', 1531327388, 'add source file foo-0.1.tar.gz', 1),
            ('bar', '1.0', 1531327389, 'create', 2),
            ('bar', '1.0', 1531327389, 'add py2.py3 file bar-1.0-py2.py3-none-any.whl', 3),
        ]
        events = PyPIEvents()
        assert list(events) == [('foo', '0.1'), ('bar', '1.0')]
Example #5
0
def test_pypi_ignore_dupes():
    with mock.patch('xmlrpc.client.ServerProxy') as proxy:
        proxy().changelog_since_serial.return_value = [
            ('foo', '0.1', 1531327388, 'create', 0),
            ('foo', '0.1', 1531327388, 'add source file foo-0.1.tar.gz', 1),
            ('bar', '1.0', 1531327389, 'create', 2),
            ('bar', '1.0', 1531327389, 'add source file bar-1.0-py2.py3-none-any.whl', 3),
            ('bar', '1.0', 1531327391, 'add py2.py3 file bar-1.0-py2.py3-none-any.whl', 4),
            ('bar', '1.0', 1531327392, 'add cp34 file bar-0.1-cp34-cp34-manylinux1_x86_64.whl', 5),
            ('bar', '1.0', 1531327392, 'add cp35 file bar-0.1-cp35-cp35-manylinux1_x86_64.whl', 6),
        ]
        events = PyPIEvents()
        assert list(events) == [('foo', '0.1'), ('bar', '1.0')]
Example #6
0
def test_pypi_remove_package():
    with mock.patch('xmlrpc.client.ServerProxy') as proxy:
        proxy().changelog_since_serial.return_value = [
            ('foo', '0.1', 1531327388, 'create', 0),
            ('foo', '0.1', 1531327388, 'add source file foo-0.1.tar.gz', 1),
            ('foo', None, 1531327388, 'remove', 2),
        ]
        events = PyPIEvents()
        assert list(events) == [
            ('foo', None, dt('2018-07-11 16:43:08'), 'create'),
            ('foo', '0.1', dt('2018-07-11 16:43:08'), 'source'),
            ('foo', None, dt('2018-07-11 16:43:08'), 'remove'),
        ]
Example #7
0
def test_pypi_cache_expunge():
    with mock.patch('xmlrpc.client.ServerProxy') as proxy:
        proxy().changelog_since_serial.return_value = [
            ('foo', '0.1', 1531327388, 'create', 0),
            ('foo', '0.1', 1531327388, 'add source file foo-0.1.tar.gz', 1),
            ('bar', '1.0', 1531327389, 'create', 2),
            ('bar', '1.0', 1531327389,
             'add py2.py3 file bar-1.0-py2.py3-none-any.whl', 3),
        ]
        events = PyPIEvents(cache_size=1)
        assert list(events) == [
            ('foo', None, dt('2018-07-11 16:43:08'), None),
            ('foo', '0.1', dt('2018-07-11 16:43:08'), True),
            ('bar', None, dt('2018-07-11 16:43:09'), None),
            ('bar', '1.0', dt('2018-07-11 16:43:09'), False),
        ]
        assert ('foo', '0.1') not in events.cache
        assert ('bar', '1.0') in events.cache
Example #8
0
def test_pypi_ignore_other_events():
    with mock.patch('xmlrpc.client.ServerProxy') as proxy:
        proxy().changelog_since_serial.return_value = [
            ('foo', '0.1', 1531327388, 'create', 0),
            ('foo', '0.1', 1531327388, 'add source file foo-0.1.tar.gz', 1),
            ('bar', '1.0', 1531327389, 'create', 2),
            ('bar', '1.0', 1531327389,
             'add py2.py3 file bar-1.0-py2.py3-none-any.whl', 3),
            ('bar', '1.0', 1531327392, 'foo', 4),
            ('bar', '1.0', 1531327392, 'foo bar baz', 5),
        ]
        events = PyPIEvents()
        assert list(events) == [
            ('foo', None, dt('2018-07-11 16:43:08'), None),
            ('foo', '0.1', dt('2018-07-11 16:43:08'), True),
            ('bar', None, dt('2018-07-11 16:43:09'), None),
            ('bar', '1.0', dt('2018-07-11 16:43:09'), False),
        ]
Example #9
0
def test_pypi_ignore_dupes():
    with mock.patch('xmlrpc.client.ServerProxy') as proxy:
        proxy().changelog_since_serial.return_value = [
            ('foo', '0.1', 1531327388, 'create', 0),
            ('foo', '0.1', 1531327388, 'add source file foo-0.1.tar.gz', 1),
            ('bar', '1.0', 1531327389, 'create', 2),
            ('bar', '1.0', 1531327389, 'add source file bar-1.0.tar.gz', 3),
            ('bar', '1.0', 1531327389, 'add source file bar-1.0.zip', 4),
            ('bar', '1.0', 1531327392,
             'add cp34 file bar-0.1-cp34-cp34-manylinux1_x86_64.whl', 5),
            ('bar', '1.0', 1531327392,
             'add cp35 file bar-0.1-cp35-cp35-manylinux1_x86_64.whl', 6),
        ]
        events = PyPIEvents()
        assert list(events) == [
            ('foo', None, dt('2018-07-11 16:43:08'), None),
            ('foo', '0.1', dt('2018-07-11 16:43:08'), True),
            ('bar', None, dt('2018-07-11 16:43:09'), None),
            ('bar', '1.0', dt('2018-07-11 16:43:09'), True),
        ]
Example #10
0
def test_pypi_promote_binary_to_source():
    with mock.patch('xmlrpc.client.ServerProxy') as proxy:
        proxy().changelog_since_serial.return_value = [
            ('foo', '0.1', 1531327388, 'create', 0),
            ('foo', '0.1', 1531327388, 'add source file foo-0.1.tar.gz', 1),
            ('bar', '1.0', 1531327389, 'create', 2),
            ('bar', '1.0', 1531327390,
             'add cp34 file bar-0.1-cp34-cp34-manylinux1_x86_64.whl', 3),
            ('bar', '1.0', 1531327390,
             'add cp35 file bar-0.1-cp35-cp35-manylinux1_x86_64.whl', 4),
            ('bar', '1.0', 1531327392, 'add source file bar-1.0.tar.gz', 5),
            ('bar', '1.0', 1531327392, 'add source file bar-1.0.zip', 6),
        ]
        events = PyPIEvents()
        assert list(events) == [
            ('foo', None, dt('2018-07-11 16:43:08'), None),
            ('foo', '0.1', dt('2018-07-11 16:43:08'), True),
            ('bar', None, dt('2018-07-11 16:43:09'), None),
            ('bar', '1.0', dt('2018-07-11 16:43:10'), False),
            # Note the timestamp doesn't alter as the release time is the
            # earliest release
            ('bar', '1.0', dt('2018-07-11 16:43:10'), True),
        ]
Example #11
0
def test_pypi_backoff():
    with mock.patch('xmlrpc.client.ServerProxy') as proxy:
        proxy().changelog_since_serial.return_value = [
            ('foo', '0.1', 1531327388, 'create', 0),
            ('foo', '0.1', 1531327388, 'add source file foo-0.1.tar.gz', 1),
            ('bar', '1.0', 1531327389, 'create', 2),
            ('bar', '1.0', 1531327389,
             'add py2.py3 file bar-1.0-py2.py3-none-any.whl', 3),
        ]
        events = PyPIEvents()
        assert list(events) == [
            ('foo', None, dt('2018-07-11 16:43:08'), 'create'),
            ('foo', '0.1', dt('2018-07-11 16:43:08'), 'source'),
            ('bar', None, dt('2018-07-11 16:43:09'), 'create'),
            ('bar', '1.0', dt('2018-07-11 16:43:09'), 'create'),
        ]
        proxy().changelog_since_serial.return_value = []
        assert list(events) == []
        proxy().changelog_since_serial.return_value = [
            ('bar', '1.1', 1531327392, 'create', 4),
            ('bar', '1.1', 1531327393, 'add source file bar-1.1.tar.gz', 5),
        ]
        # Because 10 seconds haven't elapsed...
        assert list(events) == []