Esempio n. 1
0
 def setUp(self):
     super().setUp()
     self.assertEqual("uganda", get_current_country())
     self.mocca_register = MoccaRegister.objects.get(
         mocca_country=get_current_country(),
         mocca_study_identifier="05-0125")
     self.mocca_register_male = MoccaRegister.objects.get(
         mocca_country=get_current_country(),
         mocca_study_identifier="05-0124")
     self.mocca_site = MoccaOriginalSites.objects.get(
         name=self.mocca_register.mocca_site.name)
Esempio n. 2
0
def get_mocca_site_limited_to():
    return {
        "name__in": [
            site.name for site in sites.values()
            if site.country == get_current_country()
        ]
    }
Esempio n. 3
0
 def test_custom_sites_module_domain(self):
     self.assertEqual(get_all_sites(), all_test_sites)
     self.assertEqual(settings.SITE_ID, 10)
     for sites in get_all_sites().values():
         add_or_update_django_sites(sites=sites, verbose=False)
     site = Site.objects.get(id=10)
     self.assertEqual(get_current_country(), "botswana")
     self.assertEqual(
         Alias.objects.get(site=site).domain, "mochudi.bw.clinicedc.org")
Esempio n. 4
0
 def validate_mocca_site(self):
     mocca_country = get_current_country()
     if self.cleaned_data.get("mocca_site"):
         sites = get_mocca_sites_by_country(country=mocca_country)
         if self.cleaned_data.get("mocca_site").name not in [
                 v.name for v in sites.values()
         ]:
             raise forms.ValidationError(
                 {"mocca_site": "Invalid site for selected country"})
Esempio n. 5
0
def import_for_tests(model_cls):
    LOCAL_DATE = 0
    LABEL = 1
    COUNTRY = 2
    year = get_utcnow().year
    country = get_current_country()
    if not country:
        raise HolidayImportError(
            "Cannot determine default country when importing "
            "holidays for tests. Confirm SITE_ID is valid. See `import_for_tests`"
        )
    rows = [
        [f"{year}-01-02", "Public Holiday", country],
        [f"{year}-01-01", "New Year", country],
        [f"{year}-04-14", "Good Friday", country],
        [f"{year}-04-17", "Easter Monday", country],
        [f"{year}-05-01", "May Day/Labour Day", country],
        [f"{year}-05-25", "Ascension Day", country],
        [f"{year}-07-18", "Public Holiday", country],
        [f"{year}-09-30", "Botswana Day", country],
        [f"{year}-10-02", "Public Holiday", country],
        [f"{year}-12-25", "Christmas Day", country],
        [f"{year}-12-26", "Boxing Day", country],
    ]
    objs = []
    for index, row in tqdm(enumerate(rows), total=len(rows)):
        if index == 0:
            continue
        try:
            local_date = datetime.strptime(row[LOCAL_DATE], "%Y-%m-%d").date()
        except ValueError as e:
            raise HolidayImportError(
                f"Invalid format when importing holidays (test). "
                f"Got '{e}'")
        else:
            objs.append(
                model_cls(country=row[COUNTRY],
                          local_date=local_date,
                          name=row[LABEL]))
    with transaction.atomic():
        model_cls.objects.all().delete()
        model_cls.objects.bulk_create(objs)
Esempio n. 6
0
    def test_country(self):
        for sites in self.default_all_sites.values():
            add_or_update_django_sites(sites=sites)
        self.assertEqual("mochudi", Site.objects.get_current().name)
        self.assertEqual("botswana",
                         Site.objects.get_current().siteprofile.country)
        self.assertEqual("botswana", get_current_country())
        self.assertEqual(self.default_all_sites.get("botswana"),
                         get_sites_by_country("botswana"))
        self.assertEqual(self.default_all_sites.get("botswana"),
                         get_sites_by_country())
        self.assertEqual(
            self.default_all_sites.get("botswana"),
            get_sites_by_country(all_sites=self.default_all_sites),
        )

        self.assertEqual(
            self.default_all_sites.get("botswana"),
            get_sites_by_country(country="botswana",
                                 all_sites=self.default_all_sites),
        )
Esempio n. 7
0
def holiday_country_check(app_configs, **kwargs):
    sys.stdout.write(style.SQL_KEYWORD("holiday_country_check ... \r"))
    errors = []
    holiday_path = settings.HOLIDAY_FILE
    country = get_current_country()
    if country:
        with open(holiday_path, "r") as f:
            reader = csv.DictReader(
                f, fieldnames=["local_date", "label", "country"])
            if not [
                    row["country"]
                    for row in reader if row["country"] == country
            ]:
                errors.append(
                    Warning(
                        f"Holiday file has no records for current country! "
                        f"See country in EdcSites definitions. Got {country}\n",
                        id="edc_facility.004",
                    ))
    sys.stdout.write(style.SQL_KEYWORD("holiday_country_check ... done.\n"))
    return errors
Esempio n. 8
0
 def check(cls, **kwargs):
     errors = super().check(**kwargs)
     try:
         if cls.objects.all().count() == 0:
             errors.append(
                 Warning(
                     "Holiday table is empty. Run management command 'import_holidays'. "
                     "See edc_facility.Holidays",
                     id="edc_facility.003",
                 ))
         elif cls.objects.filter(
                 country=get_current_country()).count() == 0:
             countries = [obj.country for obj in cls.objects.all()]
             countries = list(set(countries))
             errors.append(
                 Warning(
                     f"No Holidays have been defined for this country. "
                     f"See edc_facility.Holidays. Expected one of {countries}. "
                     f"Got country='{get_current_country()}'",
                     id="edc_facility.004",
                 ))
     except (ProgrammingError, OperationalError):
         pass
     return errors