Esempio n. 1
0
    def test_curl_other_site_twice(self, mocks, mocker):
        subject = TrafficHandler('snow', self.mock_traffic_commands)
        self.mock_input.return_value = '2'
        self.mock_time.ctime.return_value = 'Fri Feb  1 12:29:43 2019'
        self.mock_traffic_commands.curl = 'curl command'

        subject.curl('othersite.com')

        self.mock_input.assert_called_with(
            'How many curls for snow? (blank line to cancel) ')
        assert self.mock_print.mock_calls == [
            mocker.call('\tstarting curl on snow...'),
            mocker.call(
                'Fri Feb  1 12:29:43 2019 sending curl othersite.com #0'),
            mocker.call(
                'Fri Feb  1 12:29:43 2019 sending curl othersite.com #1'),
            mocker.call('\tdone.'),
        ]
        assert len(subject.traffic_handles) == 2
        assert self.mock_curl.mock_calls == [
            mocker.call('othersite.com', 'curl command'),
            mocker.call('othersite.com', 'curl command'),
        ]
        assert self.mock_time.sleep.mock_calls == [
            mocker.call(2), mocker.call(2)
        ]
Esempio n. 2
0
    def test_curl_bad_input(self, mocks, mocker):
        subject = TrafficHandler('snow', self.mock_traffic_commands)
        self.mock_input.side_effect = ['NaN', '-1', '']

        subject.curl()

        assert self.mock_input.mock_calls == [
            mocker.call('How many curls for snow? (blank line to cancel) '),
            mocker.call('How many curls for snow? (blank line to cancel) '),
            mocker.call('How many curls for snow? (blank line to cancel) '),
        ]
        assert self.mock_print.mock_calls == [
            mocker.call('NaN is not a number'),
            mocker.call('-1 is not a valid number'),
        ]
        assert self.mock_curl.call_count == 0
        assert not subject.traffic_handles
        assert self.mock_curl.call_count == 0
        assert self.mock_time.sleep.call_count == 0
Esempio n. 3
0
    def test_curl_default_site_once(self, mocks, mocker):
        subject = TrafficHandler('snow', self.mock_traffic_commands)
        self.mock_input.return_value = '1'
        self.mock_time.ctime.return_value = 'Fri Feb  1 12:29:43 2019'
        self.mock_traffic_commands.curl = 'curl command'

        subject.curl()

        self.mock_input.assert_called_with(
            'How many curls for snow? (blank line to cancel) ')
        assert self.mock_print.mock_calls == [
            mocker.call('\tstarting curl on snow...'),
            mocker.call('Fri Feb  1 12:29:43 2019 sending curl %s #0' %
                        'https://www.piday.org/million/'),
            mocker.call('\tdone.'),
        ]
        assert len(subject.traffic_handles) == 1
        self.mock_curl.assert_called_with('https://www.piday.org/million/',
                                          'curl command')
        self.mock_time.sleep.assert_called_with(2)