<commit_before># coding=utf-8

import sys
import struct
import unittest
from test_000_config import TestConfig
from test_001_connection import TestConnection

from gi.repository import Midgard
from gi.repository import GObject

class TestObjectMetadataCrud(unittest.TestCase):
  mgd = None
  bookstore = None

  def setUp(self):
    if self.mgd == None:
      self.mgd = TestConnection.openConnection()
    if self.bookstore is None:
      self.bookstore = Midgard.Object.factory(self.mgd, "gir_test_book_store", None)
      self.bookstore.set_property("name", "BookStore")
      self.bookstore.create()

  def tearDown(self):
    if self.bookstore is not None:
      self.bookstore.purge(False)
    self.mgd.close()
    self.mgd = None

  def getNewBook(self):
    obj = Midgard.Object.factory(self.mgd, "gir_test_book_crud", None)
    title = "The Metadata of a Holly Grail"
    obj.set_property("title", title)
    obj.set_property("store", self.bookstore.get_property("id"))
    return obj

  def testMetadataCreate(self):
    obj = self.getNewBook()
    
    score = -1
    authors = "White rabbit team"
    hidden = False

    metadata = obj.get_property("metadata")
    metadata.set_property("score", score)
    metadata.set_property("authors", authors)
    metadata.set_property("hidden", hidden)

    self.assertTrue(obj.create())
    new_obj = Midgard.Object.factory(self.mgd, "gir_test_book_crud", obj.get_property("guid"))
    self.assertIsInstance(new_obj, Midgard.Object)
    new_metadata = new_obj.get_property("metadata")
    self.assertEqual(new_metadata.get_property("score"), score)
    self.assertEqual(new_metadata.get_property("authors"), authors)
    self.assertEqual(new_metadata.get_property("hidden"), hidden)

    # Read only properties 
    self.assertIsNot(new_metadata.get_property("created"), None)
    self.assertIsNot(new_metadata.get_property("revised"), None)
    self.assertIsNot(new_metadata.get_property("revision"), 0)

    # Cleanup 
    obj.purge(False)

  def testMetadataUpdate(self):
    obj = self.getNewBook()
    
    score = 1
    authors = "White rabbit team & sons"
    hidden = True

    self.assertTrue(obj.create())

    metadata = obj.get_property("metadata")
    metadata.set_property("score", score)
    metadata.set_property("authors", authors)
    metadata.set_property("hidden", hidden)

    self.assertTrue(obj.update())
    
    new_obj = Midgard.Object.factory(self.mgd, "gir_test_book_crud", obj.get_property("guid"))
    self.assertIsInstance(new_obj, Midgard.Object)

    metadata = new_obj.get_property("metadata")

    self.assertEqual(metadata.get_property("score"), score)
    self.assertEqual(metadata.get_property("authors"), authors)
    self.assertEqual(metadata.get_property("hidden"), hidden)

    # Read only properties 
    self.assertIsNot(metadata.get_property("created"), None)
    self.assertIsNot(metadata.get_property("revised"), None)
    self.assertIsNot(metadata.get_property("revision"), 1)

    # Cleanup 
    obj.purge(False)

  def testMetadataDelete(self):
    obj = self.getNewBook()
    
    score = 0
    authors = "White rabbit team & sons"
    hidden = True

    self.assertTrue(obj.create())
    new_obj = Midgard.Object.factory(self.mgd, "gir_test_book_crud", obj.get_property("guid"))
    self.assertIsInstance(new_obj, Midgard.Object)

    metadata = new_obj.get_property("metadata")
    metadata.set_property("score", score)
    metadata.set_property("authors", authors)
    metadata.set_property("hidden", hidden)

    self.assertTrue(obj.delete(False))

    self.assertEqual(metadata.get_property("score"), score)
    self.assertEqual(metadata.get_property("authors"), authors)
    self.assertEqual(metadata.get_property("hidden"), hidden)<commit_msg>On update expect revision 0 and 1 on create<commit_after># coding=utf-8

import sys
import struct
import unittest
from test_000_config import TestConfig
from test_001_connection import TestConnection

from gi.repository import Midgard
from gi.repository import GObject

class TestObjectMetadataCrud(unittest.TestCase):
  mgd = None
  bookstore = None

  def setUp(self):
    if self.mgd == None:
      self.mgd = TestConnection.openConnection()
    if self.bookstore is None:
      self.bookstore = Midgard.Object.factory(self.mgd, "gir_test_book_store", None)
      self.bookstore.set_property("name", "BookStore")
      self.bookstore.create()

  def tearDown(self):
    if self.bookstore is not None:
      self.bookstore.purge(False)
    self.mgd.close()
    self.mgd = None

  def getNewBook(self):
    obj = Midgard.Object.factory(self.mgd, "gir_test_book_crud", None)
    title = "The Metadata of a Holly Grail"
    obj.set_property("title", title)
    obj.set_property("store", self.bookstore.get_property("id"))
    return obj

  def testMetadataCreate(self):
    obj = self.getNewBook()
    
    score = -1
    authors = "White rabbit team"
    hidden = False

    metadata = obj.get_property("metadata")
    metadata.set_property("score", score)
    metadata.set_property("authors", authors)
    metadata.set_property("hidden", hidden)

    self.assertTrue(obj.create())
    new_obj = Midgard.Object.factory(self.mgd, "gir_test_book_crud", obj.get_property("guid"))
    self.assertIsInstance(new_obj, Midgard.Object)
    new_metadata = new_obj.get_property("metadata")
    self.assertEqual(new_metadata.get_property("score"), score)
    self.assertEqual(new_metadata.get_property("authors"), authors)
    self.assertEqual(new_metadata.get_property("hidden"), hidden)

    # Read only properties 
    self.assertIsNot(new_metadata.get_property("created"), None)
    self.assertIsNot(new_metadata.get_property("revised"), None)
    self.assertEqual(new_metadata.get_property("revision"), 0)

    # Cleanup 
    obj.purge(False)

  def testMetadataUpdate(self):
    obj = self.getNewBook()
    
    score = 1
    authors = "White rabbit team & sons"
    hidden = True

    self.assertTrue(obj.create())

    metadata = obj.get_property("metadata")
    metadata.set_property("score", score)
    metadata.set_property("authors", authors)
    metadata.set_property("hidden", hidden)

    self.assertTrue(obj.update())
    
    new_obj = Midgard.Object.factory(self.mgd, "gir_test_book_crud", obj.get_property("guid"))
    self.assertIsInstance(new_obj, Midgard.Object)

    metadata = new_obj.get_property("metadata")

    self.assertEqual(metadata.get_property("score"), score)
    self.assertEqual(metadata.get_property("authors"), authors)
    self.assertEqual(metadata.get_property("hidden"), hidden)

    # Read only properties 
    self.assertIsNot(metadata.get_property("created"), None)
    self.assertIsNot(metadata.get_property("revised"), None)
    self.assertEqual(metadata.get_property("revision"), 1)

    # Cleanup 
    obj.purge(False)

  def testMetadataDelete(self):
    obj = self.getNewBook()
    
    score = 0
    authors = "White rabbit team & sons"
    hidden = True

    self.assertTrue(obj.create())
    new_obj = Midgard.Object.factory(self.mgd, "gir_test_book_crud", obj.get_property("guid"))
    self.assertIsInstance(new_obj, Midgard.Object)

    metadata = new_obj.get_property("metadata")
    metadata.set_property("score", score)
    metadata.set_property("authors", authors)
    metadata.set_property("hidden", hidden)

    self.assertTrue(obj.delete(False))

    self.assertEqual(metadata.get_property("score"), score)
    self.assertEqual(metadata.get_property("authors"), authors)
    self.assertEqual(metadata.get_property("hidden"), hidden)
{'fraction_non_alphanumeric': 0.12178296630405944, 'fraction_numerical': 0.00344919076678164, 'mean_word_length': 4.253658536585366, 'pattern_counts': {'":': 0, '<': 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': '3731701', 'n_tokens_mistral': 2405, 'n_tokens_neox': 2309, 'n_words': 421}