diff --git a/core/choices.py b/core/choices.py new file mode 100644 index 0000000..678c475 --- /dev/null +++ b/core/choices.py @@ -0,0 +1,227 @@ +from django.utils.translation import gettext_lazy as _ + +LANGUAGE = [ + ("aa", "Afar"), + ("af", "Afrikaans"), + ("ak", "Akan"), + ("sq", "Albanian"), + ("am", "Amharic"), + ("ar", "Arabic"), + ("an", "Aragonese"), + ("hy", "Armenian"), + ("as", "Assamese"), + ("av", "Avaric"), + ("ae", "Avestan"), + ("ay", "Aymara"), + ("az", "Azerbaijani"), + ("bm", "Bambara"), + ("ba", "Bashkir"), + ("eu", "Basque"), + ("be", "Belarusian"), + ("bn", "Bengali"), + ("bi", "Bislama"), + ("bs", "Bosnian"), + ("br", "Breton"), + ("bg", "Bulgarian"), + ("my", "Burmese"), + ("ca", "Catalan, Valencian"), + ("ch", "Chamorro"), + ("ce", "Chechen"), + ("ny", "Chichewa, Chewa, Nyanja"), + ("zh", "Chinese"), + ( + "cu", + "Church Slavic, Old Slavonic, Church Slavonic, Old Bulgarian, Old Church Slavonic", + ), + ("cv", "Chuvash"), + ("kw", "Cornish"), + ("co", "Corsican"), + ("cr", "Cree"), + ("hr", "Croatian"), + ("cs", "Czech"), + ("da", "Danish"), + ("dv", "Divehi, Dhivehi, Maldivian"), + ("nl", "Dutch, Flemish"), + ("dz", "Dzongkha"), + ("en", "English"), + ("eo", "Esperanto"), + ("et", "Estonian"), + ("ee", "Ewe"), + ("fo", "Faroese"), + ("fj", "Fijian"), + ("fi", "Finnish"), + ("fr", "French"), + ("fy", "Western Frisian"), + ("ff", "Fulah"), + ("gd", "Gaelic, Scottish Gaelic"), + ("gl", "Galician"), + ("lg", "Ganda"), + ("ka", "Georgian"), + ("de", "German"), + ("el", "Greek, Modern (1453–)"), + ("kl", "Kalaallisut, Greenlandic"), + ("gn", "Guarani"), + ("gu", "Gujarati"), + ("ht", "Haitian, Haitian Creole"), + ("ha", "Hausa"), + ("he", "Hebrew"), + ("hz", "Herero"), + ("hi", "Hindi"), + ("ho", "Hiri Motu"), + ("hu", "Hungarian"), + ("is", "Icelandic"), + ("io", "Ido"), + ("ig", "Igbo"), + ("id", "Indonesian"), + ("ia", "Interlingua (International Auxiliary Language Association)"), + ("ie", "Interlingue, Occidental"), + ("iu", "Inuktitut"), + ("ik", "Inupiaq"), + ("ga", "Irish"), + ("it", "Italian"), + ("ja", "Japanese"), + ("jv", "Javanese"), + ("kn", "Kannada"), + ("kr", "Kanuri"), + ("ks", "Kashmiri"), + ("kk", "Kazakh"), + ("km", "Central Khmer"), + ("ki", "Kikuyu, Gikuyu"), + ("rw", "Kinyarwanda"), + ("ky", "Kirghiz, Kyrgyz"), + ("kv", "Komi"), + ("kg", "Kongo"), + ("ko", "Korean"), + ("kj", "Kuanyama, Kwanyama"), + ("ku", "Kurdish"), + ("lo", "Lao"), + ("la", "Latin"), + ("lv", "Latvian"), + ("li", "Limburgan, Limburger, Limburgish"), + ("ln", "Lingala"), + ("lt", "Lithuanian"), + ("lu", "Luba-Katanga"), + ("lb", "Luxembourgish, Letzeburgesch"), + ("mk", "Macedonian"), + ("mg", "Malagasy"), + ("ms", "Malay"), + ("ml", "Malayalam"), + ("mt", "Maltese"), + ("gv", "Manx"), + ("mi", "Maori"), + ("mr", "Marathi"), + ("mh", "Marshallese"), + ("mn", "Mongolian"), + ("na", "Nauru"), + ("nv", "Navajo, Navaho"), + ("nd", "North Ndebele"), + ("nr", "South Ndebele"), + ("ng", "Ndonga"), + ("ne", "Nepali"), + ("no", "Norwegian"), + ("nb", "Norwegian Bokmål"), + ("nn", "Norwegian Nynorsk"), + ("ii", "Sichuan Yi, Nuosu"), + ("oc", "Occitan"), + ("oj", "Ojibwa"), + ("or", "Oriya"), + ("om", "Oromo"), + ("os", "Ossetian, Ossetic"), + ("pi", "Pali"), + ("ps", "Pashto, Pushto"), + ("fa", "Persian"), + ("pl", "Polish"), + ("pt", "Português"), + ("pa", "Punjabi, Panjabi"), + ("qu", "Quechua"), + ("ro", "Romanian, Moldavian, Moldovan"), + ("rm", "Romansh"), + ("rn", "Rundi"), + ("ru", "Russian"), + ("se", "Northern Sami"), + ("sm", "Samoan"), + ("sg", "Sango"), + ("sa", "Sanskrit"), + ("sc", "Sardinian"), + ("sr", "Serbian"), + ("sn", "Shona"), + ("sd", "Sindhi"), + ("si", "Sinhala, Sinhalese"), + ("sk", "Slovak"), + ("sl", "Slovenian"), + ("so", "Somali"), + ("st", "Southern Sotho"), + ("es", "Español"), + ("su", "Sundanese"), + ("sw", "Swahili"), + ("ss", "Swati"), + ("sv", "Swedish"), + ("tl", "Tagalog"), + ("ty", "Tahitian"), + ("tg", "Tajik"), + ("ta", "Tamil"), + ("tt", "Tatar"), + ("te", "Telugu"), + ("th", "Thai"), + ("bo", "Tibetan"), + ("ti", "Tigrinya"), + ("to", "Tonga (Tonga Islands)"), + ("ts", "Tsonga"), + ("tn", "Tswana"), + ("tr", "Turkish"), + ("tk", "Turkmen"), + ("tw", "Twi"), + ("ug", "Uighur, Uyghur"), + ("uk", "Ukrainian"), + ("ur", "Urdu"), + ("uz", "Uzbek"), + ("ve", "Venda"), + ("vi", "Vietnamese"), + ("vo", "Volapük"), + ("wa", "Walloon"), + ("cy", "Welsh"), + ("wo", "Wolof"), + ("xh", "Xhosa"), + ("yi", "Yiddish"), + ("yo", "Yoruba"), + ("za", "Zhuang, Chuang"), + ("zu", "Zulu"), +] + +ROLE = [ + ("Editor-Chefe", _("Editor-Chefe")), + ("Editor(es) Executivo", _("Editor(es) Executivo")), + ("Editor(es) Associados ou de Seção", _("Editor(es) Associados ou de Seção")), + ("Equipe Técnica", _("Equipe Técnica")), +] + +MONTHS = [ + ("01", _("January")), + ("02", _("February")), + ("03", _("March")), + ("04", _("April")), + ("05", _("May")), + ("06", _("June")), + ("07", _("July")), + ("08", _("August")), + ("09", _("September")), + ("10", _("October")), + ("11", _("November")), + ("12", _("December")), +] + +# https://creativecommons.org/share-your-work/cclicenses/ +# There are six different license types, listed from most to least permissive here: +LICENSE_TYPES = [ + ("by", _("by")), + ("by-sa", _("by-sa")), + ("by-nc", _("by-nc")), + ("by-nc-sa", _("by-nc-sa")), + ("by-nd", _("by-nd")), + ("by-nc-nd", _("by-nc-nd")), +] + +GENDER_CHOICES = [ + ("M", _("Male")), + ("F", _("Female")), +] diff --git a/core/tests.py b/core/tests.py new file mode 100644 index 0000000..5a2f468 --- /dev/null +++ b/core/tests.py @@ -0,0 +1,82 @@ +from django.test import TestCase +from django.utils.functional import Promise + +from core.choices import GENDER_CHOICES, LANGUAGE, LICENSE_TYPES, MONTHS, ROLE + + +class LanguageChoicesTest(TestCase): + def test_language_is_list(self): + self.assertIsInstance(LANGUAGE, list) + + def test_language_covers_iso_639_1(self): + codes = [code for code, _ in LANGUAGE] + # Verify some well-known ISO 639-1 codes are present + for code in ["en", "es", "pt", "fr", "de", "zh", "ja", "ar", "ru", "hi"]: + self.assertIn(code, codes) + + def test_language_entries_are_tuples(self): + for entry in LANGUAGE: + self.assertIsInstance(entry, tuple) + self.assertEqual(len(entry), 2) + + def test_language_codes_are_two_chars(self): + for code, _ in LANGUAGE: + self.assertEqual(len(code), 2, f"Language code '{code}' is not 2 characters") + + +class RoleChoicesTest(TestCase): + def test_role_is_list(self): + self.assertIsInstance(ROLE, list) + + def test_role_has_entries(self): + self.assertGreater(len(ROLE), 0) + + def test_role_labels_are_lazy_strings(self): + for _, label in ROLE: + self.assertIsInstance(label, Promise) + + +class MonthsChoicesTest(TestCase): + def test_months_is_list(self): + self.assertIsInstance(MONTHS, list) + + def test_months_has_twelve_entries(self): + self.assertEqual(len(MONTHS), 12) + + def test_months_labels_are_lazy_strings(self): + for _, label in MONTHS: + self.assertIsInstance(label, Promise) + + def test_months_codes_are_zero_padded(self): + expected_codes = [f"{i:02d}" for i in range(1, 13)] + actual_codes = [code for code, _ in MONTHS] + self.assertEqual(actual_codes, expected_codes) + + +class LicenseTypesChoicesTest(TestCase): + def test_license_types_is_list(self): + self.assertIsInstance(LICENSE_TYPES, list) + + def test_license_types_has_six_entries(self): + self.assertEqual(len(LICENSE_TYPES), 6) + + def test_license_types_covers_all_cc_types(self): + codes = [code for code, _ in LICENSE_TYPES] + expected = ["by", "by-sa", "by-nc", "by-nc-sa", "by-nd", "by-nc-nd"] + self.assertEqual(codes, expected) + + def test_license_types_labels_are_lazy_strings(self): + for _, label in LICENSE_TYPES: + self.assertIsInstance(label, Promise) + + +class GenderChoicesTest(TestCase): + def test_gender_choices_is_list(self): + self.assertIsInstance(GENDER_CHOICES, list) + + def test_gender_choices_has_entries(self): + self.assertGreater(len(GENDER_CHOICES), 0) + + def test_gender_choices_labels_are_lazy_strings(self): + for _, label in GENDER_CHOICES: + self.assertIsInstance(label, Promise)