Skip to content

Commit 5c55898

Browse files
author
Martin Kraft
committed
Updated the testing to use a yaml config file.
1 parent 39dd9b9 commit 5c55898

File tree

8 files changed

+134
-83
lines changed

8 files changed

+134
-83
lines changed

lib/repositories/albums_repository.rb

+22-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ def get_album_by_slug(slug)
4343
return album_to_return
4444
end
4545

46-
def create_album(album)
47-
entry = "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gphoto='http://schemas.google.com/photos/2007'><title type='text'>#{album.title}</title><summary type='text'>#{album.description}</summary><gphoto:location></gphoto:location><gphoto:access>#{album.access}</gphoto:access><gphoto:timestamp></gphoto:timestamp><media:group><media:keywords></media:keywords></media:group><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#album'></category></entry>"
48-
post_new_album(entry)
46+
def create_album(new_album)
47+
atom = get_album_atom(new_album)
48+
post_new_album(atom)
4949
end
5050

5151
def delete_album_by_id(album_id)
@@ -60,8 +60,27 @@ def delete_album_by_id(album_id)
6060
return res.code
6161
end
6262

63+
#def update_album(modified_album)
64+
# atom = get_album_atom(modified_album)
65+
# uri = URI(modified_album.edit_url)
66+
# status = ""
67+
# Net::HTTP.start(uri.host, uri.port, :use_ssl => uri.scheme == 'https') do |http|
68+
# request = Net::HTTP::Put.new uri.request_uri
69+
# request['Authorization'] = @authentication_token
70+
# request['Content-Type'] = "application/atom+xml; charset=UTF-8; type=entry"
71+
# request.body = atom
72+
# response = http.request(request)
73+
# status = response.code
74+
# end
75+
# return status
76+
#end
77+
6378
private
6479

80+
def get_album_atom(album)
81+
return "<entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gphoto='http://schemas.google.com/photos/2007'><title type='text'>#{album.title}</title><summary type='text'>#{album.description}</summary><gphoto:location></gphoto:location><gphoto:access>#{album.access}</gphoto:access><gphoto:timestamp></gphoto:timestamp><media:group><media:keywords></media:keywords></media:group><category scheme='http://schemas.google.com/g/2005#kind' term='http://schemas.google.com/photos/2007#album'></category></entry>"
82+
end
83+
6584
def get_edit_url_from_entry(entry)
6685
href = ""
6786
entry.elements.each("link") do |link|

test/config/test_account.yml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
password: ruhak23A
3+
number_of_albums: 3
4+
album:
5+
title: Bio Profile Pics
6+
id: "5689734429356072049"
7+
slug: BioProfilePics
8+
number_of_photos: 1
9+
photo:
10+
id: "5689734429327880498"
11+
caption: Testing!!!?
12+
tag: baloney

test/integration/test_albums.rb

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
require 'test/unit'
2+
require_relative '../../lib/picasawebalbums'
3+
4+
module PicasaWebAlbums
5+
class TestAlbums < Test::Unit::TestCase
6+
7+
def setup
8+
@test_account = YAML::load(File.open(File.expand_path('test/config/test_account.yml')))
9+
@repo = PicasaWebAlbums.get_repository('[email protected]', 'ruhak23A')
10+
end
11+
12+
def test_get_all_albums
13+
albums = @repo.get_all_albums
14+
assert_equal @test_account["number_of_albums"], albums.count
15+
end
16+
17+
def test_get_album_by_id
18+
album = @repo.get_album_by_id(@test_account["album"]["id"])
19+
assert_equal @test_account["album"]["title"], album.title
20+
end
21+
22+
def test_get_album_by_title
23+
album = @repo.get_album_by_title(@test_account["album"]["title"])
24+
assert_equal @test_account["album"]["id"], album.id
25+
end
26+
27+
def test_get_album_by_slug
28+
album = @repo.get_album_by_slug(@test_account["album"]["slug"])
29+
assert_equal @test_account["album"]["id"], album.id
30+
end
31+
32+
def test_create_new_album
33+
album = Album.new
34+
album.title = "Programmatic album title"
35+
album.description = "This is my programmatic album description!"
36+
album.access = "private"
37+
status_code = @repo.create_album(album)
38+
assert_equal "201", status_code
39+
#update_album(album.title)
40+
delete_album
41+
end
42+
43+
private
44+
45+
def update_album(album_title)
46+
album = @repo.get_album_by_title(album_title)
47+
new_description = "Some new description"
48+
album.description = new_description
49+
@repo.update_album(album)
50+
album_retrieved = @repo.get_album_by_title("Programmatic album title")
51+
assert_equal new_description, album_retrieved.description
52+
end
53+
54+
def delete_album
55+
album = @repo.get_album_by_title("Programmatic album title")
56+
if (album != nil)
57+
status_code = @repo.delete_album_by_id(album.id)
58+
assert_equal "200", status_code
59+
end
60+
end
61+
62+
end
63+
end

test/integration/test_photos.rb

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'test/unit'
2+
require 'yaml'
3+
require_relative '../../lib/picasawebalbums'
4+
5+
module PicasaWebAlbums
6+
class TestPhotos < Test::Unit::TestCase
7+
8+
def setup
9+
@test_account = YAML::load(File.open(File.expand_path('test/config/test_account.yml')))
10+
@repo = PicasaWebAlbums.get_repository(@test_account["email"], @test_account["password"])
11+
end
12+
13+
def test_get_photos_from_album
14+
album = @repo.get_album_by_id(@test_account["album"]["id"])
15+
photos = @repo.get_photos_by_album_id(album.id)
16+
assert_equal photos.count, @test_account["album"]["number_of_photos"]
17+
end
18+
19+
def test_get_photo_by_album_and_id
20+
album = @repo.get_album_by_slug(@test_account["album"]["slug"])
21+
photo = @repo.get_photo_by_album_id_and_photo_id(album.id, @test_account["album"]["photo"]["id"])
22+
assert_equal @test_account["album"]["photo"]["caption"], photo.caption
23+
end
24+
25+
def test_get_photos_by_tags
26+
tags_array = Array.new(1, @test_account["album"]["photo"]["tag"])
27+
photos = @repo.get_photos_by_tags(tags_array)
28+
assert_equal photos.count, @test_account["album"]["number_of_photos"]
29+
end
30+
31+
end
32+
end

test/test_tags.rb renamed to test/integration/test_tags.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
require 'test/unit'
22
require 'shoulda'
3-
require_relative '../lib/picasawebalbums'
3+
require_relative '../../lib/picasawebalbums'
44

55
module PicasaWebAlbums
66
class TestTags < Test::Unit::TestCase
77

88
def setup
9+
@test_account = YAML::load(File.open(File.expand_path('test/config/test_account.yml')))
910
@repo = PicasaWebAlbums.get_repository('[email protected]', 'ruhak23A')
1011
end
1112

test/test_albums.rb

-50
This file was deleted.

test/test_photos.rb

-29
This file was deleted.

test/tests.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
require_relative 'integration/test_albums'
2+
require_relative 'integration/test_photos'
3+
require_relative 'integration/test_tags'

0 commit comments

Comments
 (0)