@@ -46,6 +46,26 @@ def test_import_good_purchases(self):
4646 filehash_md5 = hashlib .md5 (filebytes ).hexdigest ()
4747 self .assertEqual (Purchase .objects .first ().import_source , filehash_md5 )
4848
49+ @authenticate
50+ def test_import_with_no_local_definition (self ):
51+ """
52+ Tests that can import a file without local definition
53+ """
54+ CanteenFactory .create (siret = "82399356058716" , managers = [authenticate .user ])
55+ with open ("./api/tests/files/good_purchase_import_no_local_def.csv" ) as purchase_file :
56+ response = self .client .post (reverse ("import_purchases" ), {"file" : purchase_file })
57+ self .assertEqual (response .status_code , status .HTTP_200_OK )
58+ self .assertEqual (Purchase .objects .count (), 2 )
59+ purchase = Purchase .objects .filter (description = "Pommes, rouges" ).first ()
60+ self .assertEqual (purchase .canteen .siret , "82399356058716" )
61+ self .assertEqual (purchase .description , "Pommes, rouges" )
62+ self .assertEqual (purchase .provider , "Le bon traiteur" )
63+ self .assertEqual (purchase .price_ht , Decimal ("90.11" ))
64+ self .assertEqual (purchase .date , date (2022 , 5 , 2 ))
65+ self .assertEqual (purchase .family , Purchase .Family .PRODUITS_LAITIERS )
66+ self .assertEqual (purchase .characteristics , [Purchase .Characteristic .BIO ])
67+ self .assertEqual (purchase .local_definition , None )
68+
4969 @authenticate
5070 def test_import_purchases_different_separators (self ):
5171 """
0 commit comments