Skip to content

Commit

Permalink
Merge pull request #1171 from google/copybara-digitalbuildings-abel
Browse files Browse the repository at this point in the history
Project import generated by Copybara.
  • Loading branch information
trav3711 authored Oct 17, 2023
2 parents 9fd83f3 + c87a477 commit 0cf0502
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
7 changes: 5 additions & 2 deletions tools/abel/model/guid_to_entity_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,13 @@ def AddEntity(self, entity: ...) -> None:
"""
if entity is None:
raise ValueError('Cannot add None values to the guid to entity map.')
if not entity.bc_guid:
elif not entity.bc_guid:
raise AttributeError(f'{entity.code}: guid missing')
if entity.bc_guid not in self._guid_to_entity_map:
elif entity.bc_guid not in list(self._guid_to_entity_map):
self._guid_to_entity_map[entity.bc_guid] = entity
elif self._guid_to_entity_map.get(entity.bc_guid) == entity:
# Do nothing, this mapping already exists
pass
else:
raise KeyError(
f'{entity.bc_guid} maps to {self._guid_to_entity_map[entity.bc_guid]}'
Expand Down
5 changes: 4 additions & 1 deletion tools/abel/model/model_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from model import entity_field as ef
from model import entity_operation
from model import model_builder as mb
from model import site as site_lib
from validate import field_translation as ft


Expand Down Expand Up @@ -304,7 +305,9 @@ def GetConnectionDependencies(entity, dependencies, split_entities):
A list of entities connected to entity.
"""
split_entities.append(entity)
if not entity.connections and entity not in split_entities:
if isinstance(entity, site_lib.Site):
return dependencies
elif not entity.connections and entity not in split_entities:
dependencies.append(entity)
return dependencies
else:
Expand Down
13 changes: 11 additions & 2 deletions tools/abel/model/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ def FromDict(cls, site_dict: Dict[str, object]) -> ...:
)
return site_instance

@property
def bc_guid(self) -> str:
"""Returns the BC GUID for a site."""
return self.guid

@property
def entities(self) -> List[str]:
"""Returns a list of entity guids contained in a site."""
Expand All @@ -104,10 +109,14 @@ def AddEntity(self, entity: Entity) -> None:
# pylint: disable=unused-argument
def GetSpreadsheetRowMapping(self, *args) -> Dict[str, str]:
"""Returns a dictionary of Site attributes by spreadsheet headers."""
return {
site_row_mapping = {
VALUES: [
{USER_ENTERED_VALUE: {STRING_VALUE: self.code}},
{USER_ENTERED_VALUE: {STRING_VALUE: self.guid}},
{USER_ENTERED_VALUE: {STRING_VALUE: self.etag}},
]
}
if self.etag:
site_row_mapping.get(VALUES).append(
{USER_ENTERED_VALUE: {STRING_VALUE: self.etag}}
)
return site_row_mapping
5 changes: 4 additions & 1 deletion tools/abel/tests/guid_to_entity_map_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,13 @@ def testAddEntityRaisesAttributeError(self):
_TEST_REPORTING_ENTITY.bc_guid = TEST_REPORTING_GUID

def testAddEntityRaisesKeyError(self):
"""Test adding a different entity with a already existing guid."""
self.guid_to_entity_map.AddEntity(_TEST_REPORTING_ENTITY)
test_virtual_entity = VirtualEntity.FromDict(TEST_VIRTUAL_ENTITY_DICT)
test_virtual_entity.bc_guid = TEST_REPORTING_GUID

with self.assertRaises(KeyError):
self.guid_to_entity_map.AddEntity(_TEST_REPORTING_ENTITY)
self.guid_to_entity_map.AddEntity(test_virtual_entity)

def testGetEntityByGuidRaisesKeyError(self):
with self.assertRaises(KeyError):
Expand Down

0 comments on commit 0cf0502

Please sign in to comment.