def setup_test_data(): teardown_test_data() with Transaction() as t: acct_repo = AccountRepo(t) acc = Account(ACCT_ID_1, "*****@*****.**", "admin", ACCT_MOCK_ISS, ACCT_MOCK_SUB, "Dan", "H", Address( "456 Dan Lane", "Danville", "CA", 12345, "US" ), "fakekit", "en_US") acct_repo.create_account(acc) with t.cursor() as cur: cur.execute("UPDATE barcodes.project" " SET is_active = FALSE" " WHERE project_id = 2") t.commit()
def test_geocode_accounts_valid(self, test_verify_address): test_verify_address.return_value = { "address_1": DUMMY_ACCT_INFO_1['address']['street'], "address_2": "", "city": DUMMY_ACCT_INFO_1['address']['city'], "state": DUMMY_ACCT_INFO_1['address']['state'], "postal": DUMMY_ACCT_INFO_1['address']['post_code'], "country": DUMMY_ACCT_INFO_1['address']['country_code'], "latitude": RESULT_LAT, "longitude": RESULT_LONG, "valid": True } with Transaction() as t: ar = AccountRepo(t) acct_1 = Account.from_dict(DUMMY_ACCT_INFO_1, ACCT_MOCK_ISS_1, ACCT_MOCK_SUB_1) ar.create_account(acct_1) ar.geocode_accounts() with t.dict_cursor() as cur: cur.execute("SELECT latitude, longitude, address_verified, " "cannot_geocode FROM ag.account " "WHERE id = %s", (ACCT_ID_1,)) r = cur.fetchone() self.assertAlmostEqual(r['latitude'], RESULT_LAT, 9) self.assertAlmostEqual(r['longitude'], RESULT_LONG, 9) self.assertTrue(r['address_verified']) self.assertFalse(r['cannot_geocode'])
def setup_test_data(): teardown_test_data() with Transaction() as t: acct_repo = AccountRepo(t) acc = Account(ACCT_ID_1, "*****@*****.**", "admin", ACCT_MOCK_ISS, ACCT_MOCK_SUB, "Dan", "H", Address("456 Dan Lane", "Danville", "CA", 12345, "US"), "fakekit") acct_repo.create_account(acc) t.commit()
def _create_dummy_acct_from_t(t, create_dummy_1=True, iss=ACCT_MOCK_ISS, sub=ACCT_MOCK_SUB): if create_dummy_1: dummy_acct_id = ACCT_ID_1 dict_to_copy = DUMMY_ACCT_INFO else: dummy_acct_id = ACCT_ID_2 dict_to_copy = DUMMY_ACCT_INFO_2 input_obj = copy.deepcopy(dict_to_copy) input_obj["id"] = dummy_acct_id acct_repo = AccountRepo(t) acct_repo.create_account(Account.from_dict(input_obj, iss, sub)) return dummy_acct_id
def register_account(body, token_info): # First register with AuthRocket, then come here to make the account new_acct_id = str(uuid.uuid4()) body["id"] = new_acct_id # Account.from_dict requires a kit_name, even if blank kit_name = body.get("kit_name", "") body["kit_name"] = kit_name code = body.get("code", "") body["code"] = code account_obj = Account.from_dict(body, token_info[JWT_ISS_CLAIM_KEY], token_info[JWT_SUB_CLAIM_KEY]) if kit_name == "" and code == "": return jsonify(code=400, message="Account registration requires " "valid kit ID or activation code"), 400 with Transaction() as t: activation_repo = ActivationRepo(t) if code != "": can_activate, cause = activation_repo.can_activate_with_cause( body["email"], code) if not can_activate: return jsonify(code=404, message=cause), 404 else: activation_repo.use_activation_code(body["email"], code) if kit_name != "": kit_repo = KitRepo(t) kit = kit_repo.get_kit_all_samples(kit_name) if kit is None: return jsonify(code=404, message="Kit name not found"), 404 acct_repo = AccountRepo(t) acct_repo.create_account(account_obj) new_acct = acct_repo.get_account(new_acct_id) t.commit() response = jsonify(new_acct.to_api()) response.status_code = 201 response.headers['Location'] = '/api/accounts/%s' % new_acct_id return response
def setup_test_data(): AdminTests.teardown_test_data() with Transaction() as t: acct_repo = AccountRepo(t) acc = Account(STANDARD_ACCT_ID, "*****@*****.**", "standard", "https://MOCKUNITTEST.com", "1234ThisIsNotARealSub", "NotDan", "NotH", Address( "123 Dan Lane", "NotDanville", "CA", 12345, "US" ), "fakekit") acct_repo.create_account(acc) acc = Account(ADMIN_ACCT_ID, "*****@*****.**", "admin", "https://MOCKUNITTEST.com", "5678ThisIsNotARealAdminSub", "Dan", "H", Address( "456 Dan Lane", "Danville", "CA", 12345, "US" ), "fakekit") acct_repo.create_account(acc) t.commit()
def register_account(body, token_info): # First register with AuthRocket, then come here to make the account new_acct_id = str(uuid.uuid4()) body["id"] = new_acct_id account_obj = Account.from_dict(body, token_info[JWT_ISS_CLAIM_KEY], token_info[JWT_SUB_CLAIM_KEY]) with Transaction() as t: kit_repo = KitRepo(t) kit = kit_repo.get_kit_all_samples(body['kit_name']) if kit is None: return jsonify(code=404, message="Kit name not found"), 404 acct_repo = AccountRepo(t) acct_repo.create_account(account_obj) new_acct = acct_repo.get_account(new_acct_id) t.commit() response = jsonify(new_acct.to_api()) response.status_code = 201 response.headers['Location'] = '/api/accounts/%s' % new_acct_id return response