def test_print_summary_data_mock(capsys, get_data_urlopen_mock): command = cli.Cli('test') resp = sndslib.get_data('test') summary = sndslib.summarize(resp) command._print_summary(summary, ['1.1.1.1']) captured = capsys.readouterr() expected_return = [ 'Date: 09/29/2020 ', 'IPs: 3 ', 'Green: 1 ', 'Yellow: 1 ', 'Red: 1 ', 'Trap Hits: 107 ', 'Blocked: 1', ] for s in expected_return: assert s in captured.out
def test_search_ip_status_return_success(get_data_urlopen_mock): resp = sndslib.get_data('test') resp_dict = sndslib.search_ip_status('1.1.1.0', resp) expected_return = { 'ip_address': '1.1.1.0', 'activity_start': '12/31/2019 8:00 AM', 'activity_end': '9/29/2020 9:00 PM', 'rcpt_commands': '14129', 'data_commands': '14129', 'message_recipients': '13025', 'filter_result': 'GREEN', 'complaint_rate': '< 0.1%', 'trap_message_start': '9/29/2020 8:07 AM', 'trap_message_end': '9/29/2020 12:03 PM', 'traphits': '41', 'sample_helo': '', 'sample_mailfrom': '', 'comments': '' } assert resp_dict == expected_return
def usage_data(self): if not self._usage_data: self._usage_data = sndslib.get_data(self.key, self.date) return self._usage_data
def test_summarize_yellow_count(get_data_urlopen_mock): resp = sndslib.get_data('test') summary = sndslib.summarize(resp) assert summary['yellow'] == 1
def test_summarize_return_dict(get_data_urlopen_mock): resp = sndslib.get_data('test') summary = sndslib.summarize(resp) assert isinstance(summary, dict)
def test_get_data_with_date_len(get_data_urlopen_mock): resp = sndslib.get_data('test', '290920') assert len(resp) == 3
def test_get_data_len(get_data_urlopen_mock): resp = sndslib.get_data('test') assert len(resp) == 3
def test_get_data__with_date_first_value(get_data_urlopen_mock): resp = sndslib.get_data('test', '290920') first_line_value = '1.1.1.0,12/31/2019 8:00 AM,9/29/2020 9:00 PM,14129,14129,13025,GREEN,< 0.1%,9/29/2020 8:07 AM,9/29/2020 12:03 PM,41,,,' # noqa assert first_line_value == resp[0]
def test_get_data__with_date_have_ips(get_data_urlopen_mock): resp = sndslib.get_data('test', '290920') assert '1.1.1.0' in resp[0]
def test_get_data_have_ips(get_data_urlopen_mock): resp = sndslib.get_data('test') assert '1.1.1.0' in resp[0]
def test_get_data_with_date_is_list(get_data_urlopen_mock): resp = sndslib.get_data('test', '290920') assert isinstance(resp, list)
def test_get_data_is_list(get_data_urlopen_mock): resp = sndslib.get_data('test') assert isinstance(resp, list)
def test_get_data_fail_without_key(): with pytest.raises(TypeError): sndslib.get_data()
def test_search_ip_status_return_failure_type(get_data_urlopen_mock): resp = sndslib.get_data('test') resp_dict = sndslib.search_ip_status('0.0.0.0', resp) assert isinstance(resp_dict, dict)
def test_search_ip_status_return_failure(get_data_urlopen_mock): resp = sndslib.get_data('test') resp_dict = sndslib.search_ip_status('0.0.0.0', resp) assert bool(resp_dict) is False