Skip to content
This repository has been archived by the owner on Feb 1, 2024. It is now read-only.

Fix delete facility endpoint #1472

Merged
merged 1 commit into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

- Fix delete facility endpoint [#1472](https://github.com/open-apparel-registry/open-apparel-registry/pull/1472)

### Security

## [47] 2021-09-14
Expand Down
54 changes: 54 additions & 0 deletions src/django/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2744,6 +2744,60 @@ def test_other_match_is_promoted(self):
alias.refresh_from_db()
self.assertEqual(match_3.facility, alias.facility)

def test_matches_without_locations_are_ignored(self):
list_2 = FacilityList \
.objects \
.create(header='header',
file_name='two',
name='Second List')

source_2 = Source \
.objects \
.create(facility_list=list_2,
source_type=Source.LIST,
is_active=True,
is_public=True,
contributor=self.contributor)

list_item_2 = FacilityListItem \
.objects \
.create(name='Item',
address='Address',
country_code='US',
geocoded_point=None,
row_index=1,
status=FacilityListItem.MATCHED,
facility=self.facility,
source=source_2)

FacilityMatch \
.objects \
.create(status=FacilityMatch.AUTOMATIC,
facility=self.facility,
facility_list_item=list_item_2,
confidence=0.65,
results='')

self.client.login(email=self.superuser_email,
password=self.superuser_password)
response = self.client.delete(self.facility_url)
self.assertEqual(204, response.status_code)

self.assertEqual(
0, Facility.objects.filter(id=self.facility.id).count())
self.assertEqual(
0, FacilityMatch.objects.filter(facility=self.facility).count())

self.list_item.refresh_from_db()
self.assertEqual(
FacilityListItem.DELETED, self.list_item.status)
self.assertEqual(
ProcessingAction.DELETE_FACILITY,
self.list_item.processing_results[-1]['action'])
self.assertEqual(
self.facility.id,
self.list_item.processing_results[-1]['deleted_oar_id'])

def test_other_inactive_match_is_promoted(self):
initial_facility_count = Facility.objects.all().count()
list_2 = FacilityList \
Expand Down
3 changes: 2 additions & 1 deletion src/django/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1395,7 +1395,8 @@ def destroy(self, request, pk=None):
best_match = max(
other_matches.filter(
status__in=(FacilityMatch.AUTOMATIC,
FacilityMatch.CONFIRMED)),
FacilityMatch.CONFIRMED)).exclude(
facility_list_item__geocoded_point__isnull=True),
key=lambda m: m.confidence)
except ValueError:
# Raised when there are no AUTOMATIC or CONFIRMED matches
Expand Down