예제 #1
0
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
예제 #2
0
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
예제 #3
0
파일: cli.py 프로젝트: undersfx/sndslib
 def usage_data(self):
     if not self._usage_data:
         self._usage_data = sndslib.get_data(self.key, self.date)
     return self._usage_data
예제 #4
0
def test_summarize_yellow_count(get_data_urlopen_mock):
    resp = sndslib.get_data('test')
    summary = sndslib.summarize(resp)
    assert summary['yellow'] == 1
예제 #5
0
def test_summarize_return_dict(get_data_urlopen_mock):
    resp = sndslib.get_data('test')
    summary = sndslib.summarize(resp)
    assert isinstance(summary, dict)
예제 #6
0
def test_get_data_with_date_len(get_data_urlopen_mock):
    resp = sndslib.get_data('test', '290920')
    assert len(resp) == 3
예제 #7
0
def test_get_data_len(get_data_urlopen_mock):
    resp = sndslib.get_data('test')
    assert len(resp) == 3
예제 #8
0
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]
예제 #9
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]
예제 #10
0
def test_get_data_have_ips(get_data_urlopen_mock):
    resp = sndslib.get_data('test')
    assert '1.1.1.0' in resp[0]
예제 #11
0
def test_get_data_with_date_is_list(get_data_urlopen_mock):
    resp = sndslib.get_data('test', '290920')
    assert isinstance(resp, list)
예제 #12
0
def test_get_data_is_list(get_data_urlopen_mock):
    resp = sndslib.get_data('test')
    assert isinstance(resp, list)
예제 #13
0
def test_get_data_fail_without_key():
    with pytest.raises(TypeError):
        sndslib.get_data()
예제 #14
0
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)
예제 #15
0
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