Skip to content

Commit

Permalink
Add DB tests for phone field
Browse files Browse the repository at this point in the history
  • Loading branch information
janbaykara committed Dec 12, 2024
1 parent 3522ddd commit 4052684
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
17 changes: 10 additions & 7 deletions hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,8 @@ def get_deduplication_hash(self) -> str:
hash_values = ["name"]
else:
hash_values = [
str(getattr(self, field)) for field in self.get_deduplication_field_names()
str(getattr(self, field))
for field in self.get_deduplication_field_names()
]
return hashlib.md5("".join(hash_values).encode()).hexdigest()

Expand Down Expand Up @@ -2582,6 +2583,7 @@ class LocalJSONSource(ExternalDataSource):
"""
A test table.
"""

crm_type = "test"
has_webhooks = False
automated_webhooks = False
Expand All @@ -2599,18 +2601,16 @@ def get_deduplication_field_names(self) -> list[str]:

def healthcheck(self):
return True

@cached_property
def df(self):
return pd.DataFrame(self.data).set_index(self.id_field)

def field_definitions(self):
# get all keys from self.data
return [
self.FieldDefinition(
label=col,
value=col
) for col in self.df.columns.tolist()
self.FieldDefinition(label=col, value=col)
for col in self.df.columns.tolist()
]

def get_record_id(self, record: dict):
Expand Down Expand Up @@ -2645,7 +2645,9 @@ async def update_many(self, mapped_records, **kwargs):
await self.update_one(mapped_record)

def delete_one(self, record_id):
self.data = [record for record in self.data if record[self.id_field] != record_id]
self.data = [
record for record in self.data if record[self.id_field] != record_id
]
self.save()

def create_one(self, record):
Expand All @@ -2658,6 +2660,7 @@ def create_many(self, records):
self.save()
return records


class AirtableSource(ExternalDataSource):
"""
An Airtable table.
Expand Down
6 changes: 3 additions & 3 deletions hub/tests/test_source_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ async def test_save_phone_field(self):
data=[
{"id": "bad1", "phone": "123456789"},
{"id": "good1", "phone": "07123456789"},
{"id": "good2", "phone": "+447123456789"}
]
{"id": "good2", "phone": "+447123456789"},
],
)
await sync_to_async(source.save)()

Expand All @@ -57,4 +57,4 @@ async def test_save_phone_field(self):
def test_valid_phone_number_for_usa(self):
phone = "4155552671"
result = validate_and_format_phone_number(phone, ["US"])
self.assertEqual(result, "+14155552671")
self.assertEqual(result, "+14155552671")

0 comments on commit 4052684

Please sign in to comment.