Exemplo n.º 1
0
 def _cleanupFile(self):
     transaction.begin()
     Globals["^DIC"]["9999905"].kill()
     Globals["^DIC"]['B']["PYTEST3"].kill()
     Globals["^DD"]["9999905"].kill()
     Globals["^DIZ"]["9999905"].kill()
     transaction.commit()
    def test_readwrite(self):
        dd = self.dbs.dd("PYTEST7")
        self.assertEqual(dd.fileid, "999912")

        pytest = self.dbs.get_file("PYTEST7")
        transaction.begin()
        rowid = pytest.insert(NAME = 'Test Insert')
        transaction.commit()

        # The low-level traverser, walks index "B", on NAME field
        # ('^DD(9999903,0,"IX","B",9999903,.01)', ''),
        cursor = pytest.traverser("B", "Test")
        rec = cursor.next()

        # validate the inserted data
        self.assertEqual(rec[0], "Test Insert")
        self.assertEqual(rec[1], "100")

        # Attempt to update the field
        e = None
        transaction.begin()
        try:
            pytest.update(rowid, C1="200")
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1
Exemplo n.º 3
0
    def test_readwrite(self):
        dd = self.dbs.dd("PYTEST7")
        self.assertEqual(dd.fileid, "999912")

        pytest = self.dbs.get_file("PYTEST7")
        transaction.begin()
        rowid = pytest.insert(NAME='Test Insert')
        transaction.commit()

        # The low-level traverser, walks index "B", on NAME field
        # ('^DD(9999903,0,"IX","B",9999903,.01)', ''),
        cursor = pytest.traverser("B", "Test")
        rec = cursor.next()

        # validate the inserted data
        self.assertEqual(rec[0], "Test Insert")
        self.assertEqual(rec[1], "100")

        # Attempt to update the field
        e = None
        transaction.begin()
        try:
            pytest.update(rowid, C1="200")
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1
Exemplo n.º 4
0
    def test_query(self):
        """
            use a query to read the file.
        """
        pytest1 = self.dbs.get_file("PYTEST1")
        transaction.begin()
        for i in range(10):
            pytest1.insert(NAME='ROW%d' % i,
                           TEXTLINE_ONE="%d: LINE 1" % i,
                           TEXTLINE2="%d: LINE 2" % i)
        transaction.commit()

        self.assertEqual(pytest1.count(), 10)

        # This cursor returns a list of row numbers
        cursor = pytest1.traverser(None,
                                   raw=True,
                                   limit=4,
                                   filters=[("NAME", "=", "ROW4")])
        result = list(cursor)
        self.assertEqual(len(result), 1)
        self.assertEqual(len(result[0]),
                         2)  # file traversal returns only rowids
        self.assertEqual(result[0][0], 'ROW4')
        self.assertEqual(result[0][1], '5')
Exemplo n.º 5
0
    def test_write(self):
        pytest4 = self.dbs.get_file("PYTEST4",
                                    internal=True,
                                    fieldnames=["GENDER", "NUMBERS", "YESNO"])
        transaction.begin()
        rowid = pytest4.insert(NAME="Insert Internal",
                               GENDER="F",
                               NUMBERS="4",
                               YESNO="N")
        transaction.commit()

        cursor = pytest4.traverser("B", "Insert Internal")
        rec = cursor.next()

        self.assertEqual(rec[0], "F")
        self.assertEqual(rec[1], "4")
        self.assertEqual(rec[2], "N")

        # Check validation
        transaction.begin()
        try:
            rowid = pytest4.update(rowid, GENDER="UNKNOWN")
            transaction.commit()
        except FilemanError, e:
            transaction.abort()
 def _cleanupFile(self):
     transaction.begin()
     Globals["^DIC"]["9999905"].kill()
     Globals["^DIC"]['B']["PYTEST3"].kill()
     Globals["^DD"]["9999905"].kill()
     Globals["^DIZ"]["9999905"].kill()
     transaction.commit()
Exemplo n.º 7
0
 def _cleanupFile(self):
     # This deletes a file
     transaction.begin()
     Globals["^DIC"]["9999906"].kill()
     Globals["^DIC"]["B"]["PYTEST4"].kill()
     Globals["^DD"]["9999906"].kill()
     Globals["^DIZ"]["9999906"].kill()
     transaction.commit()
Exemplo n.º 8
0
 def _cleanupFile(self):
     transaction.begin()
     Globals["^DIC"]["9999940"].kill()
     Globals["^DIC"]["B"]["PYMULT1"].kill()
     Globals["^DD"]["9999940"].kill()
     Globals["^DIZ"]["9999940"].kill()
     Globals["^DD"]["9999940.01"].kill()
     transaction.commit()
Exemplo n.º 9
0
 def _cleanupFile(self):
     # This deletes a file
     transaction.begin()
     Globals["^DIC"]["999912"].kill()
     Globals["^DIC"]["B"][self.filename].kill()
     Globals["^DD"]["999912"].kill()
     Globals["^DIZ"]["999912"].kill()
     transaction.commit()
Exemplo n.º 10
0
 def _createFile(self):
     # This creates a file
     transaction.begin()
     Globals.deserialise(self.DIC)
     Globals.deserialise(self.DD)
     Globals.deserialise(self.DIZ)
     Globals.deserialise(self.IX)
     transaction.commit()
Exemplo n.º 11
0
 def _cleanupFile(self):
     # This deletes a file
     transaction.begin()
     Globals["^DIC"]["9999906"].kill()
     Globals["^DIC"]["B"]["PYTEST4"].kill()
     Globals["^DD"]["9999906"].kill()
     Globals["^DIZ"]["9999906"].kill()
     transaction.commit()
Exemplo n.º 12
0
 def _cleanupFile(self):
     # This deletes a file
     transaction.begin()
     Globals["^DIC"]["999912"].kill()
     Globals["^DIC"]["B"][self.filename].kill()
     Globals["^DD"]["999912"].kill()
     Globals["^DIZ"]["999912"].kill()
     transaction.commit()
Exemplo n.º 13
0
 def _cleanupFile(self):
     # This deletes a file
     transaction.begin()
     for fileid, filename in [ ("9999920","PYTEST10A"), ("9999921","PYTEST10B"), ("9999923","PYTEST10C")]:
         Globals["^DIC"][fileid].kill()
         Globals["^DIC"]["B"][filename].kill()
         Globals["^DD"][fileid].kill()
         Globals["^DIZ"][fileid].kill()
     transaction.commit()
Exemplo n.º 14
0
 def _cleanupFile(self):
     # This deletes a file
     transaction.begin()
     for fileid, filename in [("9999920", "PYTEST10A"),
                              ("9999921", "PYTEST10B"),
                              ("9999923", "PYTEST10C")]:
         Globals["^DIC"][fileid].kill()
         Globals["^DIC"]["B"][filename].kill()
         Globals["^DD"][fileid].kill()
         Globals["^DIZ"][fileid].kill()
     transaction.commit()
Exemplo n.º 15
0
    def test_badwrite(self):
        pytest3 = self.dbs.get_file("PYTEST3")

        transaction.begin()
        e = None
        try:
            pytest3.insert(NAME="bad Insert1", INT1=1.1)
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1
Exemplo n.º 16
0
    def test_badwrite(self):
        pytest3 = self.dbs.get_file("PYTEST3")

        transaction.begin()
        e = None
        try:
            pytest3.insert(NAME="bad Insert1", INT1=1.1)
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1
Exemplo n.º 17
0
 def _createFile(self):
     # This creates a file
     transaction.begin()
     g = Globals["^DIC"]["B"][self.filename]
     if len(g.keys()) != 0:
         sys.stderr.write("File already exists: %s\n" % self.filename)
         sys.exit(1)
     Globals.deserialise(self.DIC)
     Globals.deserialise(self.DD)
     Globals.deserialise(self.DIZ)
     Globals.deserialise(self.IX)
     transaction.commit()
Exemplo n.º 18
0
 def _createFile(self):
     # This creates a file
     transaction.begin()
     g = Globals["^DIC"]["B"][self.filename]
     if len(g.keys()) != 0:
         sys.stderr.write("File already exists: %s\n" % self.filename)
         sys.exit(1)
     Globals.deserialise(self.DIC)
     Globals.deserialise(self.DD)
     Globals.deserialise(self.DIZ)
     Globals.deserialise(self.IX)
     transaction.commit()
Exemplo n.º 19
0
 def _cleanupFile(self):
     transaction.begin()
     Globals["^DIC"]["9999920"].kill()
     Globals["^DIC"]['B']["PYTEST20"].kill()
     Globals["^DD"]["9999920"].kill()
     Globals["^DIZ"]["9999920"].kill()
     Globals["^DD"]["IX"]["116"].kill()
     Globals["^DD"]["IX"]["B"]["9999920"].kill()
     Globals["^DD"]["IX"]["BB"]["9999920"].kill()
     Globals["^DD"]["IX"]["AC"]["9999920"].kill()
     Globals["^DD"]["IX"]["IX"]["D"]["116"].kill()
     Globals["^DD"]["IX"]["F"]["9999920"].kill()
     transaction.commit()
Exemplo n.º 20
0
 def _cleanupFile(self):
     transaction.begin()
     Globals["^DIC"]["9999904"].kill()
     Globals["^DIC"]['B']["PYTEST2"].kill()
     Globals["^DD"]["9999904"].kill()
     Globals["^DIZ"]["9999904"].kill()
     Globals["^DD"]["IX"]["117"].kill()
     Globals["^DD"]["IX"]["B"]["9999904"].kill()
     Globals["^DD"]["IX"]["BB"]["9999904"].kill()
     Globals["^DD"]["IX"]["AC"]["9999904"].kill()
     Globals["^DD"]["IX"]["IX"]["C"]["117"].kill()
     Globals["^DD"]["IX"]["F"]["9999904"].kill()
     transaction.commit()
Exemplo n.º 21
0
    def _createFile(self):
        # This creates a file
        transaction.begin()
        Globals.deserialise(self.DIC)
        Globals.deserialise(self.DD)
        Globals.deserialise(self.DIZ)
        Globals.deserialise(self.IX)
        transaction.commit()

        # Are indices setup
        dd = self.dbs.dd("PYTEST5")
        self.assertEqual(dd.fileid, "9999907")
        self.assertEqual(len(dd.indices), 1)
Exemplo n.º 22
0
    def _createFile(self):
        # This creates a file
        transaction.begin()
        Globals.deserialise(self.DIC)
        Globals.deserialise(self.DD)
        Globals.deserialise(self.DIZ)
        Globals.deserialise(self.IX)
        transaction.commit()

        # Are indices setup
        dd = self.dbs.dd("PYTEST2")
        self.assertEqual(len(dd.indices), 1)
        self.assertEqual(len(dd.new_indices), 1)
Exemplo n.º 23
0
    def test_badinsert(self):
        """
            Should fail to insert if foreign key non-existant
        """
        pytest = self.dbs.get_file("PYTEST10C", internal=True)

        transaction.begin()
        exception = False
        try:
            rowid = pytest.insert(NAME="TEST INSERT", VP1="VP1.20")
            transaction.commit()
        except FilemanError, e:
            transaction.abort()
            exception = e
Exemplo n.º 24
0
    def test_badinsert(self):
        """
            Should fail to insert if foreign key non-existant
        """
        pytest = self.dbs.get_file("PYTEST10C", internal=True)

        transaction.begin()
        exception = False
        try:
            rowid = pytest.insert(NAME="TEST INSERT", VP1="VP1.20")
            transaction.commit()
        except FilemanError, e:
            transaction.abort()
            exception = e
Exemplo n.º 25
0
    def test_badinsert(self):
        """
            Should fail to insert if foreign key non-existant
        """
        pytest = self.dbs.get_file("PYTEST9B", internal=True,
                fieldnames=["NAME", "P1", "P2"])

        transaction.begin()
        exception = False
        try:
            rowid = pytest.insert(NAME="TEST INSERT", P1="20")
            transaction.commit()
        except FilemanError, e:
            transaction.abort()
            exception = e
Exemplo n.º 26
0
    def test_readwrite(self):
        transaction.begin()
        pytest1 = self.dbs.get_file("PYTEST1", fieldnames=['NAME', 'TEXTLINE_ONE', 'TEXTLINE2'])
        pytest1.insert(NAME='Test Insert', TEXTLINE_ONE="LINE 1", TEXTLINE2="LINE 2")
        transaction.commit()

        # The low-level traverser, walks index "B", on NAME field
        # ('^DD(9999903,0,"IX","B",9999903,.01)', ''),
        cursor = pytest1.traverser("B", "Test")
        rec = cursor.next()

        # validate the inserted data
        self.assertEqual(rec[0], "Test Insert")
        self.assertEqual(rec[1], "LINE 1")
        self.assertEqual(rec[2], "LINE 2")
Exemplo n.º 27
0
    def test_write(self):
        pytest3 = self.dbs.get_file("PYTEST3",
            fieldnames = ["NAME", "INT1", "INT2", "DOLLARS", "FLOAT1", "FLOAT2"])
        transaction.begin()
        rowid = pytest3.insert(NAME="Insert", INT1=11, INT2=-11, DOLLARS=44.44,
            FLOAT1=3333.33, FLOAT2=-444.0)
        transaction.commit()

        cursor = pytest3.traverser("B", "Insert")
        rec = cursor.next()

        self.assertEqual(rec[1], '11')
        self.assertEqual(rec[2], '-11')
        self.assertEqual(rec[3], '44.44')
        self.assertEqual(rec[4], '3333.33')
        self.assertEqual(rec[5], '-444.0')
Exemplo n.º 28
0
    def test_badinsert(self):
        """
            Should fail to insert if foreign key non-existant
        """
        pytest = self.dbs.get_file("PYTEST9B",
                                   internal=True,
                                   fieldnames=["NAME", "P1", "P2"])

        transaction.begin()
        exception = False
        try:
            rowid = pytest.insert(NAME="TEST INSERT", P1="20")
            transaction.commit()
        except FilemanError, e:
            transaction.abort()
            exception = e
Exemplo n.º 29
0
    def _createFile(self):
        # This creates a file
        transaction.begin()
        Globals.deserialise(self.DIC)
        Globals.deserialise(self.DD)
        Globals.deserialise(self.DIZ)
        Globals.deserialise(self.IX)

        pytest = self.dbs.get_file("PYTEST20")
        for i in range(1, 11):
            pytest.insert(NAME='ROW%x' % i, TEXTLINE_ONE="%x: LINE 1" % i, TEXTLINE2="%x: LINE 2" % i)
        transaction.commit()

        # Are indices setup
        dd = self.dbs.dd("PYTEST20")
    #   self.assertEqual(len(dd.indices), 2)
        self.assertEqual(len(dd.new_indices), 1)
Exemplo n.º 30
0
    def test_insert(self):

        pytest = self.dbs.get_file("PYTEST10C", internal=True,
                fieldnames = ["NAME", "VP1"])

        transaction.begin()
        rowid = pytest.insert(NAME="TEST INSERT", VP1="VP1.2")
        transaction.commit()

        cursor = pytest.traverser("B", "TEST INSERT")
        rec = cursor.next()

        self.assertEqual(rec[0], "TEST INSERT")
        self.assertEqual(rec[1], "VP1.2")

        reference = pytest.traverse_pointer("VP1", rec[1])
        self.assertEqual(reference[0], "TWO")
        self.assertEqual(str(reference[1]), "2")
Exemplo n.º 31
0
    def test_write(self):
        """
            This is a simple write.

            TODO: Verify UTF8
            TODO: Convert WP type to a string. The list is not Pythonic
        """
        pytest5 = self.dbs.get_file("PYTEST5", internal=True, fieldnames=['NAME', 'WP1', 'WP2'])
        transaction.begin()
        rowid = pytest5.insert(NAME="Insert Internal", WP1='\n'.join([u"line 1", u"line 2", u"line 3"]),
            WP2='\n'.join([u"2 line 1", u"2 line 2", u"2 line 3"]))
        transaction.commit()

        cursor = pytest5.traverser("B", "Insert Internal")
        rec = cursor.next()
        self.assertEqual(rec[0], "Insert Internal")
        self.assertEqual(rec[1], '\n'.join([u"line 1", u"line 2", u"line 3"]))
        self.assertEqual(rec[2], '\n'.join([u"2 line 1", u"2 line 2", u"2 line 3"]))
Exemplo n.º 32
0
    def test_mandatory(self):
        """
            Fileman's concept of mandatory is that the value cannot be
            set to a null value. However, if a value is never put into
            it, it is not validated.
        """
        transaction.begin()
        pytest1 = self.dbs.get_file("PYTEST1")
        pytest1.insert(NAME='ROW1', TEXTLINE_ONE="LINE 1")
        transaction.commit()

        # TODO: These are no longer working, since I switched to insert in Internal mode
        transaction.begin()
        exception = False
        try:
            pytest1 = self.dbs.get_file("PYTEST1")
            pytest1.insert(NAME='ROW3', TEXTLINE_ONE="LINE 1", TEXTLINE2=None)
        except FilemanError, e:
            exception = True
Exemplo n.º 33
0
    def test_insert(self):

        pytest = self.dbs.get_file("PYTEST10C",
                                   internal=True,
                                   fieldnames=["NAME", "VP1"])

        transaction.begin()
        rowid = pytest.insert(NAME="TEST INSERT", VP1="VP1.2")
        transaction.commit()

        cursor = pytest.traverser("B", "TEST INSERT")
        rec = cursor.next()

        self.assertEqual(rec[0], "TEST INSERT")
        self.assertEqual(rec[1], "VP1.2")

        reference = pytest.traverse_pointer("VP1", rec[1])
        self.assertEqual(reference[0], "TWO")
        self.assertEqual(str(reference[1]), "2")
Exemplo n.º 34
0
    def test_query(self):
        """
            use a query to read the file.
        """
        pytest1 = self.dbs.get_file("PYTEST1")
        transaction.begin()
        for i in range(10):
            pytest1.insert(NAME='ROW%d' % i, TEXTLINE_ONE="%d: LINE 1" % i, TEXTLINE2="%d: LINE 2" % i)
        transaction.commit()

        self.assertEqual(pytest1.count(), 10)

        # This cursor returns a list of row numbers
        cursor = pytest1.traverser(None, raw=True, limit=4, filters=[("NAME", "=", "ROW4")])
        result = list(cursor)
        self.assertEqual(len(result), 1)
        self.assertEqual(len(result[0]), 2)  # file traversal returns only rowids
        self.assertEqual(result[0][0], 'ROW4')
        self.assertEqual(result[0][1], '5')
Exemplo n.º 35
0
    def _createFile(self):
        # This creates a file
        transaction.begin()
        Globals.deserialise(self.DIC)
        Globals.deserialise(self.DD)
        Globals.deserialise(self.DIZ)
        Globals.deserialise(self.IX)

        pytest = self.dbs.get_file("PYTEST20")
        for i in range(1, 11):
            pytest.insert(NAME='ROW%x' % i,
                          TEXTLINE_ONE="%x: LINE 1" % i,
                          TEXTLINE2="%x: LINE 2" % i)
        transaction.commit()

        # Are indices setup
        dd = self.dbs.dd("PYTEST20")
        #   self.assertEqual(len(dd.indices), 2)
        self.assertEqual(len(dd.new_indices), 1)
Exemplo n.º 36
0
    def test_readwrite(self):
        """
            Verify that we can write dates and times and read them back.
            Check both internal and external formats.
        """
        int_pytest2 = self.dbs.get_file("PYTEST2",
                fieldnames = ["NAME", "DATE1", "DATETIME1", "DATETIME2"])
        transaction.begin()
        rowid = int_pytest2.insert(NAME='Test Internal Dates', DATE1=datetime.date(2012,1,2),
            DATETIME1=datetime.datetime(2012,1,2,3,4,5), DATETIME2=datetime.datetime(2012,1,2,3,4,5))
        transaction.commit()

        cursor = int_pytest2.traverser("B", "Test Internal Dates") 

        rec = cursor.next()
        self.assertEqual(str(rec[0]), "Test Internal Dates")
        self.assertEquals(rec[1], datetime.date(2012,1,2))
        self.assertEquals(rec[2], datetime.datetime(2012,1,2,3,4,5))
        self.assertEquals(rec[3], datetime.datetime(2012,1,2,3,4,5))
Exemplo n.º 37
0
    def test_write(self):
        pytest3 = self.dbs.get_file(
            "PYTEST3",
            fieldnames=["NAME", "INT1", "INT2", "DOLLARS", "FLOAT1", "FLOAT2"])
        transaction.begin()
        rowid = pytest3.insert(NAME="Insert",
                               INT1=11,
                               INT2=-11,
                               DOLLARS=44.44,
                               FLOAT1=3333.33,
                               FLOAT2=-444.0)
        transaction.commit()

        cursor = pytest3.traverser("B", "Insert")
        rec = cursor.next()

        self.assertEqual(rec[1], '11')
        self.assertEqual(rec[2], '-11')
        self.assertEqual(rec[3], '44.44')
        self.assertEqual(rec[4], '3333.33')
        self.assertEqual(rec[5], '-444.0')
Exemplo n.º 38
0
    def test_write(self):
        pytest4 = self.dbs.get_file("PYTEST4", internal=True,
            fieldnames=["GENDER", "NUMBERS", "YESNO"])
        transaction.begin()
        rowid = pytest4.insert(NAME="Insert Internal", GENDER="F", NUMBERS="4", YESNO="N")
        transaction.commit()

        cursor = pytest4.traverser("B", "Insert Internal")
        rec = cursor.next()

        self.assertEqual(rec[0], "F")
        self.assertEqual(rec[1], "4")
        self.assertEqual(rec[2], "N")

        # Check validation
        transaction.begin()
        try:
            rowid = pytest4.update(rowid, GENDER="UNKNOWN")
            transaction.commit()
        except FilemanError, e:
            transaction.abort()
Exemplo n.º 39
0
    def test_readwrite(self):
        """
            Verify that we can write dates and times and read them back.
            Check both internal and external formats.
        """
        int_pytest2 = self.dbs.get_file(
            "PYTEST2", fieldnames=["NAME", "DATE1", "DATETIME1", "DATETIME2"])
        transaction.begin()
        rowid = int_pytest2.insert(
            NAME='Test Internal Dates',
            DATE1=datetime.date(2012, 1, 2),
            DATETIME1=datetime.datetime(2012, 1, 2, 3, 4, 5),
            DATETIME2=datetime.datetime(2012, 1, 2, 3, 4, 5))
        transaction.commit()

        cursor = int_pytest2.traverser("B", "Test Internal Dates")

        rec = cursor.next()
        self.assertEqual(str(rec[0]), "Test Internal Dates")
        self.assertEquals(rec[1], datetime.date(2012, 1, 2))
        self.assertEquals(rec[2], datetime.datetime(2012, 1, 2, 3, 4, 5))
        self.assertEquals(rec[3], datetime.datetime(2012, 1, 2, 3, 4, 5))
Exemplo n.º 40
0
    def test_readwrite(self):
        pytest = self.dbs.get_file("PYTEST8", fieldnames=['NAME', 'M1'])
        transaction.begin()
        rowid = pytest.insert(NAME='Test Insert', M1='SET X=4,Y=7')
        transaction.commit()

        # The low-level traverser, walks index "B", on NAME field
        cursor = pytest.traverser("B", "Test")
        rec = cursor.next()

        # validate the inserted data
        self.assertEqual(rec[0], "Test Insert")
        self.assertEqual(rec[1], "SET X=4,Y=7")

        # Attempt to update the field
        e = None
        transaction.begin()
        try:
            pytest.update(_rowid=rowid, M1="Invalid Code")
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1
Exemplo n.º 41
0
    def test_write(self):
        """
            This is a simple write.

            TODO: Verify UTF8
            TODO: Convert WP type to a string. The list is not Pythonic
        """
        pytest5 = self.dbs.get_file("PYTEST5",
                                    internal=True,
                                    fieldnames=['NAME', 'WP1', 'WP2'])
        transaction.begin()
        rowid = pytest5.insert(
            NAME="Insert Internal",
            WP1='\n'.join([u"line 1", u"line 2", u"line 3"]),
            WP2='\n'.join([u"2 line 1", u"2 line 2", u"2 line 3"]))
        transaction.commit()

        cursor = pytest5.traverser("B", "Insert Internal")
        rec = cursor.next()
        self.assertEqual(rec[0], "Insert Internal")
        self.assertEqual(rec[1], '\n'.join([u"line 1", u"line 2", u"line 3"]))
        self.assertEqual(rec[2],
                         '\n'.join([u"2 line 1", u"2 line 2", u"2 line 3"]))
Exemplo n.º 42
0
    def test_readwrite(self):
        pytest = self.dbs.get_file("PYTEST8", fieldnames=['NAME', 'M1'])
        transaction.begin()
        rowid = pytest.insert(NAME='Test Insert', M1='SET X=4,Y=7')
        transaction.commit()

        # The low-level traverser, walks index "B", on NAME field
        cursor = pytest.traverser("B", "Test")
        rec = cursor.next()

        # validate the inserted data
        self.assertEqual(rec[0], "Test Insert")
        self.assertEqual(rec[1], "SET X=4,Y=7")

        # Attempt to update the field
        e = None
        transaction.begin()
        try:
            pytest.update(_rowid=rowid, M1="Invalid Code")
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1
Exemplo n.º 43
0
    def test_as_list(self):
        """
            Load the record. Then get a cursor for the sub-file.
        """
        pymult = self.dbs.get_file("PYMULT1", fieldnames=['T1->T1', "T1->T2"])

        cursor = pymult.traverser("B", " ")
        parent = cursor.next()

        # Given the parent record, now traverse the children
        self.assertEquals(parent[0][0], "1")
        self.assertEquals(parent[0][1], "2")
        self.assertEquals(parent[0][2], "3")

        self.assertEquals(parent[1][0], "a")
        self.assertEquals(parent[1][1], "b")
        self.assertEquals(parent[1][2], "c")

        # Verify update of a subfile element
        transaction.begin()
        pymult.update(cursor.rowid, **{'T1->T1': ["A","B","C"]})
        transaction.commit()

        transaction.begin()
        cursor = pymult.traverser("B", " ")
        parent = cursor.next()
        self.assertEquals(parent[0][0], "A")
        self.assertEquals(parent[0][1], "B")
        self.assertEquals(parent[0][2], "C")

        # Insert a subfile element
        pymult.update(cursor.rowid, **{'T1->T1': ["A","B","C","D"],
                'T1->T2': ["AA","BB","CC","DD"]})
        transaction.commit()

        transaction.begin()
        cursor = pymult.traverser("B", " ")
        parent = cursor.next()
        self.assertEquals(len(parent[0]), 4)
        self.assertEquals(parent[0][-1], "D")
        self.assertEquals(parent[1][-1], "DD")

        # delete an element
        # TODO: this functionality is not currently working.
        pymult.update(cursor.rowid, **{'T1->T1': ["A","B"],
                'T1->T2': ["AA","BB"]})
        transaction.commit()

        cursor = pymult.traverser("B", " ")
        parent = cursor.next()
        self.assertEquals(len(parent[0]), 2)
        self.assertEquals(parent[0][-1], "B")
Exemplo n.º 44
0
    def test_traversal_file(self):
        """
            Insert multiple items. Verify that traversal back and 
            forward works.
        """
        pytest1 = self.dbs.get_file("PYTEST1")
        transaction.begin()
        for i in range(10):
            pytest1.insert(NAME='ROW%d' % i,
                           TEXTLINE_ONE="%d: LINE 1" % i,
                           TEXTLINE2="%d: LINE 2" % i)
        transaction.commit()

        self.assertEqual(pytest1.count(), 10)

        # This cursor returns a list of row numbers
        cursor = pytest1.traverser(None, from_value=4, raw=True, limit=4)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0], '4')
        self.assertEqual(result[1], '5')
        self.assertEqual(result[2], '6')
        self.assertEqual(result[3], '7')

        cursor = pytest1.traverser(None, 8, 4, ascending=False, raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0], '8')
        self.assertEqual(result[1], '7')
        self.assertEqual(result[2], '6')
        self.assertEqual(result[3], '5')

        cursor = pytest1.traverser(None,
                                   4,
                                   8,
                                   to_rule="<=",
                                   from_rule=">=",
                                   raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 5)
        self.assertEqual(result[0], '4')
        self.assertEqual(result[1], '5')
        self.assertEqual(result[2], '6')
        self.assertEqual(result[3], '7')
        self.assertEqual(result[4], '8')

        cursor = pytest1.traverser(None,
                                   8,
                                   4,
                                   ascending=False,
                                   to_rule=">=",
                                   from_rule="<=",
                                   raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 5)
        self.assertEqual(result[0], '8')
        self.assertEqual(result[1], '7')
        self.assertEqual(result[2], '6')
        self.assertEqual(result[3], '5')
        self.assertEqual(result[4], '4')

        # test limits and offsets
        cursor = pytest1.traverser(None,
                                   1,
                                   to_rule="<=",
                                   from_rule=">=",
                                   raw=True,
                                   limit=4)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0], '1')
        self.assertEqual(result[3], '4')

        cursor = pytest1.traverser(None,
                                   1,
                                   to_rule="<=",
                                   from_rule=">=",
                                   raw=True,
                                   limit=4,
                                   offset=3)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0], '4')
        self.assertEqual(result[3], '7')

        cursor = pytest1.traverser(None,
                                   1,
                                   to_rule="<=",
                                   from_rule=">=",
                                   raw=True,
                                   offset=3)
        result = list(cursor)
        self.assertEqual(len(result), 7)
        self.assertEqual(result[0], '4')
        self.assertEqual(result[6], '10')

        # non-raw cursors
        cursor = pytest1.traverser(None,
                                   1,
                                   to_rule="<=",
                                   from_rule=">=",
                                   limit=4,
                                   offset=3)
        result = [(cursor.lastrowid, values) for values in cursor]
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0][0], '4')
        self.assertEqual(result[0][1][0], 'ROW3')
        self.assertEqual(result[3][0], '7')
        self.assertEqual(result[3][1][0], 'ROW6')
Exemplo n.º 45
0
        e = None
        try:
            pytest3.insert(NAME="bad Insert2", DOLLARS=44.4499)
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1

        # rounding errors ignored
        self.assertEquals(e, None)

        transaction.begin()
        e = None
        try:
            pytest3.insert(NAME="bad Insert3", FLOAT1 = "abc")
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1

        self.assertTrue(isinstance(e, FilemanError))

    def test_indexing(self):
        """
            TODO: walk a numeric index. Can I return the values as ints / floats.
        """

test_cases = (TestNumerics,)

def load_tests(loader, tests, pattern):
    suite = unittest.TestSuite()
Exemplo n.º 46
0
    def test_traversal_file(self):
        """
            Insert multiple items. Verify that traversal back and 
            forward works.
        """
        pytest1 = self.dbs.get_file("PYTEST1")
        transaction.begin()
        for i in range(10):
            pytest1.insert(NAME='ROW%d' % i, TEXTLINE_ONE="%d: LINE 1" % i, TEXTLINE2="%d: LINE 2" % i)
        transaction.commit()

        self.assertEqual(pytest1.count(), 10)

        # This cursor returns a list of row numbers
        cursor = pytest1.traverser(None, from_value=4, raw=True, limit=4)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0], '4')
        self.assertEqual(result[1], '5')
        self.assertEqual(result[2], '6')
        self.assertEqual(result[3], '7')

        cursor = pytest1.traverser(None, 8, 4, ascending=False, raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0], '8')
        self.assertEqual(result[1], '7')
        self.assertEqual(result[2], '6')
        self.assertEqual(result[3], '5')

        cursor = pytest1.traverser(None, 4, 8, to_rule="<=", from_rule=">=", raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 5)
        self.assertEqual(result[0], '4')
        self.assertEqual(result[1], '5')
        self.assertEqual(result[2], '6')
        self.assertEqual(result[3], '7')
        self.assertEqual(result[4], '8')

        cursor = pytest1.traverser(None, 8, 4, ascending=False, to_rule=">=", from_rule="<=", raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 5)
        self.assertEqual(result[0], '8')
        self.assertEqual(result[1], '7')
        self.assertEqual(result[2], '6')
        self.assertEqual(result[3], '5')
        self.assertEqual(result[4], '4')

        # test limits and offsets
        cursor = pytest1.traverser(None, 1, to_rule="<=", from_rule=">=", raw=True, limit=4)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0], '1')
        self.assertEqual(result[3], '4')

        cursor = pytest1.traverser(None, 1, to_rule="<=", from_rule=">=", raw=True, limit=4, offset=3)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0], '4')
        self.assertEqual(result[3], '7')

        cursor = pytest1.traverser(None, 1, to_rule="<=", from_rule=">=", raw=True, offset=3)
        result = list(cursor)
        self.assertEqual(len(result), 7)
        self.assertEqual(result[0], '4')
        self.assertEqual(result[6], '10')

        # non-raw cursors
        cursor = pytest1.traverser(None, 1, to_rule="<=", from_rule=">=", limit=4, offset=3)
        result = [(cursor.lastrowid, values) for values in cursor]
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0][0], '4')
        self.assertEqual(result[0][1][0], 'ROW3')
        self.assertEqual(result[3][0], '7')
        self.assertEqual(result[3][1][0], 'ROW6')
Exemplo n.º 47
0
    def test_traversal(self):
        """
            Insert multiple items. Verify that traversal back and 
            forward works.
        """
        transaction.begin()
        pytest1 = self.dbs.get_file("PYTEST1")
        for i in range(10):
            pytest1.insert(NAME='ROW%d' % i, TEXTLINE_ONE="%d: LINE 1" % i, TEXTLINE2="%d: LINE 2" % i)
        transaction.commit()

        # Index B is a default Key Field on the NAME field
        # It is a "traditional" index
        cursor = pytest1.traverser("B", "ROW4", "ROW8", raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0][0], "ROW4")
        self.assertEqual(result[1][0], "ROW5")
        self.assertEqual(result[2][0], "ROW6")
        self.assertEqual(result[3][0], "ROW7")

        cursor = pytest1.traverser("B", "ROW8", "ROW4", ascending=False, raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0][0], "ROW8")
        self.assertEqual(result[1][0], "ROW7")
        self.assertEqual(result[2][0], "ROW6")
        self.assertEqual(result[3][0], "ROW5")

        cursor = pytest1.traverser("B", "ROW4", "ROW8", to_rule="<=", from_rule=">=", raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 5)
        self.assertEqual(result[0][0], "ROW4")
        self.assertEqual(result[1][0], "ROW5")
        self.assertEqual(result[2][0], "ROW6")
        self.assertEqual(result[3][0], "ROW7")
        self.assertEqual(result[4][0], "ROW8")

        cursor = pytest1.traverser("B", "ROW8", "ROW4", ascending=False, to_rule=">=", from_rule="<=", raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 5)
        self.assertEqual(result[0][0], "ROW8")
        self.assertEqual(result[1][0], "ROW7")
        self.assertEqual(result[2][0], "ROW6")
        self.assertEqual(result[3][0], "ROW5")
        self.assertEqual(result[4][0], "ROW4")

        # Index C is a Cross reference Field on the TEXTLINE_ONE field
        # It is a "traditional" index

        # If I just pass in "4" it searches wrongly, putting integers
        # before strings.
        # TODO: how to make numbers and strings collate properly
        cursor = pytest1.traverser("C", "4:", "8:", raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0][0], "4: LINE 1")
        self.assertEqual(result[1][0], "5: LINE 1")
        self.assertEqual(result[2][0], "6: LINE 1")
        self.assertEqual(result[3][0], "7: LINE 1")

        cursor = pytest1.traverser("C", "8:", "4:", ascending=False, raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0][0], "7: LINE 1")
        self.assertEqual(result[1][0], "6: LINE 1")
        self.assertEqual(result[2][0], "5: LINE 1")
        self.assertEqual(result[3][0], "4: LINE 1")

        # TODO: This is not working - I tried to renumber the index and
        # since then it is not working properly. 

        # Index D is a new style index. Traversal works the same as 
        # traditional indices.
        cursor = pytest1.traverser("D", "4:", "8:", raw=True)
        result = list(cursor)
        self.assertEqual(result[0][0], "4: LINE 2")
        self.assertEqual(result[1][0], "5: LINE 2")
        self.assertEqual(result[2][0], "6: LINE 2")
        self.assertEqual(result[3][0], "7: LINE 2")

        cursor = pytest1.traverser("D", "8:", "4:", ascending=False, raw=True)
        result = list(cursor)
        self.assertEqual(len(result), 4)
        self.assertEqual(result[0][0], "7: LINE 2")
        self.assertEqual(result[1][0], "6: LINE 2")
        self.assertEqual(result[2][0], "5: LINE 2")
        self.assertEqual(result[3][0], "4: LINE 2")
Exemplo n.º 48
0
        e = None
        try:
            pytest3.insert(NAME="bad Insert2", DOLLARS=44.4499)
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1

        # rounding errors ignored
        self.assertEquals(e, None)

        transaction.begin()
        e = None
        try:
            pytest3.insert(NAME="bad Insert3", FLOAT1="abc")
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1

        self.assertTrue(isinstance(e, FilemanError))

    def test_indexing(self):
        """
            TODO: walk a numeric index. Can I return the values as ints / floats.
        """


test_cases = (TestNumerics, )

Exemplo n.º 49
0
class TestNumerics(unittest.TestCase):
    """
        Create a simple file containing a couple of numeric values.
    """
    DIC = [
        ('^DIC(9999905,0)', 'PYTEST3^9999905'),
        ('^DIC(9999905,0,"AUDIT")', '@'),
        ('^DIC(9999905,0,"DD")', '@'),
        ('^DIC(9999905,0,"DEL")', '@'),
        ('^DIC(9999905,0,"GL")', '^DIZ(9999905,'),
        ('^DIC(9999905,0,"LAYGO")', '@'),
        ('^DIC(9999905,0,"RD")', '@'),
        ('^DIC(9999905,0,"WR")', '@'),
        ('^DIC(9999905,"%A")', '10000000020^3120720'),
        ('^DIC("B","PYTEST3",9999905)', ''),
    ]

    DIZ = [
        ('^DIZ(9999905,0)', 'PYTEST3^9999905^1^1'),
        ('^DIZ(9999905,1,0)',
         'entered via fileman^10^-10^33.33^22222.22^-333'),
        ('^DIZ(9999905,"B","entered via fileman",1)', ''),
    ]

    DD = [
        ('^DD(9999905,0)', 'FIELD^^5^6'),
        ('^DD(9999905,0,"DT")', '3120720'),
        ('^DD(9999905,0,"IX","B",9999905,.01)', ''),
        ('^DD(9999905,0,"NM","PYTEST3")', ''),
        ('^DD(9999905,.01,0)',
         '''NAME^RF^^0;1^K:$L(X)>30!(X?.N)!($L(X)<3)!'(X'?1P.E) X'''),
        ('^DD(9999905,.01,1,0)', '^.1'),
        ('^DD(9999905,.01,1,1,0)', '9999905^B'),
        ('^DD(9999905,.01,1,1,1)', 'S ^DIZ(9999905,"B",$E(X,1,30),DA)=""'),
        ('^DD(9999905,.01,1,1,2)', 'K ^DIZ(9999905,"B",$E(X,1,30),DA)'),
        ('^DD(9999905,.01,3)',
         'NAME MUST BE 3-30 CHARACTERS, NOT NUMERIC OR STARTING WITH PUNCTUATION'
         ),
        ('^DD(9999905,1,0)',
         '''int1^NJ6,0^^0;2^K:+X'=X!(X>999999)!(X<0)!(X?.E1"."1N.N) X'''),
        ('^DD(9999905,1,3)',
         'Type a Number between 0 and 999999, 0 Decimal Digits'),
        ('^DD(9999905,1,"DT")', '3120720'),
        ('^DD(9999905,2,0)',
         '''int2^NJ5,0^^0;3^K:+X'=X!(X>10000)!(X<-10000)!(X?.E1"."1N.N) X'''),
        ('^DD(9999905,2,3)',
         'Type a Number between -10000 and 10000, 0 Decimal Digits'),
        ('^DD(9999905,2,"DT")', '3120720'),
        ('^DD(9999905,3,0)',
         '''dollars^NJ8,2^^0;4^S:X["$" X=$P(X,"$",2) K:X'?.N.1".".2N!(X>10000)!(X<0) X'''
         ),
        ('^DD(9999905,3,3)',
         'Type a Dollar Amount between 0 and 10000, 2 Decimal Digits'),
        ('^DD(9999905,3,"DT")', '3120720'),
        ('^DD(9999905,4,0)',
         '''float1^NJ8,2^^0;5^K:+X'=X!(X>99999)!(X<0)!(X?.E1"."3N.N) X'''),
        ('^DD(9999905,4,3)',
         'Type a Number between 0 and 99999, 2 Decimal Digits'),
        ('^DD(9999905,4,"DT")', '3120720'),
        ('^DD(9999905,5,0)',
         '''float2^NJ9,4^^0;6^K:+X'=X!(X>1000)!(X<-1000)!(X?.E1"."5N.N) X'''),
        ('^DD(9999905,5,3)',
         'Type a Number between -1000 and 1000, 4 Decimal Digits'),
        ('^DD(9999905,5,"DT")', '3120720'),
        ('^DD(9999905,"B","NAME",.01)', ''),
        ('^DD(9999905,"B","dollars",3)', ''),
        ('^DD(9999905,"B","float1",4)', ''),
        ('^DD(9999905,"B","float2",5)', ''),
        ('^DD(9999905,"B","int1",1)', ''),
        ('^DD(9999905,"B","int2",2)', ''),
        ('^DD(9999905,"GL",0,1,.01)', ''),
        ('^DD(9999905,"GL",0,2,1)', ''),
        ('^DD(9999905,"GL",0,3,2)', ''),
        ('^DD(9999905,"GL",0,4,3)', ''),
        ('^DD(9999905,"GL",0,5,4)', ''),
        ('^DD(9999905,"GL",0,6,5)', ''),
        ('^DD(9999905,"IX",.01)', ''),
        ('^DD(9999905,"RQ",.01)', ''),
    ]

    IX = []

    def _cleanupFile(self):
        transaction.begin()
        Globals["^DIC"]["9999905"].kill()
        Globals["^DIC"]['B']["PYTEST3"].kill()
        Globals["^DD"]["9999905"].kill()
        Globals["^DIZ"]["9999905"].kill()
        transaction.commit()

    def _createFile(self):
        # This creates a file
        transaction.begin()
        Globals.deserialise(self.DIC)
        Globals.deserialise(self.DD)
        Globals.deserialise(self.DIZ)
        #Globals.deserialise(self.IX)
        transaction.commit()

        # Are indices setup
        dd = self.dbs.dd("PYTEST3")
        self.assertEqual(dd.fileid, "9999905")
        self.assertEqual(len(dd.indices), 1)
        #self.assertEqual(len(dd.new_indices), 1)

    def setUp(self):
        self.dbs = connect("0", "")

        self._cleanupFile()
        self._createFile()

    def tearDown(self):
        # destroy the file
        self._cleanupFile()
        if transaction.in_transaction:
            transaction.abort()

    def test_read(self):
        """
            Validate the data which was in the file. This data
            was created via FILEMAN.
        """
        pytest3 = self.dbs.get_file(
            "PYTEST3",
            internal=True,
            fieldnames=["NAME", "INT1", "INT2", "DOLLARS", "FLOAT1", "FLOAT2"])
        cursor = pytest3.traverser("B", "e")
        rec = cursor.next()

        self.assertEqual(rec[1], '10')
        self.assertEqual(rec[2], '-10')
        self.assertEqual(rec[3], '33.33')
        self.assertEqual(rec[4], '22222.22')
        self.assertEqual(rec[5], '-333.0')

        pytest3 = self.dbs.get_file(
            "PYTEST3",
            internal=False,
            fieldnames=["NAME", "INT1", "INT2", "DOLLARS", "FLOAT1", "FLOAT2"])
        cursor = pytest3.traverser("B", "e")
        rec = cursor.next()

        self.assertEqual(rec[1], '10')
        self.assertEqual(rec[2], '-10')
        self.assertEqual(rec[3], '33.33')
        self.assertEqual(rec[4], '22222.22')
        self.assertEqual(rec[5], '-333.0')

    def test_write(self):
        pytest3 = self.dbs.get_file(
            "PYTEST3",
            fieldnames=["NAME", "INT1", "INT2", "DOLLARS", "FLOAT1", "FLOAT2"])
        transaction.begin()
        rowid = pytest3.insert(NAME="Insert",
                               INT1=11,
                               INT2=-11,
                               DOLLARS=44.44,
                               FLOAT1=3333.33,
                               FLOAT2=-444.0)
        transaction.commit()

        cursor = pytest3.traverser("B", "Insert")
        rec = cursor.next()

        self.assertEqual(rec[1], '11')
        self.assertEqual(rec[2], '-11')
        self.assertEqual(rec[3], '44.44')
        self.assertEqual(rec[4], '3333.33')
        self.assertEqual(rec[5], '-444.0')

    def test_badwrite(self):
        pytest3 = self.dbs.get_file("PYTEST3")

        transaction.begin()
        e = None
        try:
            pytest3.insert(NAME="bad Insert1", INT1=1.1)
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1

        # rounding errors ignored
        self.assertEquals(e, None)

        transaction.begin()
        e = None
        try:
            pytest3.insert(NAME="bad Insert2", DOLLARS=44.4499)
            transaction.commit()
        except FilemanError, e1:
            transaction.abort()
            e = e1