예제 #1
0
 def test_new_record(self):
     t = self.temp_table()
     try:
         run_synchronous(
             t.new_record(id=10, less_than_two=False, name=f"hello"))
     finally:
         self.db.drop_table_sync(t.name)
예제 #2
0
 def test_delete_records(self):
     t = self.temp_table()
     try:
         run_synchronous(t.delete_record({'id': 1}))
         records = run_synchronous(t.get_record({'id': 1}))
         assert len(records) == 0
     finally:
         self.db.drop_table_sync(t.name)
예제 #3
0
 def test_new_record(self):
     t = self.temp_table()
     try:
         run_synchronous(t.new_record({'id': 10,
                                        'less_than_two': False,
                                        'name': f"hello"}))
     finally:
         self.db.drop_table_sync(t.name)
예제 #4
0
 def test_delete_records(self):
     t = self.temp_table()
     try:
         run_synchronous(t.delete_record({'id': 1}))
         records = run_synchronous(t.get_record({'id': 1}))
         assert len(records) == 0
     finally:
         self.db.drop_table_sync(t.name)
예제 #5
0
 def test_get_not_null_records(self):
     t = self.temp_table()
     try:
         run_synchronous(t.update_record({'id': 1}, {'name': None}))
         records = run_synchronous(t.get_record({'name': 'NOT NULL'}))
         assert len(records) == 4
         records = run_synchronous(t.get_record({'name': None}))
         assert len(records) == 1
     finally:
         self.db.drop_table_sync(t.name)
예제 #6
0
    def test_update_record(self):
        t = self.temp_table()

        try:
            run_synchronous(t.update_record({'id': 3, 'name': '3'},
                                            {'name': 'hello'}))

            updated_record = run_synchronous(t.get_record({'id': 3}))
            assert len(updated_record) == 1
            assert updated_record[0]['name'] == 'hello'
        finally:
            self.db.drop_table_sync(t.name)
예제 #7
0
    def test_backtick_names(self):
        schema = {
            'id': 'INT',
            '`less_than_two`': 'BOOLEAN',
            'name': 'VARCHAR(100)'
        }
        keys = ['id']

        t = self.db.create_temporary_table_sync("temp", schema, keys)

        try:
            records = run_synchronous(t.get_record({'`less_than_two`': True}))
            assert len(records) == 0
            run_synchronous(
                t.new_record(**{
                    'id': 5,
                    '`less_than_two`': False,
                    'name': "foo"
                }))
            assert run_synchronous(t.has_record({'`less_than_two`': False}))
            run_synchronous(
                t.update_record({'id': 5}, {'`less_than_two`': True}))
            run_synchronous(t.delete_record({'`less_than_two`': True}))
        finally:
            self.db.drop_table_sync(t.name)
예제 #8
0
    def test_update_record(self):
        t = self.temp_table()

        try:
            run_synchronous(
                t.update_record({
                    'id': 3,
                    'name': '3'
                }, {'name': 'hello'}))

            updated_record = run_synchronous(t.get_record({'id': 3}))
            assert len(updated_record) == 1
            assert updated_record[0]['name'] == 'hello'
        finally:
            self.db.drop_table_sync(t.name)
예제 #9
0
 def test_select_records(self):
     t = self.temp_table()
     try:
         records = run_synchronous(t.get_record({'id': 1}, ['less_than_two']))
         assert len(records) == 1
         assert records == [{'less_than_two': True}]
     finally:
         self.db.drop_table_sync(t.name)
예제 #10
0
 def test_select_records(self):
     t = self.temp_table()
     try:
         records = run_synchronous(
             t.get_record({'id': 1}, ['less_than_two']))
         assert len(records) == 1
         assert records == [{'less_than_two': True}]
     finally:
         self.db.drop_table_sync(t.name)
예제 #11
0
 def test_get_records(self):
     t = self.temp_table()
     try:
         records = run_synchronous(t.get_record({'id': [1, 2]}))
         assert len(records) == 2
         assert records == [{'id': 1, 'less_than_two': True, 'name': '1'},
                            {'id': 2, 'less_than_two': False, 'name': '2'}]
     finally:
         self.db.drop_table_sync(t.name)
예제 #12
0
    def temp_table(self):
        schema = {'id': 'INT',
                  'less_than_two': 'BOOLEAN',
                  'name': 'VARCHAR(100)'}
        keys = ['id']

        t = self.db.create_temporary_table_sync("temp", schema, keys)

        for i in range(1, 6):
            id = run_synchronous(t.new_record({'id': i,
                                                'less_than_two': (i < 2),
                                                'name': f"{i}"}))
            assert id == 0
        return t
예제 #13
0
    def test_backtick_names(self):
        schema = {'id': 'INT',
                  '`less_than_two`': 'BOOLEAN',
                  'name': 'VARCHAR(100)'}
        keys = ['id']

        t = self.db.create_temporary_table_sync("temp", schema, keys)

        try:
            records = run_synchronous(t.get_record({'`less_than_two`': True}))
            assert len(records) == 0
            run_synchronous(t.new_record({'id': 5, '`less_than_two`': False, 'name': "foo"}))
            assert run_synchronous(t.has_record({'`less_than_two`': False}))
            run_synchronous(t.update_record({'id': 5}, {'`less_than_two`': True}))
            run_synchronous(t.delete_record({'`less_than_two`': True}))
        finally:
            self.db.drop_table_sync(t.name)
예제 #14
0
    def temp_table(self):
        schema = {
            'id': 'INT',
            'less_than_two': 'BOOLEAN',
            'name': 'VARCHAR(100)'
        }
        keys = ['id']

        t = self.db.create_temporary_table_sync("temp", schema, keys)

        for i in range(1, 6):
            id = run_synchronous(
                t.new_record(id=i, less_than_two=(i < 2), name=f"{i}"))
            assert id == 0
        return t
예제 #15
0
 def test_get_records(self):
     t = self.temp_table()
     try:
         records = run_synchronous(t.get_record({'id': [1, 2]}))
         assert len(records) == 2
         assert records == [{
             'id': 1,
             'less_than_two': True,
             'name': '1'
         }, {
             'id': 2,
             'less_than_two': False,
             'name': '2'
         }]
     finally:
         self.db.drop_table_sync(t.name)
예제 #16
0
 def test_has_record(self):
     t = self.temp_table()
     try:
         assert run_synchronous(t.has_record({'id': 4}))
     finally:
         self.db.drop_table_sync(t.name)
예제 #17
0
 def test_has_record(self):
     t = self.temp_table()
     try:
         assert run_synchronous(t.has_record({'id': 4}))
     finally:
         self.db.drop_table_sync(t.name)