mirror of https://gitlab.com/bashrc2/epicyon
Unit test for getting day via caldav
parent
44ba3bf35c
commit
7ec097cade
24
epicyon.py
24
epicyon.py
|
@ -103,6 +103,7 @@ from socnet import instances_graph
|
|||
from migrate import migrate_accounts
|
||||
from desktop_client import run_desktop_client
|
||||
from happening import dav_month_via_server
|
||||
from happening import dav_day_via_server
|
||||
|
||||
|
||||
def str2bool(value_str) -> bool:
|
||||
|
@ -192,6 +193,9 @@ parser.add_argument('--year', dest='year', type=int,
|
|||
parser.add_argument('--month', dest='month', type=int,
|
||||
default=search_date.month,
|
||||
help='Month for calendar query')
|
||||
parser.add_argument('--day', dest='day', type=int,
|
||||
default=None,
|
||||
help='Day for calendar query')
|
||||
parser.add_argument('--postsPerSource',
|
||||
dest='max_newswire_postsPerSource', type=int,
|
||||
default=4,
|
||||
|
@ -1443,12 +1447,20 @@ if args.dav:
|
|||
elif args.gnunet:
|
||||
proxy_type = 'gnunet'
|
||||
session = create_session(proxy_type)
|
||||
result = \
|
||||
dav_month_via_server(session, http_prefix,
|
||||
args.nickname, args.domain, args.port,
|
||||
args.debug,
|
||||
args.year, args.month,
|
||||
args.password)
|
||||
if args.day:
|
||||
result = \
|
||||
dav_day_via_server(session, http_prefix,
|
||||
args.nickname, args.domain, args.port,
|
||||
args.debug,
|
||||
args.year, args.month, args.day,
|
||||
args.password)
|
||||
else:
|
||||
result = \
|
||||
dav_month_via_server(session, http_prefix,
|
||||
args.nickname, args.domain, args.port,
|
||||
args.debug,
|
||||
args.year, args.month,
|
||||
args.password)
|
||||
if result:
|
||||
print(str(result))
|
||||
sys.exit()
|
||||
|
|
54
happening.py
54
happening.py
|
@ -1075,9 +1075,9 @@ def dav_report_response(base_dir: str, nickname: str, domain: str,
|
|||
if query_start_day == query_end_day:
|
||||
# calendar for one day
|
||||
search_date = \
|
||||
datetime.datetime(year=query_start_year,
|
||||
month=query_start_month,
|
||||
day=query_start_day)
|
||||
datetime(year=query_start_year,
|
||||
month=query_start_month,
|
||||
day=query_start_day)
|
||||
ical_events = \
|
||||
get_todays_events_icalendar(base_dir, nickname, domain,
|
||||
search_date.year,
|
||||
|
@ -1303,7 +1303,53 @@ def dav_month_via_server(session, http_prefix: str,
|
|||
' <c:time-range start="' + str(year) + month_str + \
|
||||
'01T000000Z"\n' + \
|
||||
' end="' + str(year) + month_str + \
|
||||
'31T000000Z"/>\n' + \
|
||||
'31T235959Z"/>\n' + \
|
||||
' </c:comp-filter>\n' + \
|
||||
' </c:comp-filter>\n' + \
|
||||
' </c:filter>\n' + \
|
||||
'</c:calendar-query>'
|
||||
result = \
|
||||
get_method("REPORT", xml_str, session, url, params, headers, debug)
|
||||
return result
|
||||
|
||||
|
||||
def dav_day_via_server(session, http_prefix: str,
|
||||
nickname: str, domain: str, port: int,
|
||||
debug: bool,
|
||||
year: int, month: int, day: int,
|
||||
password: str) -> str:
|
||||
"""Gets the icalendar for a day via caldav
|
||||
"""
|
||||
auth_header = create_basic_auth_header(nickname, password)
|
||||
|
||||
headers = {
|
||||
'host': domain,
|
||||
'Content-type': 'application/xml',
|
||||
'Authorization': auth_header
|
||||
}
|
||||
domain_full = get_full_domain(domain, port)
|
||||
params = {}
|
||||
url = http_prefix + '://' + domain_full + '/calendars/' + nickname
|
||||
month_str = str(month)
|
||||
if month < 10:
|
||||
month_str = '0' + month_str
|
||||
day_str = str(day)
|
||||
if day < 10:
|
||||
day_str = '0' + day_str
|
||||
xml_str = \
|
||||
'<?xml version="1.0" encoding="utf-8" ?>\n' + \
|
||||
'<c:calendar-query xmlns:d="DAV:"\n' + \
|
||||
' xmlns:c="urn:ietf:params:xml:ns:caldav">\n' + \
|
||||
' <d:prop>\n' + \
|
||||
' <d:getetag/>\n' + \
|
||||
' </d:prop>\n' + \
|
||||
' <c:filter>\n' + \
|
||||
' <c:comp-filter name="VCALENDAR">\n' + \
|
||||
' <c:comp-filter name="VEVENT">\n' + \
|
||||
' <c:time-range start="' + str(year) + month_str + \
|
||||
day_str + 'T000000Z"\n' + \
|
||||
' end="' + str(year) + month_str + \
|
||||
day_str + 'T235959Z"/>\n' + \
|
||||
' </c:comp-filter>\n' + \
|
||||
' </c:comp-filter>\n' + \
|
||||
' </c:filter>\n' + \
|
||||
|
|
14
tests.py
14
tests.py
|
@ -177,6 +177,7 @@ from shares import get_shared_items_catalog_via_server
|
|||
from blocking import load_cw_lists
|
||||
from blocking import add_cw_from_lists
|
||||
from happening import dav_month_via_server
|
||||
from happening import dav_day_via_server
|
||||
|
||||
|
||||
TEST_SERVER_GROUP_RUNNING = False
|
||||
|
@ -3176,17 +3177,20 @@ def test_client_to_server(base_dir: str):
|
|||
if os.path.isfile(os.path.join(alice_inbox_path, name))]) == 0
|
||||
|
||||
print('\n\nEVENT: Bob checks his calendar via caldav')
|
||||
if os.path.isfile(bob_dir + '/basic_auth_fail.txt'):
|
||||
os.remove(bob_dir + '/basic_auth_fail.txt')
|
||||
result = \
|
||||
dav_month_via_server(session_bob, http_prefix,
|
||||
'bob', bob_domain, bob_port, True,
|
||||
test_date.year, test_date.month,
|
||||
'bobpass')
|
||||
print('response: ' + str(result))
|
||||
if os.path.isfile(bob_dir + '/basic_auth_fail.txt'):
|
||||
with open(bob_dir + '/basic_auth_fail.txt', 'r') as fp_fail:
|
||||
print(fp_fail.read())
|
||||
assert 'VCALENDAR' in str(result)
|
||||
assert 'VEVENT' in str(result)
|
||||
result = \
|
||||
dav_day_via_server(session_bob, http_prefix,
|
||||
'bob', bob_domain, bob_port, True,
|
||||
test_date.year, test_date.month,
|
||||
test_date.day, 'bobpass')
|
||||
print('response: ' + str(result))
|
||||
assert 'VCALENDAR' in str(result)
|
||||
assert 'VEVENT' in str(result)
|
||||
|
||||
|
|
Loading…
Reference in New Issue