def test_bad_entity_factory(self):
     dac = DataAccessBase(con=self.dbh,
                          name='DOES_NOT_EXISTS',
                          loop=self.loop)
     with nt.assert_raises(NoValidEntity):
         # noinspection PyProtectedMember
         dac._entity_factory(self.record)
 async def test_read(self):
     dac = DataAccessBase(self.dbh, 'PARTNERS')
     await dac.read()
     nt.assert_equal(len(dac.data), 2)
     for record in dac.data:
         nt.assert_equal(record.name, 'PARTNERS')
         nt.assert_greater(record.id, 0)
Exemplo n.º 3
0
    async def process(self, process: ProcessingStep,
                      client: aiohttp.ClientSession) -> State:
        await super().process(process, client)
        ba = DataAccessBase(self.connection)
        ba.data.append(process)
        await ba.update_state(to_state=State.InProgress.code)
        try:

            url = ['http://', process.ip_address, ':',
                   str(process.port), '/transactions/', process.url]
            log.info(''.join(url))
            resp = await client.request(method=process.method, url=''.join(url),
                                        data=process.data, timeout=1.01)

            if resp.status in {200, 201}:
                await ba.update_state(to_state=State.Processed.code)
                return State.RequestStored
            else:
                await ba.update_state(to_state=State.Error.code)
                return State.BadRequest

        except aiohttp.ClientError as error:
            log.error(error)
            await ba.update_state(to_state=State.InProgress.code)
            return State.BadRequest
 async def test_bad_execute(self):
     dac = DataAccessBase(con=self.dbh, name='EVENTS')
     future: asyncio.Future = self.loop.create_future()
     with nt.assert_raises(sqlite3.DatabaseError):
         await dac._execute_select(sql='SELECT * FROM X',
                                   parameters=[],
                                   future=future)
         await future
     with nt.assert_raises(asyncio.InvalidStateError):
         await dac._execute_select(sql='SELECT * FROM TASKS WHERE ID = ?',
                                   parameters=[1],
                                   future=future)
         future.cancel()
 def test_bad_entities(self):
     dac = DataAccessBase(con=self.dbh, name='', loop=self.loop)
     dac.data.append(Task())
     dac.data.append(Event())
     with nt.assert_raises(MixedEntitiesException):
         dac.name()
     with nt.assert_raises(IndexError):
         dac.get_result()
 async def test_bad_entity(self):
     dac = DataAccessBase(con=self.dbh, name='XXX')
     nt.assert_equals(await dac.update_state(0), 0)
     nt.assert_equals(await dac.read(), 0)
 async def test_bad_insert(self):
     dac = DataAccessBase(con=self.dbh, name='EVENTS')
     nt.assert_equals(await dac.insert(), 0)
 def test_ctor(self):
     test = DataAccessBase(self.dbh)
     nt.assert_equal(test.name, '')
 async def test_read_joined_by_id(self):
     dac = DataAccessBase(self.dbh, 'TASKS')
     await dac.read(entity_id=1)
     nt.assert_equal(len(dac.data), 1)
 async def test_read_joined_processing_steps(self):
     dac = DataAccessBase(self.dbh, 'PROCESSING_STEPS')
     await dac.read(entity_id=1)
     nt.assert_equal(len(dac.data), 1)
 async def test_read_joined_tasks(self):
     dac = DataAccessBase(self.dbh, 'TASKS')
     await dac.read()
     nt.assert_equal(len(dac.data), 1)
 async def test_datetime(self):
     dac = DataAccessBase(self.dbh, 'TASKS')
     await dac.read()
     for row in dac.data:
         nt.assert_is_instance(row.updated_on, datetime)
Exemplo n.º 13
0
 def __init__(self, con: sqlite3.Connection):
     DataAccessBase.__init__(self, con=con, name='PROCESSING_STEPS')
Exemplo n.º 14
0
 def __init__(self, con: sqlite3.Connection):
     DataAccessBase.__init__(self, con=con, name='PARTNERS')
Exemplo n.º 15
0
 def __init__(self, con: sqlite3.Connection):
     ITransaction.__init__(self)
     DataAccessBase.__init__(self, con=con, name='TASKS')