<commit_before>#!/usr/bin/env python
#
# This library is free software, distributed under the terms of
# the GNU Lesser General Public License Version 3, or any later version.
# See the COPYING file included in this archive
#
# The docstrings in this module contain epytext markup; API documentation
# may be created by processing this file with epydoc: http://epydoc.sf.net
import os
import sys
import unittest

# Add root directory of the project to our path in order to import db_store
dir_of_executable = os.path.dirname(__file__)
path_to_project_root = os.path.abspath(os.path.join(dir_of_executable, '..'))
sys.path.insert(0, path_to_project_root)
from node.db_store import Obdb


class TestDbOperations(unittest.TestCase):

    def test_insert_select_operations(self):

        # Initialize our db instance
        db = Obdb()

        # Create a dictionary of a random review
        review_to_store = {"pubKey": "123",
                           "subject": "A review",
                           "signature":  "a signature",
                           "text": "Very happy to be a customer.",
                           "rating": 10}

        # Use the insert operation to add it to the db
        db.insertEntry("reviews", review_to_store)

        # Try to retrieve the record we just added based on the pubkey
        retrieved_review = db.selectEntries("reviews", "pubkey = '123'")

        # The above statement will return a list with all the
        # retrieved records as dictionaries
        self.assertEqual(len(retrieved_review), 1)
        retrieved_review = retrieved_review[0]

        # Is the retrieved record the same as the one we added before?
        self.assertEqual(
            review_to_store["pubKey"],
            retrieved_review["pubKey"],
            "123"
        )
        self.assertEqual(
            review_to_store["subject"],
            retrieved_review["subject"],
            "A review"
        )
        self.assertEqual(
            review_to_store["signature"],
            retrieved_review["signature"],
            "a signature"
        )
        self.assertEqual(
            review_to_store["text"],
            retrieved_review["text"],
            "Very happy to be a customer."
        )
        self.assertEqual(
            review_to_store["rating"],
            retrieved_review["rating"],
            10
        )

    def test_update_operation(self):

        # Initialize our db instance
        db = Obdb()

        # Retrieve the record with pubkey equal to '123'
        retrieved_review = db.selectEntries("reviews", {"pubkey": "123"})[0]

        # Check that the rating is still '10' as expected
        self.assertEqual(retrieved_review["rating"], 10)

        # Update the record with pubkey equal to '123'
        # and lower its rating to 9
        db.updateEntries("reviews", {"pubkey": "123"}, {"rating": 9})

        # Retrieve the same record again
        retrieved_review = db.selectEntries("reviews", {"pubkey": "123"})[0]

        # Test that the rating has been updated succesfully
        self.assertEqual(retrieved_review["rating"], 9)

    def test_delete_operation(self):

        # Initialize our db instance
        db = Obdb()

        # Delete the entry with pubkey equal to '123'
        db.deleteEntries("reviews", {"pubkey": "123"})

        # Looking for this record with will bring nothing
        retrieved_review = db.selectEntries("reviews", {"pubkey": "123"})
        self.assertEqual(len(retrieved_review), 0)


if __name__ == '__main__':
    unittest.main()<commit_msg>Updated test to match db_store's new functionality<commit_after>#!/usr/bin/env python
#
# This library is free software, distributed under the terms of
# the GNU Lesser General Public License Version 3, or any later version.
# See the COPYING file included in this archive
#
# The docstrings in this module contain epytext markup; API documentation
# may be created by processing this file with epydoc: http://epydoc.sf.net
import os
import sys
import unittest

# Add root directory of the project to our path in order to import db_store
dir_of_executable = os.path.dirname(__file__)
path_to_project_root = os.path.abspath(os.path.join(dir_of_executable, '..'))
sys.path.insert(0, path_to_project_root)
from node.db_store import Obdb


class TestDbOperations(unittest.TestCase):

    def test_insert_select_operations(self):

        # Initialize our db instance
        db = Obdb("db/ob.db")

        # Create a dictionary of a random review
        review_to_store = {"pubKey": "123",
                           "subject": "A review",
                           "signature":  "a signature",
                           "text": "Very happy to be a customer.",
                           "rating": 10}

        # Use the insert operation to add it to the db
        db.insertEntry("reviews", review_to_store)

        # Try to retrieve the record we just added based on the pubkey
        retrieved_review = db.selectEntries("reviews", "pubkey = '123'")

        # The above statement will return a list with all the
        # retrieved records as dictionaries
        self.assertEqual(len(retrieved_review), 1)
        retrieved_review = retrieved_review[0]

        # Is the retrieved record the same as the one we added before?
        self.assertEqual(
            review_to_store["pubKey"],
            retrieved_review["pubKey"],
            "123"
        )
        self.assertEqual(
            review_to_store["subject"],
            retrieved_review["subject"],
            "A review"
        )
        self.assertEqual(
            review_to_store["signature"],
            retrieved_review["signature"],
            "a signature"
        )
        self.assertEqual(
            review_to_store["text"],
            retrieved_review["text"],
            "Very happy to be a customer."
        )
        self.assertEqual(
            review_to_store["rating"],
            retrieved_review["rating"],
            10
        )

    def test_update_operation(self):

        # Initialize our db instance
        db = Obdb("db/ob.db")

        # Retrieve the record with pubkey equal to '123'
        retrieved_review = db.selectEntries("reviews", "pubkey = '123'")[0]

        # Check that the rating is still '10' as expected
        self.assertEqual(retrieved_review["rating"], 10)

        # Update the record with pubkey equal to '123'
        # and lower its rating to 9
        db.updateEntries("reviews", {"pubkey": "123"}, {"rating": 9})

        # Retrieve the same record again
        retrieved_review = db.selectEntries("reviews", "pubkey = '123'")[0]

        # Test that the rating has been updated succesfully
        self.assertEqual(retrieved_review["rating"], 9)

    def test_delete_operation(self):

        # Initialize our db instance
        db = Obdb("db/ob.db")

        # Delete the entry with pubkey equal to '123'
        db.deleteEntries("reviews", {"pubkey": "123"})

        # Looking for this record with will bring nothing
        retrieved_review = db.selectEntries("reviews", "pubkey = '123'")
        self.assertEqual(len(retrieved_review), 0)


if __name__ == '__main__':
    unittest.main()
{'fraction_non_alphanumeric': 0.09508606329816768, 'fraction_numerical': 0.014158800666296502, 'mean_word_length': 2.366822429906542, 'pattern_counts': {'":': 19, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7273154', 'n_tokens_mistral': 2045, 'n_tokens_neox': 1912, 'n_words': 621}