CMS 3D CMS Logo

payload_tests.py
Go to the documentation of this file.
1 import unittest
2 import sys
3 import datetime
4 import pprint
5 import subprocess
6 import os
7 
8 import CondCore.Utilities.CondDBFW.querying as querying
9 import CondCore.Utilities.CondDBFW.data_sources as data_sources
10 import CondCore.Utilities.CondDBFW.data_formats as data_formats
11 import CondCore.Utilities.CondDBFW.shell as shell
12 import CondCore.Utilities.CondDBFW.models as models
13 
14 prod_connection_string = "frontier://FrontierProd/CMS_CONDITIONS"
15 secrets_source = None
16 
17 class payload_tests(unittest.TestCase):
18 
19  def setUp(self):
20  # set up a connection to oracle
21  self.connection = querying.connect(prod_connection_string, map_blobs=True, secrets=secrets_source)
22  # get a payload
23  self.payload = self.connection.payload(hash="00172cd62d8abae41915978d815ae62cc08ad8b9")
24  if not(os.path.isfile("test_suite.sqlite")):
25  # create file
26  handle = open("test_suite.sqlite", "w")
27  handle.close()
28  # insert schema
29  if os.path.isfile("simple_conditions_schema.sql"):
30  try:
31  process = subprocess.Popen("sqlite3 test_suite.sqlite < simple_conditions_schema.sql")
32  result = process.communicate()[0]
33  except Exception as e:
34  self.test_write_blob_to_sqlite = unittest.skip("Can't setup sqlite database file.")(self.test_write_blob_to_sqlite)
35 
37  import hashlib
38  recomputed_hash = hashlib.sha1(self.payload.object_type)
39  recomputed_hash.update(self.payload.data)
40  recomputed_hash = recomputed_hash.hexdigest()
41  self.assertEqual(recomputed_hash, self.payload.hash)
42 
44  import os
45  # open sqlite file in CondDBFW
46  sqlite_con = querying.connect("sqlite://test_suite.sqlite", map_blobs=True)
47  # write to sqlite file
48  sqlite_con.write_and_commit(self.payload)
49  # read payload from sqlite file, check for equality between blobs
50  sqlite_payload = sqlite_con.payload(hash=self.payload.hash)
51  self.assertEqual(sqlite_payload.data, self.payload.data)
52  # delete payload from sqlite file
53  tmp_sqlite_connection = sqlite_con.engine.connect()
54  result = tmp_sqlite_connection.execute("delete from payload where hash=?", self.payload.hash)
55  tmp_sqlite_connection.close()
56 
57  # check that payload isn't in sqlite anymore
58  payload_in_sqlite = sqlite_con.payload(hash=self.payload.hash)
59  self.assertEqual(payload_in_sqlite, None)
payload_tests.payload_tests.payload
payload
Definition: payload_tests.py:23
querying.connect
def connect(connection_data, mode="r", map_blobs=False, secrets=None, pooling=True)
Definition: querying.py:452
payload_tests.payload_tests
Definition: payload_tests.py:17
payload_tests.payload_tests.connection
connection
Definition: payload_tests.py:21
payload_tests.payload_tests.setUp
def setUp(self)
Definition: payload_tests.py:19
payload_tests.payload_tests.test_recomputed_hash
def test_recomputed_hash(self)
Definition: payload_tests.py:36
payload_tests.payload_tests.test_write_blob_to_sqlite
test_write_blob_to_sqlite
Definition: payload_tests.py:34