def test_default_criteria(self): # Online self.request.country = "W3" results = list(match_notification_email(self.request)) self.assertEqual(results, ["*****@*****.**"]) # European Union self.request.country = "EU" results = list(match_notification_email(self.request)) self.assertEqual(results, ["*****@*****.**"]) # United States self.request.country = "US" results = list(match_notification_email(self.request)) self.assertEqual(results, ["*****@*****.**"]) # Poland self.request.country = "PL" results = list(match_notification_email(self.request)) self.assertEqual(results, ["*****@*****.**"]) # unknown country code self.request.country = "XY" results = list(match_notification_email(self.request)) self.assertEqual(results, ["*****@*****.**"])
def test_default_criteria(self): # Online self.request.country = 'W3' results = match_notification_email(self.request) self.assertEqual(results, ['*****@*****.**']) # European Union self.request.country = 'EU' results = match_notification_email(self.request) self.assertEqual(results, ['*****@*****.**']) # United States self.request.country = 'US' results = match_notification_email(self.request) self.assertEqual(results, ['*****@*****.**']) # Poland self.request.country = 'PL' results = match_notification_email(self.request) self.assertEqual(results, ['*****@*****.**']) # unknown country code self.request.country = 'XY' results = match_notification_email(self.request) self.assertEqual(results, ['*****@*****.**'])
def test_default_criteria(self): # Online self.request.country = 'W3' results = list(match_notification_email(self.request)) self.assertEqual(results, ['*****@*****.**']) # European Union self.request.country = 'EU' results = list(match_notification_email(self.request)) self.assertEqual(results, ['*****@*****.**']) # United States self.request.country = 'US' results = list(match_notification_email(self.request)) self.assertEqual(results, ['*****@*****.**']) # Poland self.request.country = 'PL' results = list(match_notification_email(self.request)) self.assertEqual(results, ['*****@*****.**']) # unknown country code self.request.country = 'XY' results = list(match_notification_email(self.request)) self.assertEqual(results, ['*****@*****.**'])
def test_object_no_criteria(self): self.assertFalse(hasattr(self, 'country')) results = match_notification_email(self) self.assertEqual(results, ['*****@*****.**']) self.country = None results = match_notification_email(self) self.assertEqual(results, ['*****@*****.**'])
def get_additional_context(self, objects, *args, **kwargs): from workshops.util import human_daterange, match_notification_email # refresh related event event = objects["event"] event.refresh_from_db() # prepare context context = dict() context["workshop"] = event context["workshop_main_type"] = None tmp = event.tags.carpentries().first() if tmp: context["workshop_main_type"] = tmp.name context["dates"] = human_daterange(event.start, event.end) context["workshop_host"] = event.host context["regional_coordinator_email"] = list(match_notification_email(event)) # people instructors = event.task_set.filter(role__name__in=self.role_names) context["instructors"] = [instr.person for instr in instructors] hosts = event.task_set.filter(role__name="host") context["hosts"] = [host.person for host in hosts] task_emails = [task.person.email for task in instructors] context["all_emails"] = list(filter(bool, task_emails)) context["assignee"] = ( event.assigned_to.full_name if event.assigned_to else "Regional Coordinator" ) context["tags"] = list(event.tags.values_list("name", flat=True)) return context
def get_additional_context(self, objects, *args, **kwargs): from workshops.util import human_daterange, match_notification_email # refresh related event event = objects["event"] task = objects["task"] event.refresh_from_db() task.refresh_from_db() # prepare context context = dict() context["workshop"] = event context["workshop_main_type"] = None tmp = event.tags.carpentries().first() if tmp: context["workshop_main_type"] = tmp.name context["dates"] = None if event.start and event.end: context["dates"] = human_daterange(event.start, event.end) context["host"] = event.host context["regional_coordinator_email"] = list(match_notification_email(event)) context["task"] = task context["person"] = task.person context["instructor"] = task.person context["role"] = task.role context["assignee"] = ( event.assigned_to.full_name if event.assigned_to else "Regional Coordinator" ) context["tags"] = list(event.tags.values_list("name", flat=True)) return context
def get_additional_context(self, objects, *args, **kwargs): from workshops.util import ( human_daterange, match_notification_email, reports_link, ) # refresh related event event = objects["event"] event.refresh_from_db() # prepare context context = dict() context["workshop"] = event context["workshop_main_type"] = None tmp = event.tags.carpentries().first() if tmp: context["workshop_main_type"] = tmp.name context["dates"] = None if event.end: context["dates"] = human_daterange(event.start, event.end) context["host"] = event.host context["regional_coordinator_email"] = list( match_notification_email(event)) # to get only people from the task set context["instructors"] = list( Person.objects.filter(task__in=event.task_set.filter( role__name="instructor"))) context["supporting_instructors"] = list( Person.objects.filter(task__in=event.task_set.filter( role__name="supporting-instructor"))) context["helpers"] = list( Person.objects.filter(task__in=event.task_set.filter( role__name="helper"))) context["hosts"] = list( Person.objects.filter(task__in=event.task_set.filter( role__name="host"))) # querying over Person.objects lets us get rid of duplicates person_emails = list( Person.objects.filter(task__in=event.task_set.filter( role__name__in=self.ROLES)).distinct().values_list("email", flat=True)) additional_contacts = event.contact.split(TAG_SEPARATOR) all_emails = list(filter(bool, person_emails + additional_contacts)) context["all_emails"] = all_emails context["assignee"] = (event.assigned_to.full_name if event.assigned_to else "Regional Coordinator") context["reports_link"] = reports_link(event.slug) context["tags"] = list(event.tags.values_list("name", flat=True)) return context
def get_additional_context(self, objects, *args, **kwargs): from workshops.util import human_daterange, match_notification_email # refresh related event event = objects["event"] event.refresh_from_db() # prepare context context = dict() context["workshop"] = event context["workshop_main_type"] = None tmp = event.tags.carpentries().first() if tmp: context["workshop_main_type"] = tmp.name context["dates"] = human_daterange(event.start, event.end) context["workshop_host"] = event.host context["regional_coordinator_email"] = list(match_notification_email(event)) # people tasks = event.task_set.filter( role__name__in=["host", "instructor", "supporting-instructor"] ).order_by("role__name") hosts = tasks.filter(role__name="host") instructors = tasks.filter(role__name="instructor") support = tasks.filter(role__name="supporting-instructor") context["instructors"] = [instr.person for instr in instructors] context["supporting_instructors"] = [instr.person for instr in support] context["host"] = hosts[0].person context["hosts"] = [host.person for host in hosts] context["instructor1"] = instructors[0].person context["instructor2"] = instructors[1].person # supporting instructors are optional try: context["supporting_instructor1"] = support[0].person except IndexError: context["supporting_instructor1"] = None try: context["supporting_instructor2"] = support[1].person except IndexError: context["supporting_instructor2"] = None task_emails = [t.person.email for t in tasks] contacts = event.contact.split(TAG_SEPARATOR) context["all_emails"] = list(filter(bool, task_emails + contacts)) context["assignee"] = ( event.assigned_to.full_name if event.assigned_to else "Regional Coordinator" ) context["tags"] = list(event.tags.values_list("name", flat=True)) return context
def test_matching_Africa(self): """Testing just a subset of countries in Africa.""" # the Democratic Republic of the Congo self.request.country = 'CD' results = list(match_notification_email(self.request)) self.assertEqual(results, ['*****@*****.**']) # Nigeria self.request.country = 'NG' results = list(match_notification_email(self.request)) self.assertEqual(results, ['*****@*****.**']) # South Sudan self.request.country = 'SS' results = list(match_notification_email(self.request)) self.assertEqual(results, ['*****@*****.**']) # Somalia self.request.country = 'SO' results = list(match_notification_email(self.request)) self.assertEqual(results, ['*****@*****.**']) # Egipt self.request.country = 'EG' results = list(match_notification_email(self.request)) self.assertEqual(results, ['*****@*****.**']) # Tunisia self.request.country = 'TN' results = list(match_notification_email(self.request)) self.assertEqual(results, ['*****@*****.**'])
def test_matching_Africa(self): """Testing just a subset of countries in Africa.""" # the Democratic Republic of the Congo self.request.country = "CD" results = list(match_notification_email(self.request)) self.assertEqual(results, ["*****@*****.**"]) # Nigeria self.request.country = "NG" results = list(match_notification_email(self.request)) self.assertEqual(results, ["*****@*****.**"]) # South Sudan self.request.country = "SS" results = list(match_notification_email(self.request)) self.assertEqual(results, ["*****@*****.**"]) # Somalia self.request.country = "SO" results = list(match_notification_email(self.request)) self.assertEqual(results, ["*****@*****.**"]) # Egipt self.request.country = "EG" results = list(match_notification_email(self.request)) self.assertEqual(results, ["*****@*****.**"]) # Tunisia self.request.country = "TN" results = list(match_notification_email(self.request)) self.assertEqual(results, ["*****@*****.**"])
def test_matching_Africa(self): """Testing just a subset of countries in Africa.""" # the Democratic Republic of the Congo self.request.country = 'CD' results = match_notification_email(self.request) self.assertEqual(results, ['*****@*****.**']) # Nigeria self.request.country = 'NG' results = match_notification_email(self.request) self.assertEqual(results, ['*****@*****.**']) # South Sudan self.request.country = 'SS' results = match_notification_email(self.request) self.assertEqual(results, ['*****@*****.**']) # Somalia self.request.country = 'SO' results = match_notification_email(self.request) self.assertEqual(results, ['*****@*****.**']) # Egipt self.request.country = 'EG' results = match_notification_email(self.request) self.assertEqual(results, ['*****@*****.**']) # Tunisia self.request.country = 'TN' results = match_notification_email(self.request) self.assertEqual(results, ['*****@*****.**'])
def test_matching_UK_CA_NZ_AU(self): """Test a bunch of criteria automatically.""" data = [ ("GB", "*****@*****.**"), ("CA", "*****@*****.**"), ("NZ", "*****@*****.**"), ("AU", "*****@*****.**"), ] for code, email in data: with self.subTest(code=code): self.request.country = code results = list(match_notification_email(self.request)) self.assertEqual(results, [email])
def test_matching_UK_CA_NZ_AU(self): """Test a bunch of criteria automatically.""" data = [ ('GB', '*****@*****.**'), ('CA', '*****@*****.**'), ('NZ', '*****@*****.**'), ('AU', '*****@*****.**'), ] for code, email in data: with self.subTest(code=code): self.request.country = code results = match_notification_email(self.request) self.assertEqual(results, [email])
def test_matching_UK_CA_NZ_AU(self): """Test a bunch of criteria automatically.""" data = [ ('GB', '*****@*****.**'), ('CA', '*****@*****.**'), ('NZ', '*****@*****.**'), ('AU', '*****@*****.**'), ] for code, email in data: with self.subTest(code=code): self.request.country = code results = list(match_notification_email(self.request)) self.assertEqual(results, [email])
def get_additional_context(self, objects, *args, **kwargs): from workshops.util import human_daterange, match_notification_email # prepare context context = dict() # current design allows for creating a response when there's no connected # event request = objects["request"] event = objects.get("event") context["request"] = request if event: # refresh related event if it exists event.refresh_from_db() context["workshop"] = event context["workshop_main_type"] = None tmp = event.tags.carpentries().first() if tmp: context["workshop_main_type"] = tmp.name context["dates"] = human_daterange(event.start, event.end) context["workshop_host"] = event.host context["regional_coordinator_email"] = list( match_notification_email(event) ) task_emails = [ task.person.email for task in event.task_set.filter( role__name__in=["host", "instructor"] ).order_by("role__name") ] context["all_emails"] = list(filter(bool, task_emails)) context["assignee"] = ( event.assigned_to.full_name if event.assigned_to else "Regional Coordinator" ) context["tags"] = list(event.tags.values_list("name", flat=True)) else: context["assignee"] = ( request.assigned_to.full_name if request.assigned_to else "Regional Coordinator" ) return context
def get_additional_context(self, objects, *args, **kwargs): from workshops.util import match_notification_email, human_daterange # refresh related event and request event = objects["event"] event.refresh_from_db() request = objects["request"] # SelfOrganisedSubmission request.refresh_from_db() # prepare context context = dict() context["workshop"] = event context["request"] = request context["workshop_main_type"] = None tmp = event.tags.carpentries().first() if tmp: context["workshop_main_type"] = tmp.name context["dates"] = None if event.end: context["dates"] = human_daterange(event.start, event.end) context["host"] = event.host context["regional_coordinator_email"] = list( match_notification_email(event)) # event starts in less (or equal) than 10 days context["short_notice"] = event.start <= (date.today() + timedelta(days=10)) # additional contact info (see CommonRequest for details) emails = [request.email ] + request.additional_contact.split(TAG_SEPARATOR) context["all_emails"] = list(filter(bool, emails)) context["assignee"] = (event.assigned_to.full_name if event.assigned_to else "Regional Coordinator") context["tags"] = list(event.tags.values_list("name", flat=True)) return context
def get_email_kwargs(self): return { 'to': match_notification_email(self.object), 'reply_to': [self.object.email], }
def get_email_kwargs(self): return { "to": match_notification_email(self.object), "reply_to": [self.object.email], }
def test_object_no_criteria(self): self.assertFalse(hasattr(self, 'country')) results = match_notification_email(self) self.assertEqual(results, ['*****@*****.**'])