def test_create_filiere_admission(self): fa = FiliereAdmission(nom='Ecole Jedi') fa.save() # fa exists in DB ? self.assertNotEqual(fa.id, 0) # can we retrieve fa in DB ? fa_id = fa.id fa = None fa = FiliereAdmission.objects.get(nom='Ecole Jedi') self.assertEqual(fa.id, fa_id)
def create_admission(row, etat_civil): """Read an excel row and save the corresponding Admission object in database""" errors = [] ad = Admission() try: ad.filiere_org = FiliereAdmission.objects.get( nom=row['origine_avant_BS']) except FiliereAdmission.DoesNotExist: ad.filiere_org = FiliereAdmission(nom=row['origine_avant_BS']) try: ad.domaine_org = DomaineAdmission.objects.get( nom=row['filiere_avant_BS']) except DomaineAdmission.DoesNotExist: ad.domaine_org = DomaineAdmission(nom=row['filiere_avant_BS']) ad.annee_admission = row['annee_admission'] ad.rang_pre_BS = row['classement_avant_BS'] ad.taille_promo_pre_BS = row['taille_de_promo_avant_BS'] try: ad.full_clean() except ValidationError, e: m = dict(e.message_dict) errors.append([ str("%s %s" % (etat_civil.prenom, etat_civil.nom_insa)), [list(k) for k in zip(m.keys(), m.values())] ])
def setUp(self): fa = FiliereAdmission(nom='Ecole Jedi') da = DomaineAdmission(nom='Parachutage') fa.save() da.save()