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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/ape/validators/entry_posts_validator.rb', line 6
def validate(opts = {})
entry_collection = opts[:entry_collection]
reporter.info(self, "Will use collection '#{entry_collection.title}' for entry creation.")
collection_uri = entry_collection.href
entries = Feed.read(collection_uri, 'Entry collection', reporter)
reporter.info(self, "TESTING: Entry-posting basics.")
ids = []
unless entries.empty?
reporter.start_list(self, "Now in the Entries feed")
entries.each do |entry|
reporter.list_item(entry.summarize)
ids << entry.child_content('id')
end
end
poster = Poster.new(collection_uri, @authent)
if poster.last_error
reporter.error(self, "Unacceptable URI for '#{entry_collection.title}' collection: " +
poster.last_error)
return
end
my_entry = Entry.new(:text => Samples.basic_entry)
slug_num = rand(100000)
slug = "ape-#{slug_num}"
slug_re = %r{ape.?#{slug_num}}
poster.('Slug', slug)
@cats = Categories.add_cats(my_entry, entry_collection, @authent, reporter)
worked = poster.post(Names::AtomEntryMediaType, my_entry.to_s)
name = 'Posting new entry'
reporter.save_dialog(name, poster)
if !worked
reporter.error(self, "Can't POST new entry: #{poster.last_error}", name)
return
end
location = poster.('Location')
unless location
reporter.error(self, "No Location header upon POST creation", name)
return
end
reporter.success(self, "Posting of new entry to the Entries collection " +
"reported success, Location: #{location}", name)
reporter.info(self, "Examining the new entry as returned in the POST response")
check_new_entry(my_entry, poster.entry, "Returned entry") if poster.entry
name = "Retrieval of newly created entry"
new_entry = check_resource(location, name, Names::AtomMediaType)
return unless new_entry
etag = new_entry. 'etag'
reporter.info(self, "Examining the new entry as retrieved using Location header in POST response:")
begin
new_entry = Entry.new(:text => new_entry.body, :uri => location)
rescue REXML::ParseException
prob = $!.to_s.gsub(/\n/, '<br/>')
reporter.error(self, "New entry is not well-formed: #{prob}")
return
end
slug_used = false
new_entry.alt_links.each do |a|
href = a.attributes['href']
if href && href.index(slug_re)
slug_used = true
end
end
if slug_used
reporter.success(self, "Client-provided slug '#{slug}' was used in server-generated URI.")
else
reporter.warning(self, "Client-provided slug '#{slug}' not used in server-generated URI.")
end
check_new_entry(my_entry, new_entry, "Retrieved entry")
entry_id = new_entry.child_content('id')
from_feed = find_entry(collection_uri, "entry collection", entry_id)
if from_feed.class == String
Feed.read(collection_uri, "Can't find entry in collection", reporter)
reporter.error(self, "New entry didn't show up in the collections feed.")
return
end
reporter.info(self, "Examining the new entry as it appears in the collection feed:")
check_new_entry(my_entry, from_feed, "Entry from collection feed")
edit_uri = new_entry.link('edit', self)
if !edit_uri
reporter.error(self, "Entry from Location header has no edit link.")
return
end
name = 'In-place update with put'
putter = Putter.new(edit_uri, @authent)
putter.('If-Match', etag) if etag
new_title = "Let’s all do the Ape!"
new_text = Samples.retitled_entry(new_title, entry_id)
response = putter.put(Names::AtomEntryMediaType, new_text)
reporter.save_dialog(name, putter)
if response
reporter.success(self, "Update of new entry reported success.", name)
from_feed = find_entry(collection_uri, "entry collection", entry_id)
if from_feed.class == String
check_resource(collection_uri, "Check collection after lost update")
reporter.error(self, "Updated entry ID #{entry_id} not found in entries collection.")
return
end
if from_feed.child_content('title') == new_title
reporter.success(self, "Title of new entry successfully updated.")
else
reporter.warning(self, "After PUT update of title, Expected " +
"'#{new_title}', but saw '#{from_feed.child_content('title')}'")
end
else
reporter.warning(self,"Can't update new entry with PUT: #{putter.last_error}", name)
end
return unless delete_entry(from_feed, 'New Entry deletion')
still_there = find_entry(collection_uri, "entry collection", entry_id)
if still_there.class != String
reporter.error(self, "Entry is still in collection post-deletion.")
else
reporter.success(self, "Entry not found in feed after deletion.")
end
end
|