Skip to content

Commit 2863746

Browse files
Merge pull request #517 from biocore/csymons_metadata_updates
Adjustments to Metadata Push
2 parents 0868939 + 534387a commit 2863746

25 files changed

+3876
-207
lines changed

.github/workflows/python-package-conda.yml

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
VS_PASSWORD: "${{ secrets.VS_PASSWORD }}"
5757
VS_CRYPTOKEY: "${{ secrets.VS_CRYPTOKEY }}"
5858
VS_REGCODE: "${{ secrets.VS_REGCODE }}"
59+
GOOGLE_GEOCODING_KEY: "${{ secrets.GOOGLE_GEOCODING_KEY }}"
5960
run: |
6061
# pull out the port so we can modify the configuration file easily
6162
pgport=${{ job.services.postgres.ports[5432] }}

microsetta_private_api/admin/tests/test_admin_api.py

+3
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ def setup_test_data():
6060
12345,
6161
"US"
6262
),
63+
32.8798916,
64+
-117.2363115,
65+
False,
6366
"fakekit",
6467
"en_US")
6568
acct_repo.create_account(acc)

microsetta_private_api/admin/tests/test_admin_repo.py

+6
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def setup_test_data():
8585
12345,
8686
"US"
8787
),
88+
32.8798916,
89+
-117.2363115,
90+
False,
8891
"fakekit",
8992
"en_US")
9093
acct_repo.create_account(acc)
@@ -103,6 +106,9 @@ def setup_test_data():
103106
12345,
104107
"US"
105108
),
109+
32.8798916,
110+
-117.2363115,
111+
False,
106112
"fakekit",
107113
"en_US")
108114
acct_repo.create_account(acc)

microsetta_private_api/api/_account.py

+28
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from microsetta_private_api.repo.kit_repo import KitRepo
1717
from microsetta_private_api.repo.transaction import Transaction
1818
from microsetta_private_api.config_manager import SERVER_CONFIG
19+
from microsetta_private_api.util.google_geocoding import geocode_address
1920

2021

2122
def find_accounts_for_login(token_info):
@@ -66,6 +67,12 @@ def register_account(body, token_info):
6667
code = body.get("code", "")
6768
body["code"] = code
6869

70+
# We need these keys to exist to create the account object, but we'll
71+
# update them momentarily
72+
body["latitude"] = None
73+
body["longitude"] = None
74+
body["cannot_geocode"] = False
75+
6976
account_obj = Account.from_dict(body, token_info[JWT_ISS_CLAIM_KEY],
7077
token_info[JWT_SUB_CLAIM_KEY])
7178

@@ -96,6 +103,16 @@ def register_account(body, token_info):
96103
acct_repo = AccountRepo(t)
97104
acct_repo.create_account(account_obj)
98105
new_acct = acct_repo.get_account(new_acct_id)
106+
107+
# Now that we've successfully created an account, geocode it
108+
latitude, longitude, _, _, cannot_geocode = geocode_address(
109+
new_acct.address
110+
)
111+
new_acct.latitude = latitude
112+
new_acct.longitude = longitude
113+
new_acct.cannot_geocode = cannot_geocode
114+
acct_repo.update_account(new_acct)
115+
99116
t.commit()
100117

101118
response = jsonify(new_acct.to_api())
@@ -143,6 +160,17 @@ def update_account(account_id, body, token_info):
143160
)
144161
acc.language = body['language']
145162

163+
# Whenever someone updates their address, we need to update geocoding
164+
# info. We don't need to check if they're actually changing their
165+
# address, as the geocoding code prevents duplicate requests from
166+
# reaching Google's API
167+
latitude, longitude, _, _, cannot_geocode = geocode_address(
168+
acc.address
169+
)
170+
acc.latitude = latitude
171+
acc.longitude = longitude
172+
acc.cannot_geocode = cannot_geocode
173+
146174
# 422 handling is done inside acct_repo
147175
acct_repo.update_account(acc)
148176
t.commit()

microsetta_private_api/api/tests/test_api.py

+35-5
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,10 @@
7777
"first_name": "Jane",
7878
"last_name": "Doe",
7979
"language": "en_US",
80-
KIT_NAME_KEY: EXISTING_KIT_NAME
80+
KIT_NAME_KEY: EXISTING_KIT_NAME,
81+
"latitude": 32.8798916,
82+
"longitude": -117.2363115,
83+
"cannot_geocode": False
8184
}
8285
DUMMY_ACCT_INFO_2 = {
8386
"address": {
@@ -91,7 +94,10 @@
9194
"first_name": "Obie",
9295
"last_name": "Dobie",
9396
"language": "en_US",
94-
KIT_NAME_KEY: EXISTING_KIT_NAME_2
97+
KIT_NAME_KEY: EXISTING_KIT_NAME_2,
98+
"latitude": 32.8798916,
99+
"longitude": -117.2363115,
100+
"cannot_geocode": False
95101
}
96102
DUMMY_ACCT_ADMIN = {
97103
"address": {
@@ -104,7 +110,10 @@
104110
"email": TEST_EMAIL_3,
105111
"first_name": "Obie",
106112
"last_name": "Dobie",
107-
KIT_NAME_KEY: EXISTING_KIT_NAME_2
113+
KIT_NAME_KEY: EXISTING_KIT_NAME_2,
114+
"latitude": 32.8798916,
115+
"longitude": -117.2363115,
116+
"cannot_geocode": False
108117
}
109118

110119
SOURCE_ID_1 = "9fba75a5-6fbf-42be-9624-731b6a9a161a"
@@ -467,6 +476,9 @@ def _create_dummy_acct_from_t(t, create_dummy_1=True,
467476
input_obj['address']['post_code'],
468477
input_obj['address']['country_code']
469478
),
479+
input_obj['latitude'],
480+
input_obj['longitude'],
481+
input_obj['cannot_geocode'],
470482
input_obj['kit_name'],
471483
input_obj['language']
472484
)
@@ -697,6 +709,16 @@ def validate_dummy_acct_response_body(self, response_obj,
697709
expected_dict[ACCT_TYPE_KEY] = ACCT_TYPE_VAL
698710
expected_dict[CREATION_TIME_KEY] = real_creation_time
699711
expected_dict[UPDATE_TIME_KEY] = real_update_time
712+
713+
# the lat, long, and cannot_geocode need to be ignored for the sake of
714+
# comparisons
715+
expected_dict.pop("latitude", None)
716+
expected_dict.pop("longitude", None)
717+
expected_dict.pop("cannot_geocode", None)
718+
response_obj.pop("latitude", None)
719+
response_obj.pop("longitude", None)
720+
response_obj.pop("cannot_geocode", None)
721+
700722
self.assertEqual(expected_dict, response_obj)
701723

702724
return real_acct_id_from_body
@@ -740,11 +762,15 @@ def test_accounts_create_success(self):
740762

741763
def test_accounts_create_fail_400_without_required_fields(self):
742764
"""Return 400 validation fail if don't provide a required field """
765+
input_obj = copy.deepcopy(DUMMY_ACCT_INFO)
766+
input_obj.pop('latitude', None)
767+
input_obj.pop('longitude', None)
768+
input_obj.pop('cannot_geocode', None)
743769

744770
self.run_query_and_content_required_field_test(
745771
"/api/accounts", "post",
746772
self.default_querystring_dict,
747-
DUMMY_ACCT_INFO,
773+
input_obj,
748774
skip_fields=["kit_name"])
749775

750776
def test_accounts_create_fail_404(self):
@@ -926,7 +952,8 @@ def test_account_scrub_success(self):
926952
response_obj = json.loads(response.data)
927953

928954
for k in DUMMY_ACCT_INFO:
929-
if k in (KIT_NAME_KEY, 'language'):
955+
if k in (KIT_NAME_KEY, 'language', 'cannot_geocode', 'latitude',
956+
'longitude'):
930957
continue
931958
self.assertNotEqual(DUMMY_ACCT_INFO[k],
932959
response_obj[k])
@@ -1251,6 +1278,9 @@ def test_account_update_fail_400_without_required_fields(self):
12511278

12521279
dummy_acct_id = create_dummy_acct()
12531280
changed_acct_dict = self.make_updated_acct_dict()
1281+
changed_acct_dict.pop('latitude', None)
1282+
changed_acct_dict.pop('longitude', None)
1283+
changed_acct_dict.pop('cannot_geocode', None)
12541284

12551285
input_url = "/api/accounts/{0}".format(dummy_acct_id)
12561286
self.run_query_and_content_required_field_test(

microsetta_private_api/api/tests/test_integration.py

+12
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,9 @@ def setup_test_data():
173173
12345,
174174
"US"
175175
),
176+
32.8798916,
177+
-117.2363115,
178+
False,
176179
"fakekit",
177180
"en_US")
178181
acct_repo.create_account(acc)
@@ -779,6 +782,9 @@ def test_edit_account_info(self):
779782
# Hard to guess these two, so let's pop em out
780783
acc.pop("creation_time")
781784
acc.pop("update_time")
785+
acc.pop("latitude")
786+
acc.pop("longitude")
787+
acc.pop("cannot_geocode")
782788
self.assertDictEqual(acc, regular_data, "Check Initial Account Match")
783789

784790
regular_data.pop("account_id")
@@ -822,6 +828,9 @@ def test_edit_account_info(self):
822828
fuzzy_data["account_id"] = "aaaaaaaa-bbbb-cccc-dddd-eeeeffffffff"
823829
acc.pop('creation_time')
824830
acc.pop('update_time')
831+
acc.pop("latitude")
832+
acc.pop("longitude")
833+
acc.pop("cannot_geocode")
825834
self.assertDictEqual(fuzzy_data, acc, "Check Fuzz Account Match")
826835

827836
# Attempt to restore back to old data.
@@ -838,6 +847,9 @@ def test_edit_account_info(self):
838847

839848
acc.pop('creation_time')
840849
acc.pop('update_time')
850+
acc.pop("latitude")
851+
acc.pop("longitude")
852+
acc.pop("cannot_geocode")
841853
regular_data['account_type'] = 'standard'
842854
regular_data["account_id"] = "aaaaaaaa-bbbb-cccc-dddd-eeeeffffffff"
843855

microsetta_private_api/celery_utils.py

-4
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,6 @@ def __call__(self, *args, **kwargs):
4444
# "fetch_ffqs": {
4545
# "task": "microsetta_private_api.util.vioscreen.fetch_ffqs",
4646
# "schedule": 60 * 60 * 24 # every 24 hours
47-
# },
48-
# "geocode_accounts": {
49-
# "task": "microsetta_private_api.tasks.geocode_accounts",
50-
# "schedule": 60
5147
# }
5248
}
5349

0 commit comments

Comments
 (0)