Skip to content

Instantly share code, notes, and snippets.

@cabateman
Created March 10, 2021 15:06
Show Gist options
  • Save cabateman/ed50c1ea6da449842b7adb15f00d80e7 to your computer and use it in GitHub Desktop.
Save cabateman/ed50c1ea6da449842b7adb15f00d80e7 to your computer and use it in GitHub Desktop.
__author__ = "SpacedOut Engineering"
__copyright__ = "Copyright 2020, Spaced Out, Inc"
from collections import defaultdict
from typing import List, Dict, DefaultDict, Any
import requests
from app_server import create_app
from app_server.agency import mock_agency, current_agency
from app_server.ats.config.helpers.create_relations import SENSE_CORE_API_KEY
from app_server.entity import EntityType
from app_server.entity.attribute.designation import EntityAttributeDesignations
app = create_app()
def add_entity_types(entity_types: List[str]) -> str:
endpoint = (
f"https://{current_agency().slug}.sensehq.com/api/v1/entities/setup/types"
)
response = requests.put(
endpoint,
json=entity_types,
headers={"X-Api-Key": SENSE_CORE_API_KEY},
timeout=30,
)
return response.text
def add_designations(designations: List[Dict]) -> str:
create_designations: DefaultDict[EntityType, Any] = defaultdict(list)
for schema in designations:
entity_type = schema["entity_type"]
entity_attribute_name = schema["entity_attribute_name"]
usage_order = schema["usage_order"]
designation = schema["designation"]
create_designations[EntityType(entity_type)].append(
{
"entity_attribute_name": entity_attribute_name.lower(),
"designation": designation.value,
"usage_order": usage_order,
"entity_type": entity_type.value,
}
)
last_response = ""
for entity_type, designation in create_designations.items():
endpoint = f"https://fastaff.sensehq.com/api/v1/entities/setup/{entity_type.value}/attribute-designations"
response = requests.put(
endpoint,
json=designation,
headers={"X-Api-Key": SENSE_CORE_API_KEY},
timeout=30,
)
last_response = response.text
assert response.status_code == 200, response.text
return last_response
with app.app_context():
with mock_agency("1433652716322427896"):
response_text = add_designations(
[
{
"entity_type": EntityType.ERCandidateApplication,
"entity_attribute_name": "status_desc",
"designation": EntityAttributeDesignations.STATUS, # type: ignore
"usage_order": 0,
},
{
"entity_type": EntityType.ERCandidateApplication,
"entity_attribute_name": "createdon",
"designation": EntityAttributeDesignations.CREATED_DATE, # type: ignore
"usage_order": 0,
}
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment