1 | Plone Audio Patch |
---|
2 | ================= |
---|
3 | |
---|
4 | The following doctest suite is meant to be run against mp3 audio implementation |
---|
5 | to ensure that p4a.audiopatch added to p4a.audio support for correct reading not |
---|
6 | english id3 tag info. (This doctest suite borrows much from Plone4ArtistsAudio testsuite.) |
---|
7 | |
---|
8 | We begin this process by creating a new instance of a file content |
---|
9 | type. |
---|
10 | |
---|
11 | >>> id = self.folder.invokeFactory(self.file_content_type, 'samplefile') |
---|
12 | >>> samplefile = self.folder[id] |
---|
13 | |
---|
14 | Keeping the sample audio files small it should be no problem loading |
---|
15 | them into memory for testing purposes. So we proceed to give the |
---|
16 | previous file instance the sample file binary data. |
---|
17 | |
---|
18 | >>> f = open(self.samplefile, 'rb') |
---|
19 | >>> data = f.read() |
---|
20 | >>> f.close() |
---|
21 | >>> samplefile.getRawFile().update_data(data, self.required_mimetype, len(data)) |
---|
22 | |
---|
23 | This is all fine and dandy but since we went a little lowlevel to update |
---|
24 | the file, this means IAudio hasn't had a chance to update the audio |
---|
25 | metadata and related logic. So we need to fire IObjectModifiedEvent to |
---|
26 | kick IAudio. |
---|
27 | |
---|
28 | >>> from zope import event |
---|
29 | >>> from zope.app.event import objectevent |
---|
30 | >>> event.notify(objectevent.ObjectModifiedEvent(samplefile)) |
---|
31 | |
---|
32 | Now lets look up IAudio and get the data we expect from importing the |
---|
33 | audio file. |
---|
34 | |
---|
35 | >>> from p4a.audio.interfaces import IAudio |
---|
36 | >>> audiofile = IAudio(samplefile) |
---|
37 | |
---|
38 | Lets check does audiofile provide IAudioEncoded interface (added by Plone4artistsAudioPatch) |
---|
39 | |
---|
40 | >>> from p4a.audiopatch.interfaces import IAudioEncoded |
---|
41 | >>> IAudioEncoded.providedBy(audiofile) |
---|
42 | True |
---|
43 | >>> audiofile.encoding == '' |
---|
44 | True |
---|
45 | >>> audiofile.original_encoding == self.eyeD3_encoding |
---|
46 | True |
---|
47 | |
---|
48 | Lets check that audiofile info fields are encoded wrong |
---|
49 | |
---|
50 | >>> audiofile.title == self.fields['title'] |
---|
51 | False |
---|
52 | >>> audiofile.album == self.fields['album'] |
---|
53 | False |
---|
54 | >>> audiofile.artist == self.fields['artist'] |
---|
55 | False |
---|
56 | |
---|
57 | Now we set right encoding of id3 tag. |
---|
58 | |
---|
59 | >>> audiofile.encoding = self.tag_encoding |
---|
60 | >>> audiofile.title == self.fields['title'] |
---|
61 | True |
---|
62 | >>> audiofile.album == self.fields['album'] |
---|
63 | True |
---|
64 | >>> audiofile.artist == self.fields['artist'] |
---|
65 | True |
---|
66 | |
---|
67 | Do a little CMF testing. |
---|
68 | |
---|
69 | >>> samplefile.Title() == self.fields['title'].encode('utf-8') |
---|
70 | True |
---|
71 | |
---|
72 | Test reset of encodings fields when IObjectModifiedEvent fired. |
---|
73 | |
---|
74 | >>> event.notify(objectevent.ObjectModifiedEvent(samplefile)) |
---|
75 | >>> audiofile.encoding |
---|
76 | '' |
---|
77 | >>> audiofile.original_encoding |
---|
78 | 'utf_8' |
---|
79 | |
---|
80 | |
---|