def test_persistence_get_invalid_data(self, mocker):
        mocker.get(PERSISTENCE_URL + '/data', text=skillData[:50])

        service = PersistenceService()
        with self.assertLogs(logger, level="ERROR"):
            result = service.get()
            self.assertFalse(result)
    def test_persistence_delete_fail(self, mocker):
        mocker.delete(PERSISTENCE_URL, exc=requests.exceptions.ConnectTimeout)

        service = PersistenceService()
        with self.assertLogs(logger, level="ERROR"):
            result = service.delete()
            self.assertEqual(result, None)
    def test_persistence_get_all_request_exception(self, mocker):
        mocker.get(PERSISTENCE_URL, exc=requests.exceptions.RequestException)

        service = PersistenceService()
        with self.assertLogs(logger, level="ERROR"):
            result = service.get_all()
            self.assertFalse(result)
    def test_persistence_get_response_timeout(self, mocker):
        mocker.get(PERSISTENCE_URL + '/data',
                   exc=requests.exceptions.ConnectTimeout)

        service = PersistenceService()
        with self.assertLogs(logger, level="ERROR"):
            result = service.get()
            self.assertFalse(result)
    def test_persistence_set_wrong_order(self, mocker):
        import json
        mocker.post(PERSISTENCE_URL, text=setResponse)

        service = PersistenceService()
        result = service.set({"attr1": "value1", "attr2": "value2"})
        self.assertIsInstance(result, requests.Response)
        self.assertEqual(result.json()['data'], json.loads(skillData))
    def test_persistence_set(self, mocker):
        import json
        mocker.post(PERSISTENCE_URL, text=setResponse)

        service = PersistenceService()
        result = service.set(json.loads(skillData))
        self.assertIsInstance(result, requests.Response)
        self.assertEqual(result.json()['data'], json.loads(skillData))
    def test_persistence_get_not_authorized(self, mocker):
        mocker.get(PERSISTENCE_URL + '/data',
                   text='Not Authorized',
                   status_code=401)

        service = PersistenceService()
        with self.assertLogs(logger, level="ERROR"):
            result = service.get()
            self.assertFalse(result)
    def test_persistence_get(self, mocker):
        mocker.get(PERSISTENCE_URL + '/data', text=skillData)

        service = PersistenceService()
        result = service.get()
        self.assertIsInstance(result, Hasher)
        self.assertEqual(result,
                         {'attrs': {
                             'attr1': 'value1',
                             'attr2': 'value2'
                         }})
Exemplo n.º 9
0
async def test_persistence_get_all():
    respx.get(PERSISTENCE_URL + ENTRY).mock(
        return_value=Response(200, text=allSkillData)
    )

    service = PersistenceService(PERSISTENCE_URL)
    result = await service.get_all()
    assert result == {"data": {"attrs": {"attr1": "value1", "attr2": "value2"}}}
Exemplo n.º 10
0
async def test_persistence_get_not_authorized():
    respx.get(PERSISTENCE_URL + DATA).mock(
        return_value=Response(401, text="Not Authorized")
    )

    service = PersistenceService(PERSISTENCE_URL)
    with pytest.raises(HTTPError):
        await service.get()
Exemplo n.º 11
0
async def test_persistence_get_invalid_data():
    respx.get(PERSISTENCE_URL + DATA).mock(
        return_value=Response(200, text=skillData[:50])
    )

    service = PersistenceService(PERSISTENCE_URL)
    with pytest.raises(json.JSONDecodeError):
        await service.get()
Exemplo n.º 12
0
async def test_persistence_set():
    respx.post(PERSISTENCE_URL + ENTRY).mock(
        return_value=Response(200, text=setResponse)
    )

    service = PersistenceService(PERSISTENCE_URL)
    result = await service.set(json.loads(skillData))
    assert result.json() == json.loads(setResponse)
 def test_persistence_delete(self, mocker):
     mocker.delete(PERSISTENCE_URL, text="[]")
     service = PersistenceService()
     result = service.delete()
     self.assertIsInstance(result, requests.Response)
Exemplo n.º 14
0
async def test_persistence_delete():
    respx.delete(PERSISTENCE_URL + ENTRY).mock(return_value=Response(200, text="[]"))

    service = PersistenceService(PERSISTENCE_URL)
    result = await service.delete()
    assert isinstance(result, Response)