Exemplo n.º 1
0
    def test_insert_row(self):
        """Testing method / function insert_row."""
        # Add a language and pair_xlate_group entry to the database
        code = data.hashstring(str(random()))
        _translation = data.hashstring(str(random()))
        language.insert_row(code, _translation)
        idx_language = language.exists(code)
        pair_xlate_group.insert_row(_translation)
        idx_pair_xlate_group = pair_xlate_group.exists(_translation)

        # Make sure row does not exist
        translation = data.hashstring(str(random()))
        key = data.hashstring(str(random()))
        units = data.hashstring(str(random()))
        result = pair_xlate.pair_xlate_exists(idx_pair_xlate_group,
                                              idx_language, key)
        self.assertFalse(result)

        # Add an entry to the database
        pair_xlate.insert_row(key, translation, units, idx_language,
                              idx_pair_xlate_group)

        # Test
        result = pair_xlate.pair_xlate_exists(idx_pair_xlate_group,
                                              idx_language, key)
        self.assertTrue(result)
Exemplo n.º 2
0
    def test_update_row(self):
        """Testing method / function update_row."""
        # Add a language and pair_xlate_group entry to the database
        code = data.hashstring(str(random()))
        _translation = data.hashstring(str(random()))
        language.insert_row(code, _translation)
        idx_language = language.exists(code)
        pair_xlate_group.insert_row(_translation)
        idx_pair_xlate_group = pair_xlate_group.exists(_translation)

        # Make sure row does not exist
        translation = data.hashstring(str(random()))
        key = data.hashstring(str(random()))
        units = data.hashstring(str(random()))
        result = pair_xlate.pair_xlate_exists(idx_pair_xlate_group,
                                              idx_language, key)
        self.assertFalse(result)

        # Add an entry to the database
        pair_xlate.insert_row(key, translation, units, idx_language,
                              idx_pair_xlate_group)

        # Test existence
        result = pair_xlate.pair_xlate_exists(idx_pair_xlate_group,
                                              idx_language, key)
        self.assertTrue(result)

        # Test update
        new_translation = data.hashstring(str(random()))
        pair_xlate.update_row(key, new_translation, units, idx_language,
                              idx_pair_xlate_group)

        with db.db_query(20071) as session:
            row = session.query(PairXlate).filter(
                and_(PairXlate.idx_pair_xlate_group == idx_pair_xlate_group,
                     PairXlate.key == key.encode(),
                     PairXlate.idx_language == idx_language)).one()
        self.assertEqual(row.translation.decode(), new_translation)