Commit e14235e8 authored by espen.jensen's avatar espen.jensen
Browse files

Added ressurser endpoint that contains ansattnr

parent 617858d3
......@@ -34,6 +34,7 @@ def config(base_url):
"kontoplan": {"headers": {}},
"konteringsregel": {"headers": {}},
"konteringsregler": {"headers": {}},
"ressurs": {"headers": {}},
},
},
"import_service": None,
......@@ -60,6 +61,7 @@ def config_no_overrides(base_url):
"kontoplan": {},
"konteringsregel": {},
"konteringsregler": {},
"ressurs": {},
},
},
"import_service": None,
......@@ -199,3 +201,11 @@ def pytest_collection_modifyitems(config, items):
for item in items:
if "integration" in item.keywords:
item.add_marker(skip_integration)
@pytest.fixture
def ressurs_data():
return load_json_file("ressurs.json")
@pytest.fixture
def ressurser_data():
return load_json_file("ressurser.json")
[
{
"age": 120,
"birthDate": "1900-01-01T00:00:00.000",
"companyId": "72",
"dateFrom": "2019-01-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"languageCode": "",
"personId": "99999",
"personName": "Dummy, Dummy",
"personnelType": "A",
"status": "N",
"workflowState": "",
"nameInformation": {
"aliasName": "DUMMY",
"customNameField1": "",
"customNameField2": "",
"customNameField3": "",
"customNameField4": "",
"customNamePart": "",
"firstName": "Dummy",
"surname": "Dummy",
"title": ""
},
"paymentInformation": {
"contractId": "",
"supplierId": ""
},
"additionalInformation": {
"hasOvertime": false,
"isHourlyPaid": false,
"piecework": false
},
"lastUpdated": {
"updatedAt": "2020-06-02T10:57:37.397",
"updatedBy": "1100VSE"
},
"contactPoints": [
{
"contactPointType": "1",
"address": {
"countryCode": "NO",
"place": "OSLO",
"postcode": "0001",
"province": "",
"streetAddress": ""
},
"phoneNumbers": {
"telephone1": "",
"telephone2": "",
"telephone3": "",
"telephone4": "",
"telephone5": "",
"telephone6": "",
"telephone7": ""
},
"additionalContactInfo": {
"contactPerson": "",
"contactPosition": "",
"eMail": "",
"eMailCc": "",
"gtin": "",
"url": ""
},
"lastUpdated": {
"updatedAt": "2019-11-18T15:16:51.000",
"updatedBy": "1100VSE"
}
}
],
"relatedValues": [
{
"dateFrom": "2020-01-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "11000000",
"relationGroup": "10",
"relationId": "C1",
"relationName": "KOSTSTED",
"unitValue": 0
}
],
"customFieldGroups": {}
}
]
[
{
"age": 120,
"birthDate": "1900-01-01T00:00:00.000",
"companyId": "72",
"dateFrom": "2019-01-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"languageCode": "",
"personId": "99999",
"personName": "Dummy, Dummy",
"personnelType": "A",
"status": "N",
"workflowState": "",
"nameInformation": {
"aliasName": "DUMMY",
"customNameField1": "",
"customNameField2": "",
"customNameField3": "",
"customNameField4": "",
"customNamePart": "",
"firstName": "Dummy",
"surname": "Dummy",
"title": ""
},
"paymentInformation": {
"contractId": "",
"supplierId": ""
},
"additionalInformation": {
"hasOvertime": false,
"isHourlyPaid": false,
"piecework": false
},
"lastUpdated": {
"updatedAt": "2020-06-02T10:57:37.397",
"updatedBy": "1100VSE"
},
"contactPoints": [
{
"contactPointType": "1",
"address": {
"countryCode": "NO",
"place": "OSLO",
"postcode": "0001",
"province": "",
"streetAddress": ""
},
"phoneNumbers": {
"telephone1": "",
"telephone2": "",
"telephone3": "",
"telephone4": "",
"telephone5": "",
"telephone6": "",
"telephone7": ""
},
"additionalContactInfo": {
"contactPerson": "",
"contactPosition": "",
"eMail": "",
"eMailCc": "",
"gtin": "",
"url": ""
},
"lastUpdated": {
"updatedAt": "2019-11-18T15:16:51.000",
"updatedBy": "1100VSE"
}
}
],
"relatedValues": [
{
"dateFrom": "2020-01-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "11000000",
"relationGroup": "10",
"relationId": "C1",
"relationName": "KOSTSTED",
"unitValue": 0
}
],
"customFieldGroups": {}
},
{
"age": 120,
"birthDate": "1900-01-01T00:00:00.000",
"companyId": "72",
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"languageCode": "",
"personId": "100500",
"personName": "D, Laila",
"personnelType": "A",
"status": "N",
"workflowState": "",
"nameInformation": {
"aliasName": "",
"customNameField1": "",
"customNameField2": "",
"customNameField3": "",
"customNameField4": "",
"customNamePart": "",
"firstName": "Laila",
"surname": "D",
"title": ""
},
"paymentInformation": {
"contractId": "",
"supplierId": ""
},
"additionalInformation": {
"hasOvertime": false,
"isHourlyPaid": false,
"piecework": false
},
"lastUpdated": {
"updatedAt": "2020-03-12T13:45:20.000",
"updatedBy": "R.ELSC"
},
"contactPoints": [
{
"contactPointType": "1",
"address": {
"countryCode": "NO",
"place": "OSLO",
"postcode": "0001",
"province": "",
"streetAddress": ""
},
"phoneNumbers": {
"telephone1": "",
"telephone2": "",
"telephone3": "",
"telephone4": "",
"telephone5": "",
"telephone6": "",
"telephone7": ""
},
"additionalContactInfo": {
"contactPerson": "",
"contactPosition": "",
"eMail": "A.B@NTNU.NO",
"eMailCc": "",
"gtin": "",
"url": ""
},
"lastUpdated": {
"updatedAt": "2020-02-05T10:51:21.273",
"updatedBy": "1100VSE"
}
}
],
"relatedValues": [
{
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "50001597",
"relationGroup": "10",
"relationId": "ZR05",
"relationName": "STILLINGSKAT",
"unitValue": 0
},
{
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "AD",
"relationGroup": "",
"relationId": "B3",
"relationName": "KOST.KAT",
"unitValue": 0
},
{
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "AD",
"relationGroup": "",
"relationId": "B2",
"relationName": "INNT.KAT",
"unitValue": 0
},
{
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "13000000",
"relationGroup": "10",
"relationId": "C1",
"relationName": "KOSTSTED",
"unitValue": 0
},
{
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "1364",
"relationGroup": "10",
"relationId": "ZZ04",
"relationName": "STILLINGSKODE",
"unitValue": 0
}
],
"customFieldGroups": {}
},
{
"age": 120,
"birthDate": "1900-01-01T00:00:00.000",
"companyId": "72",
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"languageCode": "",
"personId": "100501",
"personName": "S, Merete",
"personnelType": "A",
"status": "N",
"workflowState": "",
"nameInformation": {
"aliasName": "",
"customNameField1": "",
"customNameField2": "",
"customNameField3": "",
"customNameField4": "",
"customNamePart": "",
"firstName": "Merete",
"surname": "S",
"title": ""
},
"paymentInformation": {
"contractId": "",
"supplierId": ""
},
"additionalInformation": {
"hasOvertime": false,
"isHourlyPaid": false,
"piecework": false
},
"lastUpdated": {
"updatedAt": "2020-03-12T13:45:41.000",
"updatedBy": "R.ELSC"
},
"contactPoints": [
{
"contactPointType": "1",
"address": {
"countryCode": "NO",
"place": "OSLO",
"postcode": "0001",
"province": "",
"streetAddress": ""
},
"phoneNumbers": {
"telephone1": "",
"telephone2": "",
"telephone3": "",
"telephone4": "",
"telephone5": "",
"telephone6": "",
"telephone7": ""
},
"additionalContactInfo": {
"contactPerson": "",
"contactPosition": "",
"eMail": "A.B@NTNU.NO",
"eMailCc": "",
"gtin": "",
"url": ""
},
"lastUpdated": {
"updatedAt": "2020-02-05T10:51:21.290",
"updatedBy": "1100VSE"
}
}
],
"relatedValues": [
{
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "50001597",
"relationGroup": "10",
"relationId": "ZR05",
"relationName": "STILLINGSKAT",
"unitValue": 0
},
{
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "AD",
"relationGroup": "",
"relationId": "B3",
"relationName": "KOST.KAT",
"unitValue": 0
},
{
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "AD",
"relationGroup": "",
"relationId": "B2",
"relationName": "INNT.KAT",
"unitValue": 0
},
{
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "13000000",
"relationGroup": "10",
"relationId": "C1",
"relationName": "KOSTSTED",
"unitValue": 0
},
{
"dateFrom": "2019-08-01T00:00:00.000",
"dateTo": "2099-12-31T00:00:00.000",
"percentage": 0,
"relatedValue": "1434",
"relationGroup": "10",
"relationId": "ZZ04",
"relationName": "STILLINGSKODE",
"unitValue": 0
}
],
"customFieldGroups": {}
}
]
\ No newline at end of file
......@@ -22,6 +22,7 @@ from ubw_client.models import (
Kontoplan,
Periode,
Prosjekt,
Ressurs,
ServerProcessResponse,
ServerProcessResult,
Transaction,
......@@ -359,7 +360,14 @@ def test_ubw_client_config():
endpoints.get_konteringsregel("72", 12)
== "https://example.com/konteringsregler/v1/72/12"
)
assert (
endpoints.get_ressurser("72")
== "https://example.com/ressurser/v1/72"
)
assert (
endpoints.get_ressurser("72", 12)
== "https://example.com/ressurser/v1/72/12"
)
def test_map_transaction():
transaction = Transaction(
......@@ -415,3 +423,26 @@ def test_map_transaction_null_dates():
assert mapped["DiscDate"] == null_date
assert mapped["DueDate"] == null_date
assert mapped["ComplDelay"] == null_date
def test_get_ressurs(client, base_url, requests_mock, ressurs_data):
company_id = "72"
ressurs_id = "99999"
requests_mock.get(
f"https://example.com/ressurser/v1/{company_id}/{ressurs_id}",
json=ressurs_data,
)
received = client.get_ressurs(company_id, ressurs_id)
expected = Ressurs.from_dict(ressurs_data[0])
assert expected == received
def test_get_ressurser(client, base_url, requests_mock, ressurser_data):
company_id = "72"
requests_mock.get(
f"https://example.com/ressurser/v1/{company_id}",
json=ressurser_data,
)
received = client.get_ressurser(company_id)
expected = [Ressurs.from_dict(b) for b in ressurser_data]
assert len(received) == 3
for i in range(len(received)):
assert received[i] == expected[i]
......@@ -303,3 +303,22 @@ def create_transactions():
]
return models.Transactions(__root__=trans_list)
@pytest.mark.integration
def test_get_ressurser(service_config):
client = get_client(**service_config)
ressurser = client.get_ressurser("72")
assert len(ressurser) > 3
for ressurs in ressurser:
assert ressurs.companyId == "72"
@pytest.mark.integration
def test_get_ressurs(service_config):
person_id = "99999";
client = get_client(**service_config)
ressurs = client.get_ressurs("72", person_id)
assert ressurs
assert ressurs["personName"] == "Dummy, Dummy"
assert ressurs["personId"] == person_id
......@@ -11,6 +11,7 @@ from ubw_client.models import (
Periode,
Prosjekt,
UbwRestEndpoints,
Ressurs,
)
......@@ -83,3 +84,14 @@ def test_konto(konto_data):
assert model.period_from == konto_data[0]["periodFrom"]
assert model.period_to == konto_data[0]["periodTo"]
assert model.status == konto_data[0]["status"]
def test_ressurs(ressurs_data):
model = Ressurs(**ressurs_data[0])
assert model.age == ressurs_data[0]["age"]
assert model.companyId == ressurs_data[0]["companyId"]
assert model.languageCode == ressurs_data[0]["languageCode"]
assert model.personId == ressurs_data[0]["personId"]
assert model.personName == ressurs_data[0]["personName"]
assert model.personnelType == ressurs_data[0]["personnelType"]
assert model.status == ressurs_data[0]["status"]
assert model.workflowState == ressurs_data[0]["workflowState"]
......@@ -143,3 +143,16 @@ def test_konteringsregel_url_no_override_wo_trailing_slash(config_no_overrides):
client = get_client(**config_no_overrides)
url = client.urls.get_konteringsregel("72", "2")
assert url == "https://example.com/base/konteringsregler/v1/72/2"
def test_ressurser_url_no_override_w_trailing_slash(config_no_overrides):
config_no_overrides["rest"]["base_url"] += "base/" # trailing slash
client = get_client(**config_no_overrides)
url = client.urls.get_ressurser("72", "2")
assert url == "https://example.com/base/ressurser/v1/72/2"
def test_ressurser_url_no_override_wo_trailing_slash(config_no_overrides):
config_no_overrides["rest"]["base_url"] += "base" # no trailing slash
client = get_client(**config_no_overrides)
url = client.urls.get_ressurser("72", "2")
assert url == "https://example.com/base/ressurser/v1/72/2"
......@@ -66,7 +66,7 @@ class Endpoints:
def get_firma(self, company_id: str):
return self._prepend_base_url(
self.rest.endpoints.firma.url or "firma", company_id
self.rest.endpoints.firma.url or "firma/v1", company_id
)
def get_arbeidsordre(self, company_id: str, ordre_id: typing.Optional[str] = None):
......@@ -112,6 +112,7 @@ class Endpoints:
str(konto),
)
def get_koststed(self, company_id: str, koststed: str):
return self._prepend_base_url(
self.rest.endpoints.koststeder.url or "koststeder/v1",
......@@ -119,6 +120,11 @@ class Endpoints:
koststed,
)
def get_ressurser(self, company_id: str, ressurs_id: typing.Optional[str] = None):
return self._prepend_base_url(
self.rest.endpoints.ressurser.url or "ressurser/v1", company_id, ressurs_id
)
def _create_transaction_report(
transaction_result_response,
......@@ -628,6 +634,18 @@ class UBWClient:
response = self.get(url, headers=headers)[0]
return models.Konteringsregel(**response)
def get_ressurser(self, company_id: str) -> typing.List[models.Ressurs]:
url = self.urls.get_ressurser(company_id)
headers = self.config.rest.endpoints.ressurser.headers
response = self.get(url, headers=headers)
return [models.Ressurs.from_dict(b) for b in response]
def get_ressurs(self, company_id: str, ressurs_id: str) -> models.Ressurs:
url = self.urls.get_ressurser(company_id, ressurs_id)
headers = self.config.rest.endpoints.ressurser.headers
response = self.get(url, headers=headers)[0]
return models.Ressurs.from_dict(response)
def get_client(**config):
return UBWClient(models.UbwClientConfig(**config))