@@ -32,11 +32,15 @@ def text(self):
3232 "Matthew Robinson <[email protected] >" 3333 ],
3434 "subject": "Test Email",
35- "filename": "fake-email.eml"
35+ "filename": "fake-email.eml",
36+ "filetype": "message/rfc822"
3637 }
3738 }
3839]"""
3940
41+ def json (self ):
42+ return json .loads (self .text )
43+
4044
4145def test_partition_via_api_from_filename (monkeypatch ):
4246 monkeypatch .setattr (
@@ -47,6 +51,7 @@ def test_partition_via_api_from_filename(monkeypatch):
4751 filename = os .path .join (DIRECTORY , ".." , ".." , "example-docs" , "fake-email.eml" )
4852 elements = partition_via_api (filename = filename , api_key = "FAKEROO" )
4953 assert elements [0 ] == NarrativeText ("This is a test email to use for unit tests." )
54+ assert elements [0 ].metadata .filetype == "message/rfc822"
5055
5156
5257def test_partition_via_api_from_file (monkeypatch ):
@@ -60,6 +65,7 @@ def test_partition_via_api_from_file(monkeypatch):
6065 with open (filename , "rb" ) as f :
6166 elements = partition_via_api (file = f , file_filename = filename , api_key = "FAKEROO" )
6267 assert elements [0 ] == NarrativeText ("This is a test email to use for unit tests." )
68+ assert elements [0 ].metadata .filetype == "message/rfc822"
6369
6470
6571def test_partition_via_api_from_file_raises_without_filename (monkeypatch ):
@@ -110,7 +116,8 @@ def text(self):
110116 "Matthew Robinson <[email protected] >" 111117 ],
112118 "subject": "Test Email",
113- "filename": "fake-email.eml"
119+ "filename": "fake-email.eml",
120+ "filetype": "message/rfc822"
114121 }
115122 }
116123 ],
@@ -128,13 +135,27 @@ def text(self):
128135 "Matthew Robinson <[email protected] >" 129136 ],
130137 "subject": "Test Email",
131- "filename": "fake-email.eml"
138+ "filename": "fake-email.eml",
139+ "filetype": "message/rfc822"
132140 }
133141 }
134142 ]
135143]"""
136144
137145
146+ def test_partition_multiple_via_api_with_single_filename (monkeypatch ):
147+ monkeypatch .setattr (
148+ requests ,
149+ "post" ,
150+ lambda * args , ** kwargs : MockResponse (status_code = 200 ),
151+ )
152+ filename = os .path .join (DIRECTORY , ".." , ".." , "example-docs" , "fake-email.eml" )
153+
154+ elements = partition_multiple_via_api (filenames = [filename ], api_key = "FAKEROO" )
155+ assert elements [0 ][0 ] == NarrativeText ("This is a test email to use for unit tests." )
156+ assert elements [0 ][0 ].metadata .filetype == "message/rfc822"
157+
158+
138159def test_partition_multiple_via_api_from_filenames (monkeypatch ):
139160 monkeypatch .setattr (
140161 requests ,
@@ -150,6 +171,7 @@ def test_partition_multiple_via_api_from_filenames(monkeypatch):
150171 elements = partition_multiple_via_api (filenames = filenames , api_key = "FAKEROO" )
151172 assert len (elements ) == 2
152173 assert elements [0 ][0 ] == NarrativeText ("This is a test email to use for unit tests." )
174+ assert elements [0 ][0 ].metadata .filetype == "message/rfc822"
153175
154176
155177def test_partition_multiple_via_api_from_files (monkeypatch ):
@@ -173,6 +195,7 @@ def test_partition_multiple_via_api_from_files(monkeypatch):
173195 )
174196 assert len (elements ) == 2
175197 assert elements [0 ][0 ] == NarrativeText ("This is a test email to use for unit tests." )
198+ assert elements [0 ][0 ].metadata .filetype == "message/rfc822"
176199
177200
178201def test_partition_multiple_via_api_raises_with_bad_response (monkeypatch ):
0 commit comments