sabredav_client 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -3
- data/.rspec +1 -1
- data/CHANGELOG.rdoc +8 -8
- data/Gemfile +3 -3
- data/Gemfile.lock +38 -39
- data/README.md +49 -49
- data/Rakefile +5 -5
- data/lib/sabredav_client.rb +10 -10
- data/lib/sabredav_client/calendar.rb +174 -171
- data/lib/sabredav_client/client.rb +57 -57
- data/lib/sabredav_client/errors/errors.rb +41 -41
- data/lib/sabredav_client/events.rb +106 -106
- data/lib/sabredav_client/net.rb +15 -15
- data/lib/sabredav_client/principal.rb +51 -51
- data/lib/sabredav_client/request.rb +97 -97
- data/lib/sabredav_client/version.rb +3 -3
- data/lib/sabredav_client/xml_request_builder.rb +7 -7
- data/lib/sabredav_client/xml_request_builder/base.rb +17 -17
- data/lib/sabredav_client/xml_request_builder/mkcalendar.rb +25 -25
- data/lib/sabredav_client/xml_request_builder/mkcol_principal.rb +28 -28
- data/lib/sabredav_client/xml_request_builder/post_sharing.rb +41 -41
- data/lib/sabredav_client/xml_request_builder/propfind_calendar.rb +41 -41
- data/lib/sabredav_client/xml_request_builder/propfind_invite.rb +19 -19
- data/lib/sabredav_client/xml_request_builder/propfind_owner.rb +19 -19
- data/lib/sabredav_client/xml_request_builder/proppatch_calendar.rb +25 -25
- data/lib/sabredav_client/xml_request_builder/proppatch_events_owner.rb +23 -23
- data/lib/sabredav_client/xml_request_builder/proppatch_principal.rb +25 -25
- data/lib/sabredav_client/xml_request_builder/report_event_changes.rb +22 -22
- data/lib/sabredav_client/xml_request_builder/report_vevent.rb +30 -30
- data/lib/sabredav_client/xml_request_builder/report_vtodo.rb +20 -20
- data/sabredav_client.gemspec +31 -31
- data/spec/fixtures/calendar_fetch_changes.xml +26 -26
- data/spec/fixtures/calendar_info.xml +14 -14
- data/spec/fixtures/calendar_sharees.xml +35 -35
- data/spec/fixtures/calendar_sharees_without_common_name.xml +26 -26
- data/spec/fixtures/event.ics +23 -23
- data/spec/fixtures/events_find_multiple.xml +51 -51
- data/spec/fixtures/events_owner.xml +12 -12
- data/spec/fixtures/xml_request_builder/mkcalendar.xml +9 -9
- data/spec/fixtures/xml_request_builder/mkcol_principal.xml +12 -12
- data/spec/fixtures/xml_request_builder/post_sharing.xml +18 -18
- data/spec/fixtures/xml_request_builder/propfind_calendar/all_properties.xml +8 -8
- data/spec/fixtures/xml_request_builder/propfind_invite.xml +6 -6
- data/spec/fixtures/xml_request_builder/propfind_owner.xml +6 -6
- data/spec/fixtures/xml_request_builder/proppatch_calendar.xml +9 -9
- data/spec/fixtures/xml_request_builder/proppatch_events_owner.xml +8 -8
- data/spec/fixtures/xml_request_builder/proppatch_principal.xml +9 -9
- data/spec/fixtures/xml_request_builder/report_event_changes.xml +8 -8
- data/spec/sabredav_client/calendar_spec.rb +142 -142
- data/spec/sabredav_client/client_spec.rb +41 -41
- data/spec/sabredav_client/events_spec.rb +119 -119
- data/spec/sabredav_client/principal_spec.rb +51 -51
- data/spec/sabredav_client/request_spec.rb +55 -55
- data/spec/sabredav_client/xml_request_builder_specs/base_spec.rb +30 -30
- data/spec/sabredav_client/xml_request_builder_specs/mkcalendar_spec.rb +13 -13
- data/spec/sabredav_client/xml_request_builder_specs/mkcol_principal_spec.rb +13 -13
- data/spec/sabredav_client/xml_request_builder_specs/post_sharing_spec.rb +15 -15
- data/spec/sabredav_client/xml_request_builder_specs/propfind_calendar_spec.rb +24 -24
- data/spec/sabredav_client/xml_request_builder_specs/propfind_invite_spec.rb +14 -14
- data/spec/sabredav_client/xml_request_builder_specs/propfind_owner_spec.rb +14 -14
- data/spec/sabredav_client/xml_request_builder_specs/proppatch_calendar.rb +15 -15
- data/spec/sabredav_client/xml_request_builder_specs/proppatch_events_owner_spec.rb +14 -14
- data/spec/sabredav_client/xml_request_builder_specs/proppatch_principal_spec.rb +24 -24
- data/spec/sabredav_client/xml_request_builder_specs/report_event_changes_spec.rb +15 -15
- data/spec/spec.opts +4 -4
- data/spec/spec_helper.rb +8 -8
- metadata +6 -5
@@ -1,9 +1,9 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<d:propertyupdate xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
3
|
-
<d:set>
|
4
|
-
<d:prop>
|
5
|
-
<d:displayname>name</d:displayname>
|
6
|
-
<c:calendar-description>description</c:calendar-description>
|
7
|
-
</d:prop>
|
8
|
-
</d:set>
|
9
|
-
</d:propertyupdate>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<d:propertyupdate xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav">
|
3
|
+
<d:set>
|
4
|
+
<d:prop>
|
5
|
+
<d:displayname>name</d:displayname>
|
6
|
+
<c:calendar-description>description</c:calendar-description>
|
7
|
+
</d:prop>
|
8
|
+
</d:set>
|
9
|
+
</d:propertyupdate>
|
@@ -1,8 +1,8 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<d:propertyupdate xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">
|
3
|
-
<d:set>
|
4
|
-
<d:prop>
|
5
|
-
<cs:objectOwner>principals/usertest</cs:objectOwner>
|
6
|
-
</d:prop>
|
7
|
-
</d:set>
|
8
|
-
</d:propertyupdate>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<d:propertyupdate xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">
|
3
|
+
<d:set>
|
4
|
+
<d:prop>
|
5
|
+
<cs:objectOwner>principals/usertest</cs:objectOwner>
|
6
|
+
</d:prop>
|
7
|
+
</d:set>
|
8
|
+
</d:propertyupdate>
|
@@ -1,9 +1,9 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<d:propertyupdate xmlns:d="DAV:" xmlns:sb="http://sabredav.org/ns">
|
3
|
-
<d:set>
|
4
|
-
<d:prop>
|
5
|
-
<sb:email-address>update@test.de</sb:email-address>
|
6
|
-
<d:displayname>David B.</d:displayname>
|
7
|
-
</d:prop>
|
8
|
-
</d:set>
|
9
|
-
</d:propertyupdate>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<d:propertyupdate xmlns:d="DAV:" xmlns:sb="http://sabredav.org/ns">
|
3
|
+
<d:set>
|
4
|
+
<d:prop>
|
5
|
+
<sb:email-address>update@test.de</sb:email-address>
|
6
|
+
<d:displayname>David B.</d:displayname>
|
7
|
+
</d:prop>
|
8
|
+
</d:set>
|
9
|
+
</d:propertyupdate>
|
@@ -1,8 +1,8 @@
|
|
1
|
-
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
-
<d:sync-collection xmlns:d="DAV:">
|
3
|
-
<d:sync-token>token-1234</d:sync-token>
|
4
|
-
<d:sync-level>1</d:sync-level>
|
5
|
-
<d:prop>
|
6
|
-
<d:getetag/>
|
7
|
-
</d:prop>
|
8
|
-
</d:sync-collection>
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<d:sync-collection xmlns:d="DAV:">
|
3
|
+
<d:sync-token>token-1234</d:sync-token>
|
4
|
+
<d:sync-level>1</d:sync-level>
|
5
|
+
<d:prop>
|
6
|
+
<d:getetag/>
|
7
|
+
</d:prop>
|
8
|
+
</d:sync-collection>
|
@@ -1,142 +1,142 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SabredavClient::Calendar do
|
4
|
-
|
5
|
-
let(:calendar) { SabredavClient::Calendar.new(:uri => "http://localhost:5232/user/calendar", :user => "user" , :password => "") }
|
6
|
-
|
7
|
-
describe "initialization" do
|
8
|
-
|
9
|
-
it "check Class of new calendar" do
|
10
|
-
expect(calendar).to be_a(SabredavClient::Calendar)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "request configuration is available" do
|
14
|
-
expect(calendar.client).to be_a(SabredavClient::Client)
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
describe "events" do
|
20
|
-
|
21
|
-
it "events returns Events class" do
|
22
|
-
expect(calendar.events).to be_a(SabredavClient::Events)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
describe "calendar" do
|
27
|
-
|
28
|
-
it "create" do
|
29
|
-
displayname = "Test Calendar"
|
30
|
-
ctag = "http://sabre.io/ns/sync/15"
|
31
|
-
sync_token = ctag
|
32
|
-
|
33
|
-
FakeWeb.register_uri(:mkcalendar, %r{http://user@localhost:5232/user/calendar}, status: ["201", "Created"])
|
34
|
-
FakeWeb.register_uri(:propfind, %r{http://user@localhost:5232/user/calendar}, status: ["200", "OK"], body: File.open("spec/fixtures/calendar_info.xml"))
|
35
|
-
|
36
|
-
r = calendar.create(displayname: displayname)
|
37
|
-
|
38
|
-
expect(r[:displayname]).to eq(displayname)
|
39
|
-
expect(r[:ctag]).to eq(ctag)
|
40
|
-
expect(r[:sync_token]).to eq(sync_token)
|
41
|
-
end
|
42
|
-
|
43
|
-
it "update" do
|
44
|
-
description = "a example description"
|
45
|
-
displayname = "example discription"
|
46
|
-
body = SabredavClient::XmlRequestBuilder::ProppatchCalendar.new(displayname, description).to_xml
|
47
|
-
header = {content_type: "application/xml"}
|
48
|
-
|
49
|
-
FakeWeb.register_uri(:proppatch, "http://user@localhost:5232/user/calendar/", status: ["207", "Multi-Staus"])
|
50
|
-
|
51
|
-
expect(calendar.client).to receive(:create_request).with(:proppatch, header: header, body: body).and_call_original
|
52
|
-
|
53
|
-
r = calendar.update(displayname: displayname, description: description)
|
54
|
-
expect(r).to be
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
it "delete" do
|
59
|
-
FakeWeb.register_uri(:delete, "http://user@localhost:5232/user/calendar/",
|
60
|
-
[{status: ["204", "No Content"]}, {status: ["404", "Not Found"]}])
|
61
|
-
r = calendar.delete
|
62
|
-
expect(r).to be(true)
|
63
|
-
|
64
|
-
expect {
|
65
|
-
calendar.delete
|
66
|
-
}.to raise_error(SabredavClient::Errors::NotFoundError)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe "sharing" do
|
71
|
-
FakeWeb.register_uri(:post, "http://user@localhost:5232/user/calendar/", [{status: ["200", "OK"]},
|
72
|
-
{status: ["200", "OK"]}])
|
73
|
-
it "is type email" do
|
74
|
-
type = :email
|
75
|
-
r = calendar.share adds: ["test@test.de"], privilege: "write-read"
|
76
|
-
expect(r).to be(true)
|
77
|
-
end
|
78
|
-
|
79
|
-
it "is not type email" do
|
80
|
-
type = :other
|
81
|
-
expect {
|
82
|
-
calendar.share adds: ["test@test.de"], privilege: "write-read", type: type
|
83
|
-
}.to raise_error(SabredavClient::Errors::ShareeTypeNotSupportedError)
|
84
|
-
end
|
85
|
-
|
86
|
-
it "add one share" do
|
87
|
-
r = calendar.share(adds: ["test@test.de"], privilege: "write-read")
|
88
|
-
expect(r).to be(true)
|
89
|
-
end
|
90
|
-
|
91
|
-
it "fetch_sharees" do
|
92
|
-
FakeWeb.register_uri(:propfind, "http://user@localhost:5232/user/calendar/", body: File.open('spec/fixtures/calendar_sharees.xml') )
|
93
|
-
|
94
|
-
organizer = {href: "/caldav/server.php/principals/user", uri: "D8D498E2-4A98-4DC7-B421-BC49261168AF"}
|
95
|
-
sharees =
|
96
|
-
[{href: "mailto:sharee1@njiuko.com", common_name: "sharee1", access: "read", status: :accepted, uri: "5bffa09e-7220-4688-a13f-088714a98783", principal: nil},
|
97
|
-
{href: "mailto:sharee2@protonet.info", common_name: "sharee2", access: "write-read", status: :accepted, uri: "f176b400-f0e4-4a57-bd92-0c307810ce12", principal: nil}]
|
98
|
-
expected_result = {sharees: sharees, organizer: organizer}
|
99
|
-
|
100
|
-
r = calendar.fetch_sharees
|
101
|
-
expect(r).to eq(expected_result)
|
102
|
-
end
|
103
|
-
|
104
|
-
context "errors" do
|
105
|
-
it "deals with missing common name" do
|
106
|
-
FakeWeb.register_uri(:propfind, "http://user@localhost:5232/user/calendar/", body: File.open('spec/fixtures/calendar_sharees_without_common_name.xml') )
|
107
|
-
|
108
|
-
organizer = {href: "/caldav/server.php/principals/user", uri: "D8D498E2-4A98-4DC7-B421-BC49261168AF"}
|
109
|
-
sharees = [{href: "mailto:sharee2@protonet.info", common_name: nil, access: "write-read", status: :accepted, uri: "f176b400-f0e4-4a57-bd92-0c307810ce12", principal: "principal/user99"}]
|
110
|
-
expected_result = {sharees: sharees, organizer: organizer}
|
111
|
-
|
112
|
-
r = calendar.fetch_sharees
|
113
|
-
expect(r).to eq(expected_result)
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe "info" do
|
119
|
-
it "fetches the calendar info" do
|
120
|
-
FakeWeb.register_uri(:propfind, "http://user@localhost:5232/user/calendar/", body: File.open('spec/fixtures/calendar_info.xml') )
|
121
|
-
info = calendar.info
|
122
|
-
|
123
|
-
expect(info[:displayname]).to eq("Test Calendar")
|
124
|
-
expect(info[:ctag]).to eq("http://sabre.io/ns/sync/15")
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
describe "fetch changes" do
|
129
|
-
new_sync_token = "http://sabredav.org/ns/sync/5001"
|
130
|
-
deletions = [ "deletedevent.ics" ]
|
131
|
-
changes = [ {uri: "newevent.ics", etag: "
|
132
|
-
|
133
|
-
it "got two changes and one deletion" do
|
134
|
-
FakeWeb.register_uri(:report, "http://user@localhost:5232/user/calendar/", body: File.open('spec/fixtures/calendar_fetch_changes.xml') )
|
135
|
-
result = calendar.fetch_changes("random_token")
|
136
|
-
expect(result[:deletions]).to eq deletions
|
137
|
-
expect(result[:changes]).to eq changes
|
138
|
-
expect(result[:sync_token]).to eq new_sync_token
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SabredavClient::Calendar do
|
4
|
+
|
5
|
+
let(:calendar) { SabredavClient::Calendar.new(:uri => "http://localhost:5232/user/calendar", :user => "user" , :password => "") }
|
6
|
+
|
7
|
+
describe "initialization" do
|
8
|
+
|
9
|
+
it "check Class of new calendar" do
|
10
|
+
expect(calendar).to be_a(SabredavClient::Calendar)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "request configuration is available" do
|
14
|
+
expect(calendar.client).to be_a(SabredavClient::Client)
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "events" do
|
20
|
+
|
21
|
+
it "events returns Events class" do
|
22
|
+
expect(calendar.events).to be_a(SabredavClient::Events)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "calendar" do
|
27
|
+
|
28
|
+
it "create" do
|
29
|
+
displayname = "Test Calendar"
|
30
|
+
ctag = "http://sabre.io/ns/sync/15"
|
31
|
+
sync_token = ctag
|
32
|
+
|
33
|
+
FakeWeb.register_uri(:mkcalendar, %r{http://user@localhost:5232/user/calendar}, status: ["201", "Created"])
|
34
|
+
FakeWeb.register_uri(:propfind, %r{http://user@localhost:5232/user/calendar}, status: ["200", "OK"], body: File.open("spec/fixtures/calendar_info.xml"))
|
35
|
+
|
36
|
+
r = calendar.create(displayname: displayname)
|
37
|
+
|
38
|
+
expect(r[:displayname]).to eq(displayname)
|
39
|
+
expect(r[:ctag]).to eq(ctag)
|
40
|
+
expect(r[:sync_token]).to eq(sync_token)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "update" do
|
44
|
+
description = "a example description"
|
45
|
+
displayname = "example discription"
|
46
|
+
body = SabredavClient::XmlRequestBuilder::ProppatchCalendar.new(displayname, description).to_xml
|
47
|
+
header = {content_type: "application/xml"}
|
48
|
+
|
49
|
+
FakeWeb.register_uri(:proppatch, "http://user@localhost:5232/user/calendar/", status: ["207", "Multi-Staus"])
|
50
|
+
|
51
|
+
expect(calendar.client).to receive(:create_request).with(:proppatch, header: header, body: body).and_call_original
|
52
|
+
|
53
|
+
r = calendar.update(displayname: displayname, description: description)
|
54
|
+
expect(r).to be
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
it "delete" do
|
59
|
+
FakeWeb.register_uri(:delete, "http://user@localhost:5232/user/calendar/",
|
60
|
+
[{status: ["204", "No Content"]}, {status: ["404", "Not Found"]}])
|
61
|
+
r = calendar.delete
|
62
|
+
expect(r).to be(true)
|
63
|
+
|
64
|
+
expect {
|
65
|
+
calendar.delete
|
66
|
+
}.to raise_error(SabredavClient::Errors::NotFoundError)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "sharing" do
|
71
|
+
FakeWeb.register_uri(:post, "http://user@localhost:5232/user/calendar/", [{status: ["200", "OK"]},
|
72
|
+
{status: ["200", "OK"]}])
|
73
|
+
it "is type email" do
|
74
|
+
type = :email
|
75
|
+
r = calendar.share adds: ["test@test.de"], privilege: "write-read"
|
76
|
+
expect(r).to be(true)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "is not type email" do
|
80
|
+
type = :other
|
81
|
+
expect {
|
82
|
+
calendar.share adds: ["test@test.de"], privilege: "write-read", type: type
|
83
|
+
}.to raise_error(SabredavClient::Errors::ShareeTypeNotSupportedError)
|
84
|
+
end
|
85
|
+
|
86
|
+
it "add one share" do
|
87
|
+
r = calendar.share(adds: ["test@test.de"], privilege: "write-read")
|
88
|
+
expect(r).to be(true)
|
89
|
+
end
|
90
|
+
|
91
|
+
it "fetch_sharees" do
|
92
|
+
FakeWeb.register_uri(:propfind, "http://user@localhost:5232/user/calendar/", body: File.open('spec/fixtures/calendar_sharees.xml') )
|
93
|
+
|
94
|
+
organizer = {href: "/caldav/server.php/principals/user", uri: "D8D498E2-4A98-4DC7-B421-BC49261168AF"}
|
95
|
+
sharees =
|
96
|
+
[{href: "mailto:sharee1@njiuko.com", common_name: "sharee1", access: "read", status: :accepted, uri: "5bffa09e-7220-4688-a13f-088714a98783", principal: nil},
|
97
|
+
{href: "mailto:sharee2@protonet.info", common_name: "sharee2", access: "write-read", status: :accepted, uri: "f176b400-f0e4-4a57-bd92-0c307810ce12", principal: nil}]
|
98
|
+
expected_result = {sharees: sharees, organizer: organizer}
|
99
|
+
|
100
|
+
r = calendar.fetch_sharees
|
101
|
+
expect(r).to eq(expected_result)
|
102
|
+
end
|
103
|
+
|
104
|
+
context "errors" do
|
105
|
+
it "deals with missing common name" do
|
106
|
+
FakeWeb.register_uri(:propfind, "http://user@localhost:5232/user/calendar/", body: File.open('spec/fixtures/calendar_sharees_without_common_name.xml') )
|
107
|
+
|
108
|
+
organizer = {href: "/caldav/server.php/principals/user", uri: "D8D498E2-4A98-4DC7-B421-BC49261168AF"}
|
109
|
+
sharees = [{href: "mailto:sharee2@protonet.info", common_name: nil, access: "write-read", status: :accepted, uri: "f176b400-f0e4-4a57-bd92-0c307810ce12", principal: "principal/user99"}]
|
110
|
+
expected_result = {sharees: sharees, organizer: organizer}
|
111
|
+
|
112
|
+
r = calendar.fetch_sharees
|
113
|
+
expect(r).to eq(expected_result)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe "info" do
|
119
|
+
it "fetches the calendar info" do
|
120
|
+
FakeWeb.register_uri(:propfind, "http://user@localhost:5232/user/calendar/", body: File.open('spec/fixtures/calendar_info.xml') )
|
121
|
+
info = calendar.info
|
122
|
+
|
123
|
+
expect(info[:displayname]).to eq("Test Calendar")
|
124
|
+
expect(info[:ctag]).to eq("http://sabre.io/ns/sync/15")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "fetch changes" do
|
129
|
+
new_sync_token = "http://sabredav.org/ns/sync/5001"
|
130
|
+
deletions = [ "deletedevent.ics" ]
|
131
|
+
changes = [ {uri: "newevent.ics", etag: "1"}, {uri: "updatedevent.ics", etag: "2"}]
|
132
|
+
|
133
|
+
it "got two changes and one deletion" do
|
134
|
+
FakeWeb.register_uri(:report, "http://user@localhost:5232/user/calendar/", body: File.open('spec/fixtures/calendar_fetch_changes.xml') )
|
135
|
+
result = calendar.fetch_changes("random_token")
|
136
|
+
expect(result[:deletions]).to eq deletions
|
137
|
+
expect(result[:changes]).to eq changes
|
138
|
+
expect(result[:sync_token]).to eq new_sync_token
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
@@ -1,41 +1,41 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SabredavClient::Client do
|
4
|
-
|
5
|
-
let!(:client) { SabredavClient::Client.new(:uri => "http://localhost:5232/user/principals/user", :user => "user" , :password => "" ) }
|
6
|
-
|
7
|
-
describe "initialization" do
|
8
|
-
|
9
|
-
it "no encryption and basic_auth" do
|
10
|
-
#TODO
|
11
|
-
end
|
12
|
-
|
13
|
-
it "with ssl and basic authentification" do
|
14
|
-
client = SabredavClient::Client.new(:uri => "https://localhost:5232/user/principals/user", :user => "user" , :password => "" )
|
15
|
-
|
16
|
-
expect(client.host).to be
|
17
|
-
expect(client.port).to be
|
18
|
-
expect(client.user).to be
|
19
|
-
expect(client.base_path).to be
|
20
|
-
expect(client.ssl).to be
|
21
|
-
expect(client.password).to be
|
22
|
-
expect(client.authtype).to eq("basic")
|
23
|
-
end
|
24
|
-
|
25
|
-
it "proxy usage" do
|
26
|
-
#TODO
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe "create_request" do
|
31
|
-
|
32
|
-
it " with header and body" do
|
33
|
-
method = :report
|
34
|
-
body = "xml_file"
|
35
|
-
header = {content_type: "application/xml"}
|
36
|
-
res = client.create_request(method, header: header, body: body)
|
37
|
-
expect(res.request.body).to eq(body)
|
38
|
-
expect(res.request.to_hash).to include("content-type" => ["application/xml"])
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SabredavClient::Client do
|
4
|
+
|
5
|
+
let!(:client) { SabredavClient::Client.new(:uri => "http://localhost:5232/user/principals/user", :user => "user" , :password => "" ) }
|
6
|
+
|
7
|
+
describe "initialization" do
|
8
|
+
|
9
|
+
it "no encryption and basic_auth" do
|
10
|
+
#TODO
|
11
|
+
end
|
12
|
+
|
13
|
+
it "with ssl and basic authentification" do
|
14
|
+
client = SabredavClient::Client.new(:uri => "https://localhost:5232/user/principals/user", :user => "user" , :password => "" )
|
15
|
+
|
16
|
+
expect(client.host).to be
|
17
|
+
expect(client.port).to be
|
18
|
+
expect(client.user).to be
|
19
|
+
expect(client.base_path).to be
|
20
|
+
expect(client.ssl).to be
|
21
|
+
expect(client.password).to be
|
22
|
+
expect(client.authtype).to eq("basic")
|
23
|
+
end
|
24
|
+
|
25
|
+
it "proxy usage" do
|
26
|
+
#TODO
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "create_request" do
|
31
|
+
|
32
|
+
it " with header and body" do
|
33
|
+
method = :report
|
34
|
+
body = "xml_file"
|
35
|
+
header = {content_type: "application/xml"}
|
36
|
+
res = client.create_request(method, header: header, body: body)
|
37
|
+
expect(res.request.body).to eq(body)
|
38
|
+
expect(res.request.to_hash).to include("content-type" => ["application/xml"])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -1,119 +1,119 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe SabredavClient::Events do
|
4
|
-
client = SabredavClient::Client.new(uri: "http://localhost:5232/user/calendar", user: "user", password: "")
|
5
|
-
let!(:events) { described_class.new(client = client) }
|
6
|
-
|
7
|
-
describe "initialization" do
|
8
|
-
|
9
|
-
it "client" do
|
10
|
-
|
11
|
-
expect(events.client).to be_a(SabredavClient::Client)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe "delete" do
|
16
|
-
|
17
|
-
it "one event" do
|
18
|
-
uri = "event.ics"
|
19
|
-
FakeWeb.register_uri(:delete, "http://user@localhost:5232/user/calendar/#{uri}",
|
20
|
-
[{:body => "1 deleted.", :status => ["200", "OK"]}])
|
21
|
-
r = events.delete(uri)
|
22
|
-
|
23
|
-
expect(r).to be(true)
|
24
|
-
end
|
25
|
-
|
26
|
-
context "error" do
|
27
|
-
it "raises error if etag not includes .ics" do
|
28
|
-
uri = nil
|
29
|
-
|
30
|
-
expect {
|
31
|
-
events.delete(uri)
|
32
|
-
}.to raise_error(SabredavClient::Errors::SabredavClientError)
|
33
|
-
|
34
|
-
uri = "x-vvvvvv-sssss-2122222-xssw"
|
35
|
-
|
36
|
-
expect {
|
37
|
-
events.delete(uri)
|
38
|
-
}.to raise_error(SabredavClient::Errors::SabredavClientError)
|
39
|
-
end
|
40
|
-
|
41
|
-
it "it raises error NotFoundError if resource was not found" do
|
42
|
-
uri = "event.ics"
|
43
|
-
FakeWeb.register_uri(:delete, "http://user@localhost:5232/user/calendar/#{uri}",
|
44
|
-
[{:body => "not found", :status => ["404", "Not Found"]}])
|
45
|
-
expect {
|
46
|
-
events.delete(uri)
|
47
|
-
}.to raise_error(SabredavClient::Errors::NotFoundError)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe "find one event" do
|
53
|
-
|
54
|
-
it "one event" do
|
55
|
-
uid = "47732F70-1793-47B3-80FA-57E3C5ECA0E5"
|
56
|
-
uri = "#{uid}.ics"
|
57
|
-
|
58
|
-
etag = "6341a7e8f9a1f775dd07c55b17ff27b7"
|
59
|
-
|
60
|
-
expected_result = {etag: etag, ics: File.open("spec/fixtures/event.ics").read}
|
61
|
-
|
62
|
-
FakeWeb.register_uri(:get, "http://user@localhost:5232/user/calendar/#{uri}", body: File.open("spec/fixtures/event.ics"), etag: etag )
|
63
|
-
r = events.find(uri)
|
64
|
-
|
65
|
-
expect(r).to eq(expected_result)
|
66
|
-
end
|
67
|
-
|
68
|
-
it "two events" do
|
69
|
-
FakeWeb.register_uri(:report, "http://user@localhost:5232/user/calendar/", body: File.open('spec/fixtures/events_find_multiple.xml'))
|
70
|
-
r = events.find_multiple(starts: "2001-02-02 07:00", ends: "2000-02-03 23:59")
|
71
|
-
|
72
|
-
expect(r).to include("BEGIN:VCALENDAR")
|
73
|
-
expect(r).to include("UID:960232b0-371c-0130-9e6b-001999638982")
|
74
|
-
expect(r).to include("UID:98f067a0-371c-0130-9e6c-001999638982")
|
75
|
-
expect(r).to include("END:VCALENDAR")
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
describe "create_update" do
|
80
|
-
etag = "\"123\""
|
81
|
-
uri = "event.ics"
|
82
|
-
event_ics = File.open('spec/fixtures/event.ics')
|
83
|
-
|
84
|
-
it "create event" do
|
85
|
-
FakeWeb.register_uri(:put, "http://user@localhost:5232/user/calendar/#{uri}", {etag: etag, status: ["201", "OK"]})
|
86
|
-
r = events.create_update(uri, event_ics.to_s)
|
87
|
-
|
88
|
-
expect(r).to eq "123"
|
89
|
-
end
|
90
|
-
|
91
|
-
it "update event" do
|
92
|
-
new_etag = "124"
|
93
|
-
FakeWeb.register_uri(:put, "http://user@localhost:5232/user/calendar/#{uri}", {status: ["200", "OK"], etag: new_etag})
|
94
|
-
r = events.create_update(uri, event_ics.to_s, etag )
|
95
|
-
|
96
|
-
expect(r).not_to eq etag
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
describe "owner" do
|
101
|
-
uri = "event.ics"
|
102
|
-
|
103
|
-
it "find" do
|
104
|
-
owner = "principals/usertest"
|
105
|
-
FakeWeb.register_uri(:propfind, "http://user@localhost:5232/user/calendar/#{uri}", {status: ["200", "OK"], body: File.open("spec/fixtures/events_owner.xml")})
|
106
|
-
r = events.owner(uri)
|
107
|
-
|
108
|
-
expect(r).to eq(owner)
|
109
|
-
end
|
110
|
-
|
111
|
-
it "update" do
|
112
|
-
FakeWeb.register_uri(:proppatch, "http://user@localhost:5232/user/calendar/#{uri}", {status: ["200", "OK"]})
|
113
|
-
r = events.update_owner(uri, "principals/usertest")
|
114
|
-
|
115
|
-
expect(r).to be
|
116
|
-
end
|
117
|
-
|
118
|
-
end
|
119
|
-
end
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SabredavClient::Events do
|
4
|
+
client = SabredavClient::Client.new(uri: "http://localhost:5232/user/calendar", user: "user", password: "")
|
5
|
+
let!(:events) { described_class.new(client = client) }
|
6
|
+
|
7
|
+
describe "initialization" do
|
8
|
+
|
9
|
+
it "client" do
|
10
|
+
|
11
|
+
expect(events.client).to be_a(SabredavClient::Client)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "delete" do
|
16
|
+
|
17
|
+
it "one event" do
|
18
|
+
uri = "event.ics"
|
19
|
+
FakeWeb.register_uri(:delete, "http://user@localhost:5232/user/calendar/#{uri}",
|
20
|
+
[{:body => "1 deleted.", :status => ["200", "OK"]}])
|
21
|
+
r = events.delete(uri)
|
22
|
+
|
23
|
+
expect(r).to be(true)
|
24
|
+
end
|
25
|
+
|
26
|
+
context "error" do
|
27
|
+
it "raises error if etag not includes .ics" do
|
28
|
+
uri = nil
|
29
|
+
|
30
|
+
expect {
|
31
|
+
events.delete(uri)
|
32
|
+
}.to raise_error(SabredavClient::Errors::SabredavClientError)
|
33
|
+
|
34
|
+
uri = "x-vvvvvv-sssss-2122222-xssw"
|
35
|
+
|
36
|
+
expect {
|
37
|
+
events.delete(uri)
|
38
|
+
}.to raise_error(SabredavClient::Errors::SabredavClientError)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "it raises error NotFoundError if resource was not found" do
|
42
|
+
uri = "event.ics"
|
43
|
+
FakeWeb.register_uri(:delete, "http://user@localhost:5232/user/calendar/#{uri}",
|
44
|
+
[{:body => "not found", :status => ["404", "Not Found"]}])
|
45
|
+
expect {
|
46
|
+
events.delete(uri)
|
47
|
+
}.to raise_error(SabredavClient::Errors::NotFoundError)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "find one event" do
|
53
|
+
|
54
|
+
it "one event" do
|
55
|
+
uid = "47732F70-1793-47B3-80FA-57E3C5ECA0E5"
|
56
|
+
uri = "#{uid}.ics"
|
57
|
+
|
58
|
+
etag = "6341a7e8f9a1f775dd07c55b17ff27b7"
|
59
|
+
|
60
|
+
expected_result = {etag: etag, ics: File.open("spec/fixtures/event.ics").read}
|
61
|
+
|
62
|
+
FakeWeb.register_uri(:get, "http://user@localhost:5232/user/calendar/#{uri}", body: File.open("spec/fixtures/event.ics"), etag: etag )
|
63
|
+
r = events.find(uri)
|
64
|
+
|
65
|
+
expect(r).to eq(expected_result)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "two events" do
|
69
|
+
FakeWeb.register_uri(:report, "http://user@localhost:5232/user/calendar/", body: File.open('spec/fixtures/events_find_multiple.xml'))
|
70
|
+
r = events.find_multiple(starts: "2001-02-02 07:00", ends: "2000-02-03 23:59")
|
71
|
+
|
72
|
+
expect(r).to include("BEGIN:VCALENDAR")
|
73
|
+
expect(r).to include("UID:960232b0-371c-0130-9e6b-001999638982")
|
74
|
+
expect(r).to include("UID:98f067a0-371c-0130-9e6c-001999638982")
|
75
|
+
expect(r).to include("END:VCALENDAR")
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe "create_update" do
|
80
|
+
etag = "\"123\""
|
81
|
+
uri = "event.ics"
|
82
|
+
event_ics = File.open('spec/fixtures/event.ics')
|
83
|
+
|
84
|
+
it "create event" do
|
85
|
+
FakeWeb.register_uri(:put, "http://user@localhost:5232/user/calendar/#{uri}", {etag: etag, status: ["201", "OK"]})
|
86
|
+
r = events.create_update(uri, event_ics.to_s)
|
87
|
+
|
88
|
+
expect(r).to eq "123"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "update event" do
|
92
|
+
new_etag = "124"
|
93
|
+
FakeWeb.register_uri(:put, "http://user@localhost:5232/user/calendar/#{uri}", {status: ["200", "OK"], etag: new_etag})
|
94
|
+
r = events.create_update(uri, event_ics.to_s, etag )
|
95
|
+
|
96
|
+
expect(r).not_to eq etag
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "owner" do
|
101
|
+
uri = "event.ics"
|
102
|
+
|
103
|
+
it "find" do
|
104
|
+
owner = "principals/usertest"
|
105
|
+
FakeWeb.register_uri(:propfind, "http://user@localhost:5232/user/calendar/#{uri}", {status: ["200", "OK"], body: File.open("spec/fixtures/events_owner.xml")})
|
106
|
+
r = events.owner(uri)
|
107
|
+
|
108
|
+
expect(r).to eq(owner)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "update" do
|
112
|
+
FakeWeb.register_uri(:proppatch, "http://user@localhost:5232/user/calendar/#{uri}", {status: ["200", "OK"]})
|
113
|
+
r = events.update_owner(uri, "principals/usertest")
|
114
|
+
|
115
|
+
expect(r).to be
|
116
|
+
end
|
117
|
+
|
118
|
+
end
|
119
|
+
end
|