This repository has been archived by the owner on Feb 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_pyfraid.py
56 lines (46 loc) · 1.95 KB
/
test_pyfraid.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
""" This module tests the afaid.py module
"""
import unittest2
from mock import patch
import pyafraid
class TestAfraid(unittest2.TestCase):
@patch('sys.exit')
def test_error(self, mockexit):
""" Test that the error method works properly
"""
errcode = 2
pyafraid.error('this is an error message', code=errcode)
mockexit.assert_called_with(2)
def test_get_sha(self):
""" Test that the get_sha method returns the correct digest string
"""
username = 'foo'
password = 'bar'
expected = '4fa0d6984df3b91af1f0942b7522987783050b90'
self.assertEqual(pyafraid.get_sha(username, password), expected)
def test_parse_ascii_api(self):
records = pyafraid.parse_ascii_api(API_OUTPUT)
self.assertEqual(records, SAMPLE_RECORDS)
def test_get_records_by_desc(self):
desc = 'example.org'
record = pyafraid.get_record_by_desc(SAMPLE_RECORDS, desc)
self.assertEqual(record, SAMPLE_RECORDS[0])
@patch('urllib2.urlopen')
def test_update_url(self, mockurlopen):
mockurlopen.return_value.read.return_value = ""
pyafraid.update_url(SAMPLE_RECORDS[0])
API_OUTPUT = \
"""
example.org|1.1.1.1|http://freedns.afraid.org/dynamic/update.php?someFakeHash
deathstar.example.org|2.2.2.2|http://freedns.afraid.org/dynamic/update.php?eLKJDUasdfialsdDDF
eve.example.org|3.3.3.3|http://freedns.afraid.org/dynamic/update.php?eFMybzR5Vn
"""
SAMPLE_RECORDS = [{'desc': 'example.org',
'ip': '1.1.1.1',
'url': 'http://freedns.afraid.org/dynamic/update.php?someFakeHash'},
{'desc': 'deathstar.example.org',
'ip': '2.2.2.2',
'url': 'http://freedns.afraid.org/dynamic/update.php?eLKJDUasdfialsdDDF'},
{'desc': 'eve.example.org',
'ip': '3.3.3.3',
'url': 'http://freedns.afraid.org/dynamic/update.php?eFMybzR5Vn'}]