def test_recordings(): if os.path.isdir(datapath): shutil.rmtree(datapath) Data.initializeData() DALMember.insertMember('dan', '123', 'a') vowels = ['a', 'e', 'i', 'o', 'u', '.'] for vowel in vowels: DALRecording.uploadVowelRecording( AudioSegment.from_mp3( os.path.join('./tests/DALtests/testsData/input/a', vowel + '.mp3')), 'dan', 'a', vowel) for vowel in vowels: assert (AudioSegment.from_file( os.path.join('./tests/DALtests/testsData/expectedresult/a', vowel + '.mp3')).raw_data == DALRecording.getVowelRecording( 'dan', 'a', vowel).raw_data)
def uploadSound(self, recording, letter): tone = Tone(letter) # this is a repair of existing tone if tone < self.__tone: toneVowels = splitSound(recording) for i, vowelRecording in enumerate(toneVowels): DALRecording.uploadVowelRecording(vowelRecording, self.__name, tone.letter, vowels[i]) elif tone == self.__tone: toneVowels = splitSound(recording) for i, vowelRecording in enumerate(toneVowels): DALRecording.uploadVowelRecording(vowelRecording, self.__name, tone.letter, vowels[i]) self.__tone = self.__tone.next() DALMember.updateUserProgress(self.__tone.letter, self.__name) else: raise SoundException(SoundError.SENT_RECORDING_AFTER_PROGRESS)
def test_insertMember(): if os.path.isdir(datapath): shutil.rmtree(datapath) Data.initializeData() DALMember.insertMember('dan', '123', 'a') assert (DALMember.memberExists('dan', '123')) assert (not DALMember.memberExists('dan', '12')) assert (not DALMember.memberExists('da', '123')) assert (DALMember.usernameExists('dan')) assert (not DALMember.usernameExists('da')) assert (DALMember.getMemberProgress('dan') == 'a') DALMember.insertMember('1', '2', '3') assert (DALMember.getAllMembers() == [('dan', 'a', '123'), ('1', '3', '2')]) DALMember.updateUserProgress('b', 'dan') assert (DALMember.getMemberProgress('dan') == 'b')
def initializeMember(name, password): member = Member(name, Tone.first()) if DALMember.usernameExists(name): raise SoundException(SoundError.USERNAME_TAKEN) DALMember.insertMember(name, password, member.__tone.letter) return member
def getAllMembers(): rows = DALMember.getAllMembers() members = {} for row in rows: members[row[0]] = row[1] return members
def getMemberByusername(username): if not DALMember.usernameExists(username): raise SoundException(SoundError.USERNAME_DOES_NOT_EXIST) return Member(username, Tone(DALMember.getMemberProgress(username)))
def getMemberBynameAndPassword(username, password): if not DALMember.memberExists(username, password): raise SoundException(SoundError.WRONG_USERNAME_OR_PASSWORD) return Member(username, Tone(DALMember.getMemberProgress(username)))
def zipTone(self, tone, outputpath): DALMember.zipUserTone(self.__name, tone, outputpath)