class ResourceTestCase(NoSignalTestCase): def setUp(self): super(ResourceTestCase, self).setUp() self.publisher = Publisher(name="Test Publisher 1") self.publisher.save() self.publisher2 = Publisher(name="Test Publisher 2") self.publisher2.save() self.title = Title(name="Test Title", slug="test-title") self.title.publisher = self.publisher self.title.save() self.media = Media(name="Media Title", slug="test-media") self.media.save() self.language = Language(code="ztest", name="Z Language") self.language.save() def test_string_representation(self): resource = Resource(language=self.language, title=self.title) resource.save() resource.medias.add(self.media) resource.save() self.assertEquals(str(resource), "Test Title in Z Language") self.assertEquals(str(resource.the_publisher()), "Test Publisher 1") resource.publisher = self.publisher2 resource.save() self.assertEquals(str(resource.the_publisher()), "Test Publisher 2")
def test_add_and_delete_from_additionallanguage(self): additional = AdditionalLanguage.objects.create(ietf_tag="zzz-z-test", common_name="ZTest") additional.save() integrate_imports() # run task synchronously data = Language.names_text().split("\n") self.assertTrue("zzz-z-test\tZTest" in data) additional.delete() data = Language.names_text().split("\n") self.assertTrue("zzz-z-test\tZTest" not in data)
def test_additionallanguage_direction(self): additional = AdditionalLanguage.objects.create(ietf_tag="zzz-r-test", common_name="ZRTest", direction="r") additional.save() langnames = Language.names_text().split("\n") self.assertTrue("zzz-r-test\tZRTest" in langnames) data = json.loads(json.dumps(Language.names_data())) langs = {x["lc"]: x for x in data} self.assertTrue("zzz-r-test" in langs) self.assertEquals(langs["zzz-r-test"]["ld"], "rtl")
def test_add_and_delete_from_additionallanguage(self): additional = AdditionalLanguage.objects.create( ietf_tag="zzz-z-test", common_name="ZTest" ) additional.save() integrate_imports() # run task synchronously data = Language.names_text().split("\n") self.assertTrue("zzz-z-test\tZTest" in data) additional.delete() data = Language.names_text().split("\n") self.assertTrue("zzz-z-test\tZTest" not in data)
def setUp(self): super(ResourceTestCase, self).setUp() self.publisher = Publisher(name="Test Publisher 1") self.publisher.save() self.publisher2 = Publisher(name="Test Publisher 2") self.publisher2.save() self.title = Title(name="Test Title", slug="test-title") self.title.publisher = self.publisher self.title.save() self.media = Media(name="Media Title", slug="test-media") self.media.save() self.language = Language(code="ztest", name="Z Language") self.language.save()
def test_additionallanguage_direction(self): additional = AdditionalLanguage.objects.create( ietf_tag="zzz-r-test", common_name="ZRTest", direction="r" ) additional.save() langnames = Language.names_text().split("\n") self.assertTrue("zzz-r-test\tZRTest" in langnames) data = json.loads(json.dumps(Language.names_data())) langs = {x["lc"]: x for x in data} self.assertTrue("zzz-r-test" in langs) self.assertEquals(langs["zzz-r-test"]["ld"], "rtl")
def test_names_export(self): data = Language.names_text().split("\n") data = [x.split("\t")[0] for x in data] # self.assertFalse("bmy" in data) self.assertTrue("aa" in data) self.assertTrue("kmg" in data) self.assertTrue("es-419" in data)
def test_names_data(self): """ Default version of Language.names_data should contain more attributes """ result = Language.names_data() self.assertEqual(len(result), 1) self.assertIn("alt", result[0]) self.assertIn("ld", result[0]) self.assertIn("gw", result[0]) self.assertIn("cc", result[0])
def setUpClass(cls): super(ResourceTestCase, cls).setUpClass() cls.publisher = Publisher(name="Test Publisher 1") cls.publisher.save() cls.publisher2 = Publisher(name="Test Publisher 2") cls.publisher2.save() cls.title = Title(name="Test Title", slug="test-title") cls.title.publisher = cls.publisher cls.title.save() cls.media = Media(name="Media Title", slug="test-media") cls.media.save() cls.language = Language(code="ztest", name="Z Language") cls.language.save()
def test_names_data(self): """ Default version of Language.names_data should contain more attributes """ result = Language.names_data() self.assertEqual(len(result), 1) self.assertIn("pk", result[0]) self.assertIn("lc", result[0]) self.assertIn("ln", result[0]) self.assertIn("ang", result[0]) self.assertIn("lr", result[0]) self.assertIn("hc", result[0]) self.assertIn("alt", result[0]) self.assertIn("ld", result[0]) self.assertIn("gw", result[0]) self.assertIn("cc", result[0])
def test_names_data_short(self): """ Only specified attributes should be returned by names_data (short version) """ result = Language.names_data(short=True) self.assertEqual(len(result), 1) self.assertIn("pk", result[0]) self.assertIn("lc", result[0]) self.assertIn("ln", result[0]) self.assertIn("ang", result[0]) self.assertIn("lr", result[0]) self.assertNotIn("alt", result[0]) self.assertNotIn("ld", result[0]) self.assertNotIn("gw", result[0]) self.assertEqual(result[0].get("lc"), "tl") self.assertEqual(result[0].get("ln"), "Test Language")
def test_names_data_short(self): """ Only specified attributes should be returned by names_data (short version) """ result = Language.names_data(short=True) self.assertEqual(len(result), 1) self.assertIn("pk", result[0]) self.assertIn("lc", result[0]) self.assertIn("ln", result[0]) self.assertIn("ang", result[0]) self.assertIn("lr", result[0]) self.assertIn("hc", result[0]) self.assertNotIn("alt", result[0]) self.assertNotIn("ld", result[0]) self.assertNotIn("gw", result[0]) self.assertNotIn("cc", result[0]) self.assertEqual(result[0].get("lc"), "tl") self.assertEqual(result[0].get("ln"), "Test Language")
def test_get_gateway_languages(self): other_language = Language.objects.create(code="ol", iso_639_3="tol", name="Test Other Language", gateway_flag=False) result = Language.get_gateway_languages() expected_gateway_language = dict(pk=self.lang.pk, lc=self.lang.lc, ln=self.lang.ln, ang=self.lang.ang, lr=self.lang.lr) expected_other_language = dict(pk=other_language.pk, lc=other_language.lc, ln=other_language.ln, ang=other_language.ang, lr=other_language.lr) self.assertIn(expected_gateway_language, result) self.assertNotIn(expected_other_language, result)
def test_names_json_export(self): data = json.loads(json.dumps(Language.names_data())) langs = {x["lc"]: x for x in data} # self.assertFalse("bmy" in langs) self.assertTrue("aa" in langs) self.assertEquals(langs["aa"]["cc"], ["ET"]) self.assertEquals(langs["aa"]["ln"], "Afaraf") self.assertEquals(langs["aa"]["lr"], "Africa") self.assertEquals(langs["aa"]["ld"], "ltr") self.assertTrue("kmg" in langs) self.assertEquals(langs["kmg"]["cc"], ["PG"]) self.assertEquals(langs["kmg"]["ln"], u"K\xe2te") self.assertEquals(langs["kmg"]["lr"], "Pacific") self.assertEquals(langs["kmg"]["ld"], "ltr") self.assertTrue("es-419" in langs) self.assertEquals(langs["es-419"]["cc"], []) self.assertEquals(langs["es-419"]["ln"], u"Espa\xf1ol Latin America") self.assertEquals(langs["es-419"]["lr"], "") self.assertEquals(langs["es-419"]["ld"], "ltr")
def setUpClass(cls): super(OBSTestCase, cls).setUpClass() lang1 = Language(code="z1", name="Z Test 1") lang1.save() lang2 = Language(code="z2", name="Z Test 2") lang2.save()
def setUpClass(cls): country1 = Country(code="c1", name="Country 1") country1.extra_data = {"gateway_language": "gz1"} country1.save() country2 = Country(code="c2", name="Country 2") country2.save() lang1 = Language(code="gz1", name="Z Test 1", gateway_flag=True, gateway_language=None, country=country1) lang1.save() lang2 = Language(code="gz2", name="Z Test 2", gateway_flag=False, gateway_language=lang1, country=country2) lang2.save() lang3 = Language(code="gz3", name="Z Test 3", gateway_flag=False, gateway_language=None, country=country1) lang3.save() lang4 = Language(code="gz4", name="Z Test 4", gateway_flag=False, gateway_language=None, country=country2) lang4.save() lang5 = Language(code="gz5", name="Z Test 5", gateway_flag=False, gateway_language=None, country=None) lang5.save()
def handle_languages_integrated(sender, **kwargs): cache.delete("langnames") cache.set("langnames", Language.names_data(), None)
def setUpClass(cls): lang1 = Language(code="z1", name="Z Test 1") lang1.save() lang2 = Language(code="z2", name="Z Test 2") lang2.save()
def test_codes_export(self): data = Language.codes_text().split(" ") # self.assertFalse("bmy" in data) self.assertTrue("aa" in data) self.assertTrue("kmg" in data) self.assertTrue("es-419" in data)
def names_text_export(request): return HttpResponse(Language.names_text(), content_type="text/plain")
def test_called_inappropriately(self): """ If called inappropriately, function should throw a fail response with message """ status = notify_external_apps() self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance="string") self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance=1) self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance=[]) self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance={}) self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance=()) self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance=object()) self.assertFalse(status.success) self.assertGreater(len(status.message), 0) lang = Language() status = notify_external_apps(instance=lang) self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance=lang, action=None) self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance=lang, action=" ") self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance=lang, action=1) self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance=lang, action=[]) self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance=lang, action={}) self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance=lang, action=()) self.assertFalse(status.success) self.assertGreater(len(status.message), 0) status = notify_external_apps(instance=lang, action=object()) self.assertFalse(status.success) self.assertGreater(len(status.message), 0)
def setUpClass(cls): super(SeedGatewayTestCase, cls).setUpClass() country1 = Country(code="c1", name="Country 1") country1.extra_data = {"gateway_language": "gz1"} country1.save() country2 = Country(code="c2", name="Country 2") country2.save() lang1 = Language(code="gz1", name="Z Test 1", gateway_flag=True, gateway_language=None, country=country1) lang1.save() lang2 = Language(code="gz2", name="Z Test 2", gateway_flag=False, gateway_language=lang1, country=country2) lang2.save() lang3 = Language(code="gz3", name="Z Test 3", gateway_flag=False, gateway_language=None, country=country1) lang3.save() lang4 = Language(code="gz4", name="Z Test 4", gateway_flag=False, gateway_language=None, country=country2) lang4.save() lang5 = Language(code="gz5", name="Z Test 5", gateway_flag=False, gateway_language=None, country=None) lang5.save()