Exemplo n.º 1
0
def test_check_connection_authentication_failure(mocker):
    source = SourceMyHours()
    logger_mock = MagicMock()

    responses.add(responses.POST,
                  f"{URL_BASE}/tokens/login",
                  status=403,
                  json={"message": "Incorrect email or password"})

    success, exception = source.check_connection(logger_mock, DEFAULT_CONFIG)

    assert success is False
    assert exception is not None
Exemplo n.º 2
0
def test_check_connection_connection_failure(mocker):
    source = SourceMyHours()
    logger_mock = MagicMock()

    responses.add(responses.POST,
                  f"{URL_BASE}/tokens/login",
                  json={
                      "accessToken": "at",
                      "refreshToken": "rt",
                      "expiresIn": 100
                  })
    responses.add(responses.GET, f"{URL_BASE}/Clients", status=403)

    success, exception = source.check_connection(logger_mock, DEFAULT_CONFIG)
    assert success is False
    assert exception is not None
Exemplo n.º 3
0
def test_check_connection_success(mocker):
    source = SourceMyHours()
    logger_mock = MagicMock()

    responses.add(responses.POST,
                  f"{URL_BASE}/tokens/login",
                  json={
                      "accessToken": "at",
                      "refreshToken": "rt",
                      "expiresIn": 100
                  })
    responses.add(
        responses.GET,
        f"{URL_BASE}/Clients",
    )

    assert source.check_connection(logger_mock, DEFAULT_CONFIG) == (True, None)
Exemplo n.º 4
0
def test_streams(mocker):
    source = SourceMyHours()
    responses.add(responses.POST,
                  f"{URL_BASE}/tokens/login",
                  json={
                      "accessToken": "at",
                      "refreshToken": "rt",
                      "expiresIn": 100
                  })
    config = {
        "email": "*****@*****.**",
        "password": "******",
        "logs_batch_size": 30,
        "start_date": "2021-01-01"
    }

    streams = source.streams(config)
    expected_streams_number = 5
    assert len(streams) == expected_streams_number