Merge lp:~elopio/ubuntuone-testing/add-photo into lp:ubuntuone-testing

Proposed by Leo Arias
Status: Merged
Approved by: Philip Fibiger
Approved revision: 119
Merged at revision: 108
Proposed branch: lp:~elopio/ubuntuone-testing/add-photo
Merge into: lp:ubuntuone-testing
Prerequisite: lp:~elopio/ubuntuone-testing/open-photos-tab
Diff against target: 129 lines (+68/-26)
3 files modified
ubuntuone/web/tests/sst/photos/u1webp83_addphoto.py (+32/-25)
ubuntuone/web/tests/sst/shared/actions/photos.py (+10/-1)
ubuntuone/web/tests/sst/shared/utils/randomphotos.py (+26/-0)
To merge this branch: bzr merge lp:~elopio/ubuntuone-testing/add-photo
Reviewer Review Type Date Requested Status
Philip Fibiger (community) Approve
Review via email: mp+115062@code.launchpad.net

Commit message

Added a utility function to create random photos.
Cleaned the add photo test.

Description of the change

Added a utility function to create random photos.
Cleaned the add photo test.

To post a comment you must log in.
Revision history for this message
Ubuntu One Auto Pilot (otto-pilot) wrote :

Voting does not meet specified criteria. Required: Approve >= 1, Disapprove == 0, Needs Fixing == 0, Needs Information == 0, Resubmit == 0, Pending == 0. Got: 1 Pending.

Revision history for this message
Philip Fibiger (pfibiger) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== renamed file 'ubuntuone/web/tests/sst/photos/u1p001_addphoto.py' => 'ubuntuone/web/tests/sst/photos/u1webp83_addphoto.py'
2--- ubuntuone/web/tests/sst/photos/u1p001_addphoto.py 2012-06-19 20:29:12 +0000
3+++ ubuntuone/web/tests/sst/photos/u1webp83_addphoto.py 2012-07-16 04:51:46 +0000
4@@ -1,33 +1,40 @@
5 # -*- coding: utf-8 -*-
6-# Copyright 2012 Canonical Ltd - All rights reserved
7
8-""" U1P001 Test to upload a photo. """
9+# Copyright 2012 Canonical Ltd.
10+#
11+# This program is free software: you can redistribute it and/or modify it
12+# under the terms of the GNU General Public License version 3, as published
13+# by the Free Software Foundation.
14+#
15+# This program is distributed in the hope that it will be useful, but
16+# WITHOUT ANY WARRANTY; without even the implied warranties of
17+# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
18+# PURPOSE. See the GNU General Public License for more details.
19+#
20+# You should have received a copy of the GNU General Public License along
21+# with this program. If not, see <http://www.gnu.org/licenses/>.
22
23 from sst.actions import *
24+from os import path, remove
25 import actions.setup as setup_actions
26 import actions.files as files_actions
27 import actions.photos as photos_actions
28-import os.path
29-from data.photos import test_files_path, file_name_orig, file_size
30-from data.user import User
31-try:
32- from _photopasswords import full_name, email, password
33-except:
34- skip('Try adding a _photopasswords.py file to the photos folder if you ' \
35- 'expect this to work. Read the README.txt file ;)')
36-
37-
38-test_user = User(full_name, email, password)
39-setup_actions.setup(user=test_user)
40-files_actions.open()
41-file_path_orig = test_files_path + file_name_orig
42-file_names = photos_actions.generate_unique_files(test_files_path,
43- file_name_orig, 1)
44-file_path_uniq = test_files_path + file_names[0]
45-files_actions.upload_file(os.path.abspath(file_path_uniq))
46-photos_actions.clean_test_file(os.path.abspath(file_path_uniq))
47-files_actions.open() # refresh because edge is broken.
48-files_actions.assert_file_exists(file_names[0])
49-assert files_actions.get_file_size(file_names[0]) == file_size
50+from utils.randomphotos import make_random_photo_and_return_path
51+import uuid
52+import tempfile
53+import numpy
54+import Image
55+
56+setup_actions.setup(new_user=False)
57+
58+random_photo_path = make_random_photo_and_return_path()
59+files_actions.open()
60+files_actions.upload_file(random_photo_path)
61+remove(random_photo_path)
62+random_photo_name = path.basename(random_photo_path)
63+# XXX refresh because there is a bug in edge server.
64+# See https://bugs.launchpad.net/ubuntuone-servers/+bug/1007147
65+files_actions.open()
66+files_actions.assert_file_exists(random_photo_name)
67 photos_actions.open()
68-photos_actions.assert_photo_is_displayed_on_gallery(file_names[0])
69+photos_actions.assert_photo_present_in_list(random_photo_name)
70
71=== modified file 'ubuntuone/web/tests/sst/shared/actions/photos.py'
72--- ubuntuone/web/tests/sst/shared/actions/photos.py 2012-07-16 04:51:46 +0000
73+++ ubuntuone/web/tests/sst/shared/actions/photos.py 2012-07-16 04:51:46 +0000
74@@ -28,7 +28,6 @@
75 def open():
76 click_photos_tab()
77 switch_to_window()
78- assert_page_title()
79
80
81 def click_photos_tab():
82@@ -48,6 +47,16 @@
83 assert_text(heading1_element, folder_name)
84
85
86+def assert_photo_present_in_list(photo_name):
87+ photo_element = _get_photo_element_in_list(photo_name)
88+ assert_displayed(photo_element)
89+
90+
91+def _get_photo_element_in_list(photo_name):
92+ return get_element('.photo-list img.scaled[data-qa-id="%(name)s"]'
93+ % {'name': photo_name})
94+
95+
96 def _get_md5(filename):
97 """ get md5 checksum of file 'filename'. """
98 m = hashlib.md5()
99
100=== added file 'ubuntuone/web/tests/sst/shared/utils/randomphotos.py'
101--- ubuntuone/web/tests/sst/shared/utils/randomphotos.py 1970-01-01 00:00:00 +0000
102+++ ubuntuone/web/tests/sst/shared/utils/randomphotos.py 2012-07-16 04:51:46 +0000
103@@ -0,0 +1,26 @@
104+# -*- coding: utf-8 -*-
105+
106+"""Thanks to heltonbiker for the code to generate the random image.
107+See http://stackoverflow.com/a/10901092
108+
109+As part of the code for this file was copied from stackoverflow,
110+it has a CC-BY-SA 3.0 license.
111+
112+"""
113+
114+import numpy
115+import Image
116+import tempfile
117+import uuid
118+
119+def make_random_photo_and_return_path():
120+ photo_uuid = str(uuid.uuid1())
121+ photo_path = None
122+ random_matrix = numpy.random.rand(200, 200, 3) * 255
123+ random_uint8_matrix = random_matrix.astype('uint8')
124+ image = Image.fromarray(random_uint8_matrix).convert('RGBA')
125+ photo = tempfile.NamedTemporaryFile(mode='wr', prefix='Random photo ',
126+ suffix=photo_uuid + '.jpg', delete=False)
127+ image.save(photo)
128+ photo.close
129+ return photo.name

Subscribers

People subscribed via source and target branches