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/>.
21 from django
.test
import TestCase
24 from mygpo
.core
.slugs
import get_duplicate_slugs
25 from mygpo
.core
.models
import Podcast
, PodcastGroup
, Episode
28 class PodcastGroupTests(unittest
.TestCase
):
31 self
.podcast1
= Podcast(urls
=['http://example1.com'])
34 self
.podcast2
= Podcast(urls
=['http://example2.com'])
37 group
= self
.podcast1
.group_with(self
.podcast2
, 'My Group', 'p1', 'p2')
39 self
.assertIn(self
.podcast1
, group
.podcasts
)
40 self
.assertIn(self
.podcast2
, group
.podcasts
)
41 self
.assertEquals(len(group
.podcasts
), 2)
42 self
.assertEquals(group
.title
, 'My Group')
43 self
.assertEquals(self
.podcast1
.group_member_name
, 'p1')
44 self
.assertEquals(self
.podcast2
.group_member_name
, 'p2')
47 self
.podcast3
= Podcast(urls
=['http://example3.com'])
50 group
= self
.podcast1
.group_with(self
.podcast3
, 'My Group', 'p1', 'p3')
52 self
.assertIn(self
.podcast3
, group
.podcasts
)
53 self
.assertEquals(self
.podcast3
.group_member_name
, 'p3')
55 # add group to podcast
56 self
.podcast4
= Podcast(urls
=['http://example4.com'])
59 group
= self
.podcast4
.group_with(self
.podcast1
, 'My Group', 'p4', 'p1')
61 self
.assertIn(self
.podcast4
, group
.podcasts
)
62 self
.assertEquals(self
.podcast4
.group_member_name
, 'p4')
66 class UnifySlugTests(unittest
.TestCase
):
70 from mygpo
.core
.models
import Episode
71 a
= Episode(_id
='a', slug
='1')
72 b
= Episode(_id
='b', merged_slugs
=['1'])
73 c
= Episode(_id
='c', merged_slugs
=['1'])
75 dups_list
= list(get_duplicate_slugs([a
, b
, c
]))
77 # only one duplicate slug is reported
78 self
.assertEquals(len(dups_list
), 1)
80 slug
, dups
= dups_list
[0]
82 self
.assertEquals(slug
, '1')
83 self
.assertEquals(len(dups
), 2)
84 self
.assertEquals(dups
[0], b
)
85 self
.assertEquals(dups
[1], c
)
86 self
.assertEquals(dups
, [b
, c
])
90 suite
= unittest
.TestSuite()
91 suite
.addTest(doctest
.DocTestSuite(mygpo
.utils
))
92 suite
.addTest(unittest
.TestLoader().loadTestsFromTestCase(PodcastGroupTests
))
93 suite
.addTest(unittest
.TestLoader().loadTestsFromTestCase(UnifySlugTests
))