예제 #1
0
    def delete_entry(self, word):
        DatabaseHandler.delete_entry(word, self.database)

        try:
            self.trie.delete_word(word)
        except AttributeError:
            return
 def test_existing_extract_entry(self):
     handler = DatabaseHandler()
     expected_result = {'Entry': 'Lampe', 'Gender': 'die',
                        'Plural': 'Lampen', 'Genetive': 'Lampe',
                        'Meaning': 'lamp', 'Examples': '-'}
     self.assertEqual(handler.extract_entry('Lampe', DATABASE)[0],
                      expected_result)
 def test_existing_extract_entry(self):
     handler = DatabaseHandler()
     expected_result = {
         'Entry': 'Lampe',
         'Gender': 'die',
         'Plural': 'Lampen',
         'Genetive': 'Lampe',
         'Meaning': 'lamp',
         'Examples': '-'
     }
     self.assertEqual(
         handler.extract_entry('Lampe', DATABASE)[0], expected_result)
 def test_edit_entry(self):
     handler = DatabaseHandler()
     self.assertEqual(
         handler.extract_entry('Hund', DATABASE)[0]['Gender'], 'der')
     handler.edit_entry('Hund', 'Gender', 'xyz', DATABASE)
     self.assertEqual(
         handler.extract_entry('Hund', DATABASE)[0]['Gender'], 'xyz')
     handler.edit_entry('Hund', 'Gender', 'der', DATABASE)
     self.assertEqual(
         handler.extract_entry('Hund', DATABASE)[0]['Gender'], 'der')
예제 #5
0
    def edit_entry(self, entry, field, new_value):
        DatabaseHandler.edit_entry(entry, field, new_value, self.database)

        try:
            word_in_trie = self.trie.search_for_word(entry)

            if field == 'Entry':
                self.trie.delete_word(word_in_trie.word_hash['Entry'])
                word_in_trie.word_hash['Entry'] = new_value
                self.trie.add_word(word_in_trie)
            else:
                word_in_trie.word_hash[field] = new_value
        except AttributeError:
            return
 def test_edit_entry(self):
     handler = DatabaseHandler()
     self.assertEqual(handler.extract_entry('Hund', DATABASE)[0]['Gender'],
                      'der')
     handler.edit_entry('Hund', 'Gender', 'xyz', DATABASE)
     self.assertEqual(handler.extract_entry('Hund', DATABASE)[0]['Gender'],
                      'xyz')
     handler.edit_entry('Hund', 'Gender', 'der', DATABASE)
     self.assertEqual(handler.extract_entry('Hund', DATABASE)[0]['Gender'],
                      'der')
 def test_add_noun_and_delete(self):
     handler = DatabaseHandler()
     test_noun = Noun({'Entry': 'xyz', 'Gender': 'das',
                       'Plural': 'Beispiele', 'Genetive': 'Beispieles',
                       'Meaning': 'example', 'Examples': 'Too lazy'})
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
     handler.add_noun(test_noun, DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), True)
     handler.delete_entry('xyz', DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
 def test_add_adjective_and_delete(self):
     handler = DatabaseHandler()
     test_adj = Adjective({'Entry': 'xyz', 'Comparative': 'a',
                           'Superlative': 'b',
                           'Meaning': 'c', 'Examples': 'd'})
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
     handler.add_adjective(test_adj, DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), True)
     handler.delete_entry('xyz', DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
 def test_add_adjective_and_delete(self):
     handler = DatabaseHandler()
     test_adj = Adjective({
         'Entry': 'xyz',
         'Comparative': 'a',
         'Superlative': 'b',
         'Meaning': 'c',
         'Examples': 'd'
     })
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
     handler.add_adjective(test_adj, DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), True)
     handler.delete_entry('xyz', DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
 def test_add_verb_and_delete(self):
     handler = DatabaseHandler()
     test_verb = Verb({'Entry': 'xyz', 'Used_case': 'a',
                       'Preposition': 'b', 'Separable': 'c',
                       'Forms': 'd', 'Examples': 'e',
                       'Transitive': 'e', 'Meaning': 'm'})
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
     handler.add_verb(test_verb, DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), True)
     handler.delete_entry('xyz', DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
 def test_add_noun_and_delete(self):
     handler = DatabaseHandler()
     test_noun = Noun({
         'Entry': 'xyz',
         'Gender': 'das',
         'Plural': 'Beispiele',
         'Genetive': 'Beispieles',
         'Meaning': 'example',
         'Examples': 'Too lazy'
     })
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
     handler.add_noun(test_noun, DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), True)
     handler.delete_entry('xyz', DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
예제 #12
0
 def extract_entry(self, word):
     try:
         found_entry = self.trie.search_for_word(word)
         if found_entry:
             return found_entry
         raise DatabaseError
     except AttributeError:
         entry_data = DatabaseHandler.extract_entry(word, self.database)
         class_name = getattr(sys.modules[__name__], entry_data[1][:-1])
         return class_name(entry_data[0])
 def test_add_verb_and_delete(self):
     handler = DatabaseHandler()
     test_verb = Verb({
         'Entry': 'xyz',
         'Used_case': 'a',
         'Preposition': 'b',
         'Separable': 'c',
         'Forms': 'd',
         'Examples': 'e',
         'Transitive': 'e',
         'Meaning': 'm'
     })
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
     handler.add_verb(test_verb, DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), True)
     handler.delete_entry('xyz', DATABASE)
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
 def test_add_high_score(self):
     handler = DatabaseHandler()
     high_score = {'Name': 'Robert', 'Date': '07.08.2016 11:30:30',
                   'Score': '0.7', 'Questions': '7',
                   'Description': 'Nouns with Meaning'}
     handler.add_highscore(high_score, HS_DB)
     all_high_scores = handler.extract_all_high_scores(HS_DB)
     self.assertEqual(len(all_high_scores), 1)
     self.assertEqual(all_high_scores[0][0], 'Robert')
     handler.clear_database(HS_DB)
 def test_add_high_score(self):
     handler = DatabaseHandler()
     high_score = {
         'Name': 'Robert',
         'Date': '07.08.2016 11:30:30',
         'Score': '0.7',
         'Questions': '7',
         'Description': 'Nouns with Meaning'
     }
     handler.add_highscore(high_score, HS_DB)
     all_high_scores = handler.extract_all_high_scores(HS_DB)
     self.assertEqual(len(all_high_scores), 1)
     self.assertEqual(all_high_scores[0][0], 'Robert')
     handler.clear_database(HS_DB)
예제 #16
0
 def add_entry(self, database):
     DatabaseHandler.add_noun(self, database)
 def test_nonexisting_extract_entry(self):
     handler = DatabaseHandler()
     self.assertRaises(DatabaseError, handler.extract_entry, 'xyz',
                       DATABASE)
 def test_exists_entry(self):
     handler = DatabaseHandler()
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
     self.assertEqual(handler.exists_entry('Hund', DATABASE), True)
예제 #19
0
 def add_high_score(self, database):
     DatabaseHandler.add_highscore(self.to_dict(), database)
예제 #20
0
 def add_entry(self, database):
     DatabaseHandler.add_verb(self, database)
예제 #21
0
 def extract_all_high_scores(self, database):
     return DatabaseHandler.extract_all_high_scores(database)
예제 #22
0
 def add_entry(self, database):
     DatabaseHandler.add_noun(self, database)
예제 #23
0
 def exists_entry(self, word):
     try:
         return bool(self.trie.search_for_word(word))
     except AttributeError:
         return DatabaseHandler.exists_entry(word, self.database)
 def test_exists_entry(self):
     handler = DatabaseHandler()
     self.assertEqual(handler.exists_entry('xyz', DATABASE), False)
     self.assertEqual(handler.exists_entry('Hund', DATABASE), True)
예제 #25
0
 def add_entry(self, database):
     DatabaseHandler.add_adjective(self, database)
예제 #26
0
 def add_entry(self, database):
     DatabaseHandler.add_verb(self, database)