예제 #1
0
 def setUp(self):
     self.commandes = mock()
     self.fabrique = mock()
     self.service = ServiceCommande(self.commandes, self.fabrique)
     self.devis = mock()
     self.date = mock()
     self.createur = mock()
     self.commande = mock()
     
     when(self.fabrique).nouvelle_commande(self.createur, self.date, self.devis).thenReturn(self.commande)
     
     when(self.commande).devis().thenReturn(self.devis)
     when(self.commande).date().thenReturn(self.date)
     when(self.commande).createur().thenReturn(self.createur)
예제 #2
0
class TestJaneCreeUneCommandePourUnDevisValideEtUneDateDInterventionCorrecte(unittest.TestCase):

    def setUp(self):
        self.commandes = mock()
        self.fabrique = mock()
        self.service = ServiceCommande(self.commandes, self.fabrique)
        self.devis = mock()
        self.date = mock()
        self.createur = mock()
        self.commande = mock()
        
        when(self.fabrique).nouvelle_commande(self.createur, self.date, self.devis).thenReturn(self.commande)
        
        when(self.commande).devis().thenReturn(self.devis)
        when(self.commande).date().thenReturn(self.date)
        when(self.commande).createur().thenReturn(self.createur)
        
    def test_Jane_cree_une_commande_pour_un_devis_valide_et_une_date_d_intervention_correcte_ajoute_la_commande(self):
        """Test l'ajout d'une commande valide par Jane"""
        
        """
        given   : un devis valide, une date d'intervention valide, un utilisateur autorise
        when    : ajoute le devis avec la date d'intervention dans une commande
        then    : la commande est cree et ajoutee a la liste des commandes
        """

        when(self.devis).expire().thenReturn(False)
        when(self.date).expire().thenReturn(False)
        when(self.createur).peut_creer_commandes().thenReturn(True)
        self.service.ajouter_commande(self.createur, self.date, self.devis)
        verify(self.commandes).append(self.commande)
        
    def test_Jane_cree_une_commande_pour_un_devis_invalide_et_une_date_d_intervention_correcte_leve_une_exception(self):
        """Test l'ajout d'une commande avec un devis invalide. Une exception est alors levee"""
        
        """
        given   : un devis invalide, une date d'intervention valide, un utilisateur autorise
        when    : ajoute le devis avec la date d'intervention dans une commande
        then    : une exception est leve car le devis est invalide (DevisInvalide)
        """
        
        when(self.devis).expire().thenReturn(True)
        when(self.date).expire().thenReturn(False)
        when(self.createur).peut_creer_commandes().thenReturn(True)
        self.assertRaises(DevisInvalide, self.service.ajouter_commande, self.createur, self.date, self.devis)
        
    def test_Jane_cree_une_commande_pour_un_devis_invalide_et_une_date_d_intervention_correcte_n_ajoute_pas(self):
        """Test l'ajout d'une commande avec un devis invalide. L'ajout n'a alors pas lieu"""        
        
        """
        given   : un devis invalide, une date d'intervention valide, un utilisateur autorise
        when    : ajoute le devis avec la date d'intervention dans une commande
        then    : la commande n'est pas ajoutee a la liste des commandes
        """
        
        when(self.devis).expire().thenReturn(True)
        when(self.date).expire().thenReturn(False)
        when(self.createur).peut_creer_commandes().thenReturn(True)
        try:
            self.service.ajouter_commande(self.createur, self.date, self.devis)
        except(DevisInvalide):
            pass
        verify(self.commandes, never).append(self.commande)
        
    def test_Jane_cree_une_commande_pour_un_devis_valide_et_une_date_d_intervention_incorrecte_leve_une_exception(self):
        """Test l'ajout d'une commande avec une date invalide. Une exception est levee"""
        
        """
        given   : un devis valide, une date d'intervention invalide, un utilisateur autorise
        when    : ajoute le devis avec la date d'intervention dans une commande
        then    : une exception est levee car la date est invalide (DateInterventionInvalide)
        """
        
        when(self.devis).expire().thenReturn(False)
        when(self.date).expire().thenReturn(True)
        when(self.createur).peut_creer_commandes().thenReturn(True)        
        self.assertRaises(DateInterventionInvalide, self.service.ajouter_commande, self.createur, self.date, self.devis)
        
    def test_Jane_cree_une_commande_pour_un_devis_valide_et_une_date_d_intervention_incorrecte_n_ajoute_pas(self):
        """Test l'ajout d'une commande avec une date invalide. L'ajout n'a alors pas lieu"""
        
        """
        given   : un devis valide, une date d'intervention invalide, un utilisateur autorise
        when    : ajoute le devis avec la date d'intervention dans une commande
        then    : la commande n'est pas ajoutee a la liste des commandes
        """
        
        when(self.devis).expire().thenReturn(False)
        when(self.date).expire().thenReturn(True) 
        when(self.createur).peut_creer_commandes().thenReturn(True) 
        try:
            self.service.ajouter_commande(self.createur, self.date, self.devis)      
        except(DateInterventionInvalide):
            pass    
        verify(self.commandes, never).append(self.commande)
        
    def test_Jane_cree_une_commande_mais_n_a_pas_le_droit_leve_une_exception(self):
        """Test Jane ajoute une commande, mais n'a pas le droit. Une exception est levee"""
        
        """
        given   : un devis valide, une date d'intervention valide, un utilisateur non autorise
        when    : ajoute le devis avec la date d'intervention dans une commande
        then    : une exception est levee car l'utilisateur n'a pas les droits de creation de commandes (UtilisateurNonAutorise)
        """
        
        when(self.devis).expire().thenReturn(False)
        when(self.date).expire().thenReturn(False)
        when(self.createur).peut_creer_commandes().thenReturn(False)
        self.assertRaises(UtilisateurNonAutorise, self.service.ajouter_commande, self.createur, self.date, self.devis)
        
    def test_Jane_cree_une_commande_mais_n_a_pas_le_droit_n_ajoute_pas(self):
        """Test Jane ajoute une commande, mais n'a pas le droit. L'ajout n'a alors pas lieu"""
        
        """
        given   : un devis valide, une date d'intervention valide, un utilisateur non autorise
        when    : ajoute le devis avec la date d'intervention dans une commande
        then    : la commande n'est pas ajoutee a la liste des commandes
        """
        
        when(self.devis).expire().thenReturn(False)
        when(self.date).expire().thenReturn(False)
        when(self.createur).peut_creer_commandes().thenReturn(False)
        try:
            self.service.ajouter_commande(self.createur, self.date, self.devis)
        except(UtilisateurNonAutorise):
            pass
        verify(self.commandes, never).append(self.commande)