fix api contact search
This commit is contained in:
1 parent
04d2bc957f
commit
39e64854b8
4 files changed
+124
-33
No files matched your search
@@ -39,6 +39,7 @@ def test_contact_feed_authentication_search_and_contract(client):
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"contacts": [{
|
||||
"name": "علی رضایی",
|
||||
"mobile": "09123456789",
|
||||
"phones": [{"type": "همراه", "number": "09123456789"}],
|
||||
}]}
|
||||
assert response["Cache-Control"] == "no-store"
|
||||
@@ -47,6 +48,50 @@ def test_contact_feed_authentication_search_and_contract(client):
|
||||
assert client.post(URL, **authorize(client)).status_code == 405
|
||||
|
||||
|
||||
@pytest.mark.parametrize("search", [
|
||||
"09123456789", "+989123456789", "00989123456789",
|
||||
"۰۹۱۲۳۴۵۶۷۸۹", "۰۹۱۲-۳۴۵-۶۷۸۹",
|
||||
])
|
||||
def test_contact_feed_finds_same_mobile_in_supported_formats(client, search):
|
||||
key = PhoneContactApiKey()
|
||||
key.set_key(FIRST_KEY)
|
||||
key.save()
|
||||
make_contact(mobile="09123456789", first_name="علی", last_name="رضایی")
|
||||
make_contact(mobile="09123456780", first_name="مریم")
|
||||
|
||||
response = client.get(URL, {"search": search}, **authorize(client))
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"contacts": [{
|
||||
"name": "علی رضایی",
|
||||
"mobile": "09123456789",
|
||||
"phones": [{"type": "همراه", "number": "09123456789"}],
|
||||
}]}
|
||||
assert client.get(URL, {"search": "09120000000"}, **authorize(client)).json() == {"contacts": []}
|
||||
|
||||
|
||||
@pytest.mark.parametrize("stored,search,display", [
|
||||
("+989131234567", "09131234567", "09131234567"),
|
||||
("+989131234567", "00989131234567", "09131234567"),
|
||||
("+982112345678", "02112345678", "02112345678"),
|
||||
("02112345678", "+982112345678", "02112345678"),
|
||||
("+982112345678", "0098-21-1234-5678", "02112345678"),
|
||||
])
|
||||
def test_contact_feed_matches_any_iranian_prefix_without_mobile_area_code_assumption(client, stored, search, display):
|
||||
key = PhoneContactApiKey()
|
||||
key.set_key(FIRST_KEY)
|
||||
key.save()
|
||||
profile = make_contact(mobile="09123456789", first_name="علی", last_name="رضایی")
|
||||
get_user_model().objects.filter(pk=profile.user_id).update(mobile=stored)
|
||||
|
||||
response = client.get(URL, {"search": search}, **authorize(client))
|
||||
assert response.status_code == 200
|
||||
assert response.json() == {"contacts": [{
|
||||
"name": "علی رضایی",
|
||||
"mobile": display,
|
||||
"phones": [{"type": "همراه" if display.startswith("09") else "تلفن", "number": display}],
|
||||
}]}
|
||||
|
||||
|
||||
def test_key_rotation_and_disabling_take_effect_immediately(client):
|
||||
key = PhoneContactApiKey()
|
||||
key.set_key(FIRST_KEY)
|
||||
|
||||
Reference in new issue
Block a user