# Path: example/sitemaps.py
# class ExampleSitemap(Sitemap):
#     changefreq = 'never'
#     priority = 0.5
# 
#     def items(self):
#         return Post.objects.all()
# 
# Path: staticgen/helpers.py
# def get_static_site_domain():
#     static_site_domain = settings.STATICGEN_STATIC_SITE_DOMAIN
#     if static_site_domain is None:
#         connection = connect_s3(
#             settings.AWS_ACCESS_KEY_ID,
#             settings.AWS_SECRET_ACCESS_KEY
#         )
#         bucket = connection.get_bucket(settings.AWS_STORAGE_BUCKET_NAME)
#         static_site_domain = bucket.get_website_endpoint()
#     return static_site_domain.rstrip('/')
# 
# Path: staticgen/sitemaps.py
# def override_sitemaps_domain(sitemaps):
#     staticgen_sitemaps = {}
#     for section, site in sitemaps.items():
#         cls_name = 'Staticgen{name}'.format(name=site.__name__)
#         staticgen_sitemaps[section] = type(cls_name, (StaticgenSitemap, site), {})
#     return staticgen_sitemaps


from django.test import TestCase
from example.sitemaps import ExampleSitemap
from staticgen.helpers import get_static_site_domain
from staticgen.sitemaps import override_sitemaps_domain
# -*- coding: utf-8 -*-

from __future__ import unicode_literals




class TestStaticgenSitemapsDomainOverride(TestCase):

    def test_domain_override(self):
        sitemaps = override_sitemaps_domain({'test': ExampleSitemap})
        sitemap = sitemaps['test']
        if callable(sitemap):
            sitemap = sitemap()

        url = sitemap.get_urls()[0]
        domain = 'http://{domain}'.format(domain=get_static_site_domain())

# Path: example/sitemaps.py
# class ExampleSitemap(Sitemap):
#     changefreq = 'never'
#     priority = 0.5
# 
#     def items(self):
#         return Post.objects.all()
# 
# Path: staticgen/helpers.py
# def get_static_site_domain():
#     static_site_domain = settings.STATICGEN_STATIC_SITE_DOMAIN
#     if static_site_domain is None:
#         connection = connect_s3(
#             settings.AWS_ACCESS_KEY_ID,
#             settings.AWS_SECRET_ACCESS_KEY
#         )
#         bucket = connection.get_bucket(settings.AWS_STORAGE_BUCKET_NAME)
#         static_site_domain = bucket.get_website_endpoint()
#     return static_site_domain.rstrip('/')
# 
# Path: staticgen/sitemaps.py
# def override_sitemaps_domain(sitemaps):
#     staticgen_sitemaps = {}
#     for section, site in sitemaps.items():
#         cls_name = 'Staticgen{name}'.format(name=site.__name__)
#         staticgen_sitemaps[section] = type(cls_name, (StaticgenSitemap, site), {})
#     return staticgen_sitemaps


# Path: tests/test_sitemaps.py
from django.test import TestCase
from example.sitemaps import ExampleSitemap
from staticgen.helpers import get_static_site_domain
from staticgen.sitemaps import override_sitemaps_domain

# -*- coding: utf-8 -*-

from __future__ import unicode_literals




class TestStaticgenSitemapsDomainOverride(TestCase):

    def test_domain_override(self):
        sitemaps = override_sitemaps_domain({'test': ExampleSitemap})
        sitemap = sitemaps['test']
        if callable(sitemap):
            sitemap = sitemap()

        url = sitemap.get_urls()[0]
        domain = 'http://{domain}'.format(domain=get_static_site_domain())

        self.assertTrue(url['location'].startswith(domain))