1+ """
2+ Module des tests unitaires pour les classes contenant les données des logs Apache
3+ (ClientInformations, RequetesInformations et ReponseInformations).
4+ """
5+
6+ import pytest
7+ from datetime import datetime , timezone , timedelta
8+ from donnees .client_informations import ClientInformations
9+ from donnees .requete_informations import RequeteInformations
10+ from donnees .reponse_informations import ReponseInformations
11+
12+ @pytest .mark .parametrize ("adresse_ip, identifiant_rfc, utilisateur, agent_utilisateur" , [
13+ ("192.168.0.1" , "rfc" , "utilisateur" , "Mozilla/5.0" )
14+ ])
15+ def test_client_informations_valide (adresse_ip ,
16+ identifiant_rfc ,
17+ utilisateur ,
18+ agent_utilisateur ):
19+ client = ClientInformations (
20+ adresse_ip ,
21+ identifiant_rfc ,
22+ utilisateur ,
23+ agent_utilisateur
24+ )
25+ assert client .adresse_ip == adresse_ip
26+ assert client .identifiant_rfc == identifiant_rfc
27+ assert client .nom_utilisateur == utilisateur
28+ assert client .agent_utilisateur == agent_utilisateur
29+
30+ @pytest .mark .parametrize ("adresse_ip, identifiant_rfc, utilisateur, agent_utilisateur" , [
31+ (False , "rfc" , "utilisateur" , "Mozilla/5.0" ),
32+ ("192.168.0.1" , False , "utilisateur" , "Mozilla/5.0" ),
33+ ("192.168.0.1" , "rfc" , False , "Mozilla/5.0" ),
34+ ("192.168.0.1" , "rfc" , "utilisateur" , False )
35+ ])
36+ def test_client_exception_type_invalide (adresse_ip ,
37+ identifiant_rfc ,
38+ utilisateur ,
39+ agent_utilisateur ):
40+ with pytest .raises (TypeError ):
41+ client = ClientInformations (
42+ adresse_ip ,
43+ identifiant_rfc ,
44+ utilisateur ,
45+ agent_utilisateur
46+ )
47+
48+ @pytest .mark .parametrize ("horodatage, methode_http, url, protocole_http, ancienne_url" , [
49+ (datetime (2012 , 12 , 12 , 10 , 10 , 10 , tzinfo = timezone (timedelta (hours = 10 ))),
50+ "POST" , "essaie.fr/contact" , "HTTP/1.2" , "essaie.fr/accueil" )
51+ ])
52+ def test_requete_informations_valide (horodatage ,
53+ methode_http ,
54+ url ,
55+ protocole_http ,
56+ ancienne_url ):
57+ requete = RequeteInformations (
58+ horodatage ,
59+ methode_http ,
60+ url ,
61+ protocole_http ,
62+ ancienne_url
63+ )
64+ assert requete .horodatage == horodatage
65+ assert requete .methode_http == methode_http
66+ assert requete .url == url
67+ assert requete .protocole_http == protocole_http
68+ assert requete .ancienne_url == ancienne_url
69+
70+ @pytest .mark .parametrize ("horodatage, methode_http, url, protocole_http, ancienne_url" , [
71+ (False , "POST" , "essaie.fr/contact" , "HTTP/1.2" , "essaie.fr/accueil" ),
72+ (datetime (2012 , 12 , 12 , 10 , 10 , 10 , tzinfo = timezone (timedelta (hours = 10 ))),
73+ False , "essaie.fr/contact" , "HTTP/1.2" , "essaie.fr/accueil" ),
74+ (datetime (2012 , 12 , 12 , 10 , 10 , 10 , tzinfo = timezone (timedelta (hours = 10 ))),
75+ "POST" , False , "HTTP/1.2" , "essaie.fr/accueil" ),
76+ (datetime (2012 , 12 , 12 , 10 , 10 , 10 , tzinfo = timezone (timedelta (hours = 10 ))),
77+ "POST" , "essaie.fr/contact" , False , "essaie.fr/accueil" ),
78+ (datetime (2012 , 12 , 12 , 10 , 10 , 10 , tzinfo = timezone (timedelta (hours = 10 ))),
79+ "POST" , "essaie.fr/contact" , "HTTP/1.2" , False ),
80+ ])
81+ def test_requete_exception_type_invalide (horodatage ,
82+ methode_http ,
83+ url ,
84+ protocole_http ,
85+ ancienne_url ):
86+ with pytest .raises (TypeError ):
87+ requete = RequeteInformations (
88+ horodatage ,
89+ methode_http ,
90+ url ,
91+ protocole_http ,
92+ ancienne_url
93+ )
94+
95+ @pytest .mark .parametrize ("code_statut_http, taille_octets" , [
96+ (404 , 50 )
97+ ])
98+ def test_reponse_informations_valide (code_statut_http ,
99+ taille_octets ):
100+ reponse = ReponseInformations (
101+ code_statut_http ,
102+ taille_octets
103+ )
104+ assert reponse .code_statut_http == code_statut_http
105+ assert reponse .taille_octets == taille_octets
106+
107+ @pytest .mark .parametrize ("code_statut_http, taille_octets" , [
108+ (False , 50 ),
109+ (404 , False )
110+ ])
111+ def test_reponse_exception_type_invalide (code_statut_http ,
112+ taille_octets ):
113+ with pytest .raises (TypeError ):
114+ reponse = ReponseInformations (
115+ code_statut_http ,
116+ taille_octets
117+ )
0 commit comments