示例#1
0
    def test_get_linked_orgs(self, mock_get_shared_sites_count):
        settings_sites = list(getattr(settings, "COUNTRY_FLAGS_SITES", []))
        mock_get_shared_sites_count.return_value = {
            "global_count": 120,
            "countries_count": 12,
            "linked_sites": settings_sites,
        }

        settings_sites_count = len(settings_sites)

        # we have 1 org in settings we do not show its link (global)
        self.assertEqual(len(get_linked_orgs()), settings_sites_count - 1)
        self.assertEqual(get_linked_orgs()[0]["name"].lower(), "afghanistan")
示例#2
0
def show_org_flags(context):
    request = context['request']
    linked_orgs = get_linked_orgs(request.user.is_authenticated())
    return dict(linked_orgs=linked_orgs,
                break_pos=min(len(linked_orgs) / 2, 9),
                STATIC_URL=settings.STATIC_URL,
                is_iorg=context['is_iorg'])
示例#3
0
 def pre_process(self, request, *args, **kwargs):
     if not self.request.org:
         org = Org.objects.filter(subdomain='', is_active=True).first()
         if not org:
             linked_sites = get_linked_orgs()
             return TemplateResponse(request, settings.SITE_CHOOSER_TEMPLATE, dict(orgs=linked_sites))
         else:
             return HttpResponsePermanentRedirect('http://' + getattr(settings, "HOSTNAME", 'locahost'))
示例#4
0
 def pre_process(self, request, *args, **kwargs):
     if not self.request.org:
         org = Org.objects.filter(subdomain='', is_active=True).first()
         if not org:
             linked_sites = get_linked_orgs()
             return TemplateResponse(request, settings.SITE_CHOOSER_TEMPLATE, dict(orgs=linked_sites))
         else:
             return HttpResponsePermanentRedirect('http://' + getattr(settings, "HOSTNAME", 'locahost'))
示例#5
0
 def pre_process(self, request, *args, **kwargs):
     if not self.request.org:
         org = Org.objects.filter(subdomain='www', is_active=True).first()
         if not org:
             linked_sites = get_linked_orgs()
             return TemplateResponse(request, settings.SITE_CHOOSER_TEMPLATE, dict(orgs=linked_sites))
         else:
             return HttpResponsePermanentRedirect(settings.SITE_HOST_PATTERN % org.subdomain)
示例#6
0
def show_org_flags(context):
    request = context["request"]
    linked_orgs = get_linked_orgs(request.user.is_authenticated)
    return dict(
        linked_orgs=linked_orgs,
        break_pos=min(len(linked_orgs) / 2, 9),
        STATIC_URL=settings.STATIC_URL,
        is_iorg=context["is_iorg"],
    )
示例#7
0
    def test_get_linked_orgs(self):

        # we have 4 old org in the settings
        self.assertEqual(len(get_linked_orgs()), 3)
        for old_site in get_linked_orgs():
            self.assertFalse(old_site['name'].lower() == 'burundi')

        self.org.set_config('is_on_landing_page', True)

        # missing flag
        self.assertEqual(len(get_linked_orgs()), 3)
        for old_site in get_linked_orgs():
            self.assertFalse(old_site['name'].lower() == 'burundi')

        Image.objects.create(org=self.org, image_type=FLAG, name='burundi_flag',
                             image="media/image.jpg", created_by=self.admin, modified_by=self.admin)

        # burundi should be included and be the first; by alphetical order
        self.assertEqual(len(get_linked_orgs()), 4)
        self.assertEqual(get_linked_orgs()[0]['name'].lower(), 'burundi')
        with self.settings(HOSTNAME='localhost:8000'):
            self.assertEqual(get_linked_orgs()[0]['host'].lower(), 'http://burundi.localhost:8000')
            self.assertEqual(get_linked_orgs(True)[0]['host'].lower(), 'http://burundi.localhost:8000')

            self.org.domain = 'ureport.bi'
            self.org.save()

            self.assertEqual(get_linked_orgs()[0]['host'].lower(), 'http://burundi.localhost:8000')
            self.assertEqual(get_linked_orgs(True)[0]['host'].lower(), 'http://burundi.localhost:8000')

            with self.settings(SESSION_COOKIE_SECURE=True):
                self.assertEqual(get_linked_orgs()[0]['host'].lower(), 'http://ureport.bi')
                self.assertEqual(get_linked_orgs(True)[0]['host'].lower(), 'https://burundi.localhost:8000')
示例#8
0
文件: tests.py 项目: forkkit/ureport
    def test_get_linked_orgs(self):

        # use aaaburundi to force the to be alphabetically first
        self.org.subdomain = "aaaburundi"
        self.org.save()

        settings_sites_count = len(list(getattr(settings, "PREVIOUS_ORG_SITES", [])))

        # we have 3 old org in the settings
        self.assertEqual(len(get_linked_orgs()), settings_sites_count)
        for old_site in get_linked_orgs():
            self.assertFalse(old_site["name"].lower() == "aaaburundi")
            self.assertFalse(old_site["order_name"].lower() == "burundi")

        self.org.set_config("common.is_on_landing_page", True)

        # missing flag
        self.assertEqual(len(get_linked_orgs()), settings_sites_count)
        for old_site in get_linked_orgs():
            self.assertFalse(old_site["name"].lower() == "aaaburundi")
            self.assertFalse(old_site["order_name"].lower() == "burundi")

        Image.objects.create(
            org=self.org,
            image_type=FLAG,
            name="burundi_flag",
            image="media/image.jpg",
            created_by=self.admin,
            modified_by=self.admin,
        )

        # burundi should be included and be the first; by alphabetical order by subdomain
        self.assertEqual(len(get_linked_orgs()), settings_sites_count + 1)
        self.assertEqual(get_linked_orgs()[0]["order_name"].lower(), "aaaburundi")
        self.assertEqual(get_linked_orgs()[0]["name"].lower(), "burundi")

        self.org.subdomain = "rwanda"
        self.org.save()

        # rwanda should be included and the third in the list alphabetically by subdomain
        self.assertEqual(len(get_linked_orgs()), settings_sites_count + 1)
        self.assertEqual(get_linked_orgs()[settings_sites_count - 3]["order_name"].lower(), "trinidad and tobago")
        self.assertEqual(get_linked_orgs()[settings_sites_count - 3]["name"].lower(), "trinidad and tobago")

        # revert subdomain to burundi
        self.org.subdomain = "aaaburundi"
        self.org.save()

        with self.settings(HOSTNAME="localhost:8000"):
            self.assertEqual(get_linked_orgs()[0]["host"].lower(), "http://aaaburundi.localhost:8000")
            self.assertEqual(get_linked_orgs(True)[0]["host"].lower(), "http://aaaburundi.localhost:8000")

            self.org.domain = "ureport.bi"
            self.org.save()

            self.assertEqual(get_linked_orgs()[0]["host"].lower(), "http://aaaburundi.localhost:8000")
            self.assertEqual(get_linked_orgs(True)[0]["host"].lower(), "http://aaaburundi.localhost:8000")

            with self.settings(SESSION_COOKIE_SECURE=True):
                self.assertEqual(get_linked_orgs()[0]["host"].lower(), "http://ureport.bi")
                self.assertEqual(get_linked_orgs(True)[0]["host"].lower(), "https://aaaburundi.localhost:8000")
示例#9
0
    def test_get_linked_orgs(self):

        # use aaaburundi to force the to be alphabetically first
        self.org.subdomain = 'aaaburundi'
        self.org.save()

        settings_sites_count = len(list(getattr(settings, 'PREVIOUS_ORG_SITES', [])))

        # we have 3 old org in the settings
        self.assertEqual(len(get_linked_orgs()), settings_sites_count)
        for old_site in get_linked_orgs():
            self.assertFalse(old_site['name'].lower() == 'aaaburundi')

        self.org.set_config('common.is_on_landing_page', True)

        # missing flag
        self.assertEqual(len(get_linked_orgs()), settings_sites_count)
        for old_site in get_linked_orgs():
            self.assertFalse(old_site['name'].lower() == 'aaaburundi')

        Image.objects.create(org=self.org, image_type=FLAG, name='burundi_flag',
                             image="media/image.jpg", created_by=self.admin, modified_by=self.admin)

        # burundi should be included and be the first; by alphabetical order by subdomain
        self.assertEqual(len(get_linked_orgs()), settings_sites_count + 1)
        self.assertEqual(get_linked_orgs()[0]['name'].lower(), 'aaaburundi')

        self.org.subdomain = 'rwanda'
        self.org.save()

        # rwanda should be included and the third in the list alphabetically by subdomain
        self.assertEqual(len(get_linked_orgs()), settings_sites_count + 1)
        self.assertEqual(get_linked_orgs()[settings_sites_count - 4]['name'].lower(), 'rwanda')

        # revert subdomain to burundi
        self.org.subdomain = 'aaaburundi'
        self.org.save()

        with self.settings(HOSTNAME='localhost:8000'):
            self.assertEqual(get_linked_orgs()[0]['host'].lower(), 'http://aaaburundi.localhost:8000')
            self.assertEqual(get_linked_orgs(True)[0]['host'].lower(), 'http://aaaburundi.localhost:8000')

            self.org.domain = 'ureport.bi'
            self.org.save()

            self.assertEqual(get_linked_orgs()[0]['host'].lower(), 'http://aaaburundi.localhost:8000')
            self.assertEqual(get_linked_orgs(True)[0]['host'].lower(), 'http://aaaburundi.localhost:8000')

            with self.settings(SESSION_COOKIE_SECURE=True):
                self.assertEqual(get_linked_orgs()[0]['host'].lower(), 'http://ureport.bi')
                self.assertEqual(get_linked_orgs(True)[0]['host'].lower(), 'https://aaaburundi.localhost:8000')
示例#10
0
def set_linked_sites(request):
    linked_orgs = get_linked_orgs(request.user.is_authenticated)
    return dict(linked_orgs=linked_orgs)
示例#11
0
文件: tests.py 项目: rapidpro/ureport
    def test_get_linked_orgs(self):

        # use aaaburundi to force the to be alphabetically first
        self.org.subdomain = "aaaburundi"
        self.org.save()

        settings_sites_count = len(list(getattr(settings, "PREVIOUS_ORG_SITES", [])))

        # we have 3 old org in the settings
        self.assertEqual(len(get_linked_orgs()), settings_sites_count)
        for old_site in get_linked_orgs():
            self.assertFalse(old_site["name"].lower() == "aaaburundi")

        self.org.set_config("common.is_on_landing_page", True)

        # missing flag
        self.assertEqual(len(get_linked_orgs()), settings_sites_count)
        for old_site in get_linked_orgs():
            self.assertFalse(old_site["name"].lower() == "aaaburundi")

        Image.objects.create(
            org=self.org,
            image_type=FLAG,
            name="burundi_flag",
            image="media/image.jpg",
            created_by=self.admin,
            modified_by=self.admin,
        )

        # burundi should be included and be the first; by alphabetical order by subdomain
        self.assertEqual(len(get_linked_orgs()), settings_sites_count + 1)
        self.assertEqual(get_linked_orgs()[0]["name"].lower(), "aaaburundi")

        self.org.subdomain = "rwanda"
        self.org.save()

        # rwanda should be included and the third in the list alphabetically by subdomain
        self.assertEqual(len(get_linked_orgs()), settings_sites_count + 1)
        self.assertEqual(get_linked_orgs()[settings_sites_count - 4]["name"].lower(), "trinidad and tobago")

        # revert subdomain to burundi
        self.org.subdomain = "aaaburundi"
        self.org.save()

        with self.settings(HOSTNAME="localhost:8000"):
            self.assertEqual(get_linked_orgs()[0]["host"].lower(), "http://aaaburundi.localhost:8000")
            self.assertEqual(get_linked_orgs(True)[0]["host"].lower(), "http://aaaburundi.localhost:8000")

            self.org.domain = "ureport.bi"
            self.org.save()

            self.assertEqual(get_linked_orgs()[0]["host"].lower(), "http://aaaburundi.localhost:8000")
            self.assertEqual(get_linked_orgs(True)[0]["host"].lower(), "http://aaaburundi.localhost:8000")

            with self.settings(SESSION_COOKIE_SECURE=True):
                self.assertEqual(get_linked_orgs()[0]["host"].lower(), "http://ureport.bi")
                self.assertEqual(get_linked_orgs(True)[0]["host"].lower(), "https://aaaburundi.localhost:8000")
示例#12
0
def show_org_flags():
    linked_orgs = get_linked_orgs()
    return dict(linked_orgs=linked_orgs, break_pos=len(linked_orgs)/2 ,STATIC_URL=settings.STATIC_URL)