Skip to content

Commit

Permalink
testing bug fixes and logic updates
Browse files Browse the repository at this point in the history
  • Loading branch information
lmhale99 committed Jan 25, 2023
1 parent b3337d0 commit 5bbae6c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
26 changes: 10 additions & 16 deletions cdcs/CDCS/_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ def upload_template(self,
if content is None:
raise ValueError('filename or content must be given')

if title in self.template_titles:
raise ValueError(f'template {title} already exists')

# Encode str as bytes if needed
if isinstance(content, str):
try:
Expand Down Expand Up @@ -346,19 +349,7 @@ def upload_template(self,
rest_url = '/rest/template/global/'

# Send request
response = self.post(rest_url, data=data, checkstatus=False)

# Check for specific error message for pre-existing template titles
if response.status_code == 400 and response.json() == {'message': {'title': ['This field must be unique.']}}:
raise ValueError(f'template {title} already exists')
else:
# Throw any other errors
if not response.ok:
try:
print(response.json())
except:
print(response.text)
response.raise_for_status()
response = self.post(rest_url, data=data)

if verbose and response.status_code == 201:
template_id = response.json()['id']
Expand Down Expand Up @@ -444,7 +435,11 @@ def update_template(self,

# Get template manager
if template_manager is None:
template_manager = self.get_template_managers(title=title).loc[0]
template_managers = self.get_template_managers(title=title)
if len(template_managers) == 1:
template_manager = template_managers.iloc[0]
else:
raise ValueError(f'template {title} does not exist')

# Encode str as bytes if needed
if isinstance(content, str):
Expand Down Expand Up @@ -477,11 +472,10 @@ def update_template(self,
# Send request
response = self.post(rest_url, data=data)

template_id = response.json()['id']
if verbose and response.status_code == 201:
template_id = response.json()['id']
print(f'template {title} ({template_id}) successfully uploaded.')


# Set new version as the current template
if set_current:
self.set_current_template(template_id=template_id, verbose=verbose)
Expand Down
2 changes: 1 addition & 1 deletion cdcs/CDCS/_xslt.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def upload_xslt(self,
filename = Path(filename).name

elif name is not None:
filename = name + '.xsd'
filename = f'{name}.xsl'

else:
raise ValueError('filename or name must be given')
Expand Down

0 comments on commit 5bbae6c

Please sign in to comment.