def test_load_trees(self): iso = ISOCode.objects.create(iso_code='abc') lang = Language.objects.create(glotto_code='ubyk1235', name='Ubykh', iso_code=iso) lang.save() load_societies(csv_dict_reader(data_path('societies.csv'))) society = Society.objects.create( ext_id = '455', xd_id = 'xd455', name = 'test', language=lang ) society.save() res = load_trees(data_path()) self.assertEqual(res, 2) sequences = tree_names(data_path()) #labels should be created for the 5 societies in the semitic tree in societies.csv, plus the test society above self.assertEqual(sequences, 6) tree = LanguageTree.objects.filter(name='Abkhaz-Adyge.glotto.trees').first() label = LanguageTreeLabels.objects.filter(label='ubyk1235').first() self.assertIn(label, tree.taxa.all()) self.assertIn(society, label.societies.all()) tree = LanguageTree.objects.filter(name='semitic.trees').first() labels = LanguageTreeLabels.objects.filter(label='Amharic').first() self.assertEqual(tree.taxa.count(), 25) self.assertEqual(labels.societies.count(), 3) self.assertEqual(labels.societies.all().order_by('-languagetreelabelssequence__fixed_order').first().ext_id, 'Ca7') # existing trees are not recreated: self.assertEqual(load_trees(data_path()), 0)
def test_load_trees(self): iso = ISOCode.objects.create(iso_code='abc') lang = Language.objects.create(glotto_code='ubyk1235', name='Ubykh', iso_code=iso) lang.save() load_societies(csv_dict_reader(data_path('societies.csv'))) society = Society.objects.create(ext_id='455', xd_id='xd455', name='test', language=lang) society.save() res = load_trees(data_path()) self.assertEqual(res, 2) sequences = tree_names(data_path()) #labels should be created for the 5 societies in the semitic tree in societies.csv, plus the test society above self.assertEqual(sequences, 6) tree = LanguageTree.objects.filter( name='Abkhaz-Adyge.glotto.trees').first() label = LanguageTreeLabels.objects.filter(label='ubyk1235').first() self.assertIn(label, tree.taxa.all()) self.assertIn(society, label.societies.all()) tree = LanguageTree.objects.filter(name='semitic.trees').first() labels = LanguageTreeLabels.objects.filter(label='Amharic').first() self.assertEqual(tree.taxa.count(), 25) self.assertEqual(labels.societies.count(), 3) self.assertEqual( labels.societies.all().order_by( '-languagetreelabelssequence__fixed_order').first().ext_id, 'Ca7') # existing trees are not recreated: self.assertEqual(load_trees(data_path()), 0)
def test_load_trees(self): iso = ISOCode.objects.create(iso_code='abc') lang = Language.objects.create(glotto_code='ubyk1235', name='Ubykh', iso_code=iso) lang.save() res = load_trees(data_path()) self.assertEqual(res, 1) tree = LanguageTree.objects.filter(name='Abkhaz-Adyge.glotto.trees').first() self.assertIn(lang, tree.languages.all()) # existing trees are not recreated: self.assertEqual(load_trees(data_path()), 0)