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")
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'])
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'))
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)
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"], )
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')
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")
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')
def set_linked_sites(request): linked_orgs = get_linked_orgs(request.user.is_authenticated) return dict(linked_orgs=linked_orgs)
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")
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)