'Check that titles attached to unpublished pages are not in the urlset.
As titles are \'published\' depending on their attached page, we create a
set of unpublished titles by checking titles attached to the draft and
public version of each page'

def test_sitemap_unpublished_titles(self):

    sitemap = CMSSitemap()
    locations = []
    urlset = sitemap.get_urls()
    unpublished_titles = set()
    for item in urlset:
        locations.append(item['location'])
    for page in Page.objects.drafts():
        if page.get_public_object():
            set1 = set(page.get_public_object().title_set.values_list('path', flat=True))
            set2 = set(page.title_set.values_list('path', flat=True))
            unpublished_titles.update(set2.difference(set1))
        else:
            unpublished_titles.update(page.title_set.values_list('path', flat=True))
    for path in unpublished_titles:
        title = Title.objects.get(path=path)
        if title.path:
            url = ('http://example.com/%s/%s/' % (title.language, title.path))
        else:
            url = ('http://example.com/%s/%s' % (title.language, title.path))
        self.assertFalse((url in locations))
