def test_transactional_factory(): from google.cloud.firestore_v1.transaction import _Transactional from google.cloud.firestore_v1.transaction import transactional wrapped = transactional(mock.sentinel.callable_) assert isinstance(wrapped, _Transactional) assert wrapped.to_wrap is mock.sentinel.callable_
def test_update_state_returned_states(state_doc, initial_state, next_state, expected): initial_id = initial_state[0] initial_phase = initial_state[1] next_id = next_state[0] next_phase = next_state[1] add_state(state_doc, initial_phase, initial_id, DATE) write_state(state_doc) transactional_update_state = transactional(analytics.update_state) with transaction() as txn: result_state = transactional_update_state( txn, next_id, _date(2), next_phase, state_doc["source"], state_doc["year"], state_doc["species"], state_doc.get("altitude_grp"), ) assert len(result_state) == expected, (state_doc, result_state) assert _date(2) in result_state
def test_update_results_calculation(state, e_min, e_max, e_median, e_q25, e_q75): source = "src" species = "species" phase = "phase" year = 2000 altitude_grp = "grp" transactional_update_result = transactional(analytics.update_result) with transaction() as txn: transactional_update_result(txn, state, phase, source, year, species, altitude_grp) data = read_result() assert data["values"]["phase"]["min"] == e_min assert data["values"]["phase"]["max"] == e_max assert data["values"]["phase"]["median"] == e_median assert data["values"]["phase"]["quantile_25"] == e_q25 assert data["values"]["phase"]["quantile_75"] == e_q75
def test_update_state_initalized(altitude_grp): transactional_update_state = transactional(analytics.update_state) with transaction() as txn: result_state = transactional_update_state(txn, OBSERVATION_ID, DATE, PHASE, SOURCE, YEAR, SPECIES, altitude_grp) # check written document data = read_state(altitude_grp=altitude_grp) if altitude_grp is None: assert "altitude_grp" not in data else: assert data["altitude_grp"] == altitude_grp assert data["source"] == SOURCE assert data["year"] == YEAR assert data["species"] == SPECIES assert data["state"]["phase"][OBSERVATION_ID] == DATE # check returned state assert result_state[0] == DATE
def test_update_state_write(state_doc, obs_id, obs_date, phase, expected): add_state(state_doc, "phase1", "id1", _date(1)) add_state(state_doc, "phase2", "id1", _date(2)) add_state(state_doc, "phase1", "id2", _date(3)) add_state(state_doc, "phase2", "id3", _date(4)) base_state_ref = copy.deepcopy(state_doc) write_document( analytics.STATE_COLLECTION, analytics.get_analytics_document_id( state_doc["year"], state_doc["species"], state_doc["source"], state_doc.get("altitude_grp"), ), state_doc, ) transactional_update_state = transactional(analytics.update_state) with transaction() as txn: transactional_update_state( txn, obs_id, _date(obs_date), phase, state_doc["source"], state_doc["year"], state_doc["species"], state_doc.get("altitude_grp"), ) data = read_state( state_doc["year"], state_doc["species"], state_doc["source"], state_doc.get("altitude_grp"), ) assert deepdiff.DeepDiff(base_state_ref, data) == expected, ( base_state_ref, data, )
def _call_fut(to_wrap): from google.cloud.firestore_v1.transaction import transactional return transactional(to_wrap)