Skip to content
This repository has been archived by the owner on May 10, 2019. It is now read-only.

Commit

Permalink
Sets created during pass one shouldn't be created again at the end
Browse files Browse the repository at this point in the history
Add a test for this too. Fixes issue 35.
  • Loading branch information
richq committed Sep 6, 2014
1 parent acecacb commit 440795a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
4 changes: 3 additions & 1 deletion f2flickr/tags2set.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ def createSets(uploadedNow, historyFile):

if (not lastSetName == setName and not lastSetName == ''):
#new set is starting so save last
_creatSet(photoSet, lastSetName, existingSets)
newset = _creatSet(photoSet, lastSetName, existingSets)
if newset:
existingSets.append(newset)
createdSets.add(lastSetName)
photoSet = []
logging.debug("tags2set: Adding image %s", image)
Expand Down
2 changes: 1 addition & 1 deletion test/fakeflickr.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self):
self._photosets = []

def getPhotosets(self):
return self._photosets
return [s for s in self._photosets]

def addPhotosetInternal(self, ps):
self._photosets.append(ps)
Expand Down
45 changes: 36 additions & 9 deletions test/test_tags2set.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@
import fakeflickr
import shelve

def setSubsetsTrue():
tmp = open('uploadr.ini', 'r')
lines = tmp.readlines()
tmp.close()
tmp = open('uploadr.ini', 'w')
for line in lines:
if line.startswith('only_sub_sets'):
line = line.replace('false', 'true')
tmp.write(line)
tmp.close()

def addinvert(dictthing):
"""
Add the keys and values, but inverted to the dictionary
Expand Down Expand Up @@ -104,22 +115,38 @@ def testOnlySubsTrue(self):
import f2flickr.tags2set
import f2flickr.configuration
uploaded, historyFile = self.createHistory()
tmp = open('uploadr.ini', 'r')
lines = tmp.readlines()
tmp.close()
tmp = open('uploadr.ini', 'w')
for line in lines:
if line.startswith('only_sub_sets'):
line = line.replace('false', 'true')
tmp.write(line)
tmp.close()
setSubsetsTrue()
f2flickr.configuration.configdict = f2flickr.configuration.ConfigDict()
f2flickr.tags2set.createSets(uploaded, historyFile)
user = fakeflickr.fakelogin()
self.assertEquals(1, len(user.getPhotosets()))
ps = user.getPhotosets()[0]
self.assertEquals('Crete', ps.title)

def testIssue35(self):
"""
Create 2 simple sets, shouldn't create 3
"""
import f2flickr.tags2set
historyFile = tempfile.mktemp()
fakeuploaded = shelve.open(historyFile)
setSubsetsTrue()
fakeuploaded['archive1/Sterwart Park, Perth/IMG_7872.JPG'] = '15134361666'
fakeuploaded['archive1/Quebec City, Sept 2005/IMG_7877.JPG'] = '15154414551'
fakeuploaded['archive1/Quebec City, Sept 2005/IMG_7876.JPG'] = '14970716900'
fakeuploaded['archive1/Sterwart Park, Perth/IMG_7873.JPG'] = '14970824597'

addinvert(fakeuploaded)
fakeuploaded.close()

uploaded = ['15134361666', '15154414551', '14970716900', '14970824597']

f2flickr.tags2set.createSets(uploaded, historyFile)
user = fakeflickr.fakelogin()
self.assertEquals(2, len(user.getPhotosets()))

os.remove(historyFile)


if __name__ == '__main__':

Expand Down

0 comments on commit 440795a

Please sign in to comment.