2 # This file is part of my.gpodder.org.
4 # my.gpodder.org is free software: you can redistribute it and/or modify it
5 # under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or (at your
7 # option) any later version.
9 # my.gpodder.org is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
12 # License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with my.gpodder.org. If not, see <http://www.gnu.org/licenses/>.
18 from datetime
import datetime
21 from django
.test
import TestCase
23 from mygpo
.core
.models
import Podcast
, Episode
24 from mygpo
.users
.models
import EpisodeAction
, User
25 from mygpo
.maintenance
.merge
import PodcastMerger
26 from mygpo
.counter
import Counter
27 from mygpo
.db
.couchdb
.episode_state
import episode_state_for_user_episode
30 class MergeTests(TestCase
):
33 self
.podcast1
= Podcast(urls
=['http://example.com/feed.rss'])
34 self
.podcast2
= Podcast(urls
=['http://test.org/podcast/'])
38 self
.episode1
= Episode(podcast
=self
.podcast1
.get_id(),
39 urls
= ['http://example.com/episode1.mp3'])
40 self
.episode2
= Episode(podcast
=self
.podcast2
.get_id(),
41 urls
= ['http://example.com/episode1.mp3'])
46 self
.user
= User(username
='test')
47 self
.user
.email
= 'test@example.com'
48 self
.user
.set_password('secret!')
52 def test_merge_podcasts(self
):
54 state1
= episode_state_for_user_episode(self
.user
, self
.episode1
)
55 state2
= episode_state_for_user_episode(self
.user
, self
.episode2
)
57 action1
= EpisodeAction(action
='play', timestamp
=datetime
.utcnow())
58 action2
= EpisodeAction(action
='download', timestamp
=datetime
.utcnow())
60 state1
.add_actions([action1
])
61 state2
.add_actions([action2
])
66 # decide which episodes to merge
67 groups
= [(0, [self
.episode1
, self
.episode2
])]
70 pm
= PodcastMerger([self
.podcast1
, self
.podcast2
], counter
, groups
)
73 state1
= episode_state_for_user_episode(self
.user
, self
.episode1
)
75 self
.assertIn(action1
, state1
.actions
)
76 self
.assertIn(action2
, state1
.actions
)
81 self
.podcast1
.delete()
82 self
.episode1
.delete()
84 #self.podcast2.delete()
85 #self.episode2.delete()
91 suite
= unittest
.TestSuite()
92 suite
.addTest(unittest
.TestLoader().loadTestsFromTestCase(MergeTests
))