def test_get_document_archived(self): from corehq.apps.commtrack.tests.util import get_single_balance_block from corehq.apps.commtrack.models import StockState from corehq.apps.products.models import SQLProduct block = get_single_balance_block(self.case.case_id, self.product_a._id, 100) submit_case_blocks(block, DOMAIN) stock_states = StockState.include_archived.all() self.assertEquals(1, len(stock_states)) def toggle_product_archive(): sql_product = SQLProduct.objects.get(code=self.product_a.code) sql_product.is_archived = not sql_product.is_archived sql_product.save() toggle_product_archive() self.addCleanup(toggle_product_archive) self.assertTrue(SQLProduct.objects.get(code=self.product_a.code).is_archived) state = stock_states[0] store = LedgerV1DocumentStore(DOMAIN) doc = store.get_document(state.id) self.assertEquals(int(doc['_id']), state.id) self.assertEquals(doc['case_id'], state.case_id)
def get_document_store(data_source_type, data_source_name, domain): if data_source_type == COUCH: try: return CouchDocumentStore( couch_config.get_db_for_db_name(data_source_name)) except DatabaseNotFound: # in debug mode we may be flipping around our databases so don't fail hard here if settings.DEBUG: return None raise elif data_source_type == FORM_SQL: return ReadonlyFormDocumentStore(domain) elif data_source_type == CASE_SQL: return ReadonlyCaseDocumentStore(domain) elif data_source_type == SMS: return ReadonlySMSDocumentStore() elif data_source_type == LEDGER_V2: return ReadonlyLedgerV2DocumentStore(domain) elif data_source_type == LEDGER_V1: return LedgerV1DocumentStore(domain) elif data_source_type == LOCATION: return ReadonlyLocationDocumentStore(domain) else: raise UnknownDocumentStore( 'getting document stores for backend {} is not supported!'.format( data_source_type))
def get_document_store(data_source_type, data_source_name, domain): # change this to just 'data_source_name' after June 2018 type_or_name = (data_source_type, data_source_name) if data_source_type == SOURCE_COUCH: try: return CouchDocumentStore( couch_config.get_db_for_db_name(data_source_name)) except DatabaseNotFound: # in debug mode we may be flipping around our databases so don't fail hard here if settings.DEBUG: return None raise elif FORM_SQL in type_or_name: return ReadonlyFormDocumentStore(domain) elif CASE_SQL in type_or_name: return ReadonlyCaseDocumentStore(domain) elif SMS in type_or_name: return ReadonlySMSDocumentStore() elif LEDGER_V2 in type_or_name: return ReadonlyLedgerV2DocumentStore(domain) elif LEDGER_V1 in type_or_name: return LedgerV1DocumentStore(domain) elif LOCATION in type_or_name: return ReadonlyLocationDocumentStore(domain) elif SYNCLOG_SQL in type_or_name: return ReadonlySyncLogDocumentStore() else: raise UnknownDocumentStore( 'getting document stores for backend {} is not supported!'.format( data_source_type))
def test_get_document(self): from corehq.apps.commtrack.tests.util import get_single_balance_block block = get_single_balance_block(self.case.case_id, self.product_a._id, 100) submit_case_blocks(block, DOMAIN) from corehq.apps.commtrack.models import StockState stock_states = StockState.include_archived.all() self.assertEquals(1, len(stock_states)) state = stock_states[0] store = LedgerV1DocumentStore(DOMAIN) doc = store.get_document(state.id) self.assertEquals(int(doc['_id']), state.id) self.assertEquals(doc['case_id'], state.case_id)
def get_document_store(data_source_type, data_source_name, domain, load_source="unknown"): # change this to just 'data_source_name' after June 2018 type_or_name = (data_source_type, data_source_name) if data_source_type == SOURCE_COUCH: try: return CouchDocumentStore( couch_config.get_db_for_db_name(data_source_name)) except DatabaseNotFound: # in debug mode we may be flipping around our databases so don't fail hard here if settings.DEBUG: return None raise elif FORM_SQL in type_or_name: store = FormDocumentStore(domain) load_counter = form_load_counter elif CASE_SQL in type_or_name: store = CaseDocumentStore(domain) load_counter = case_load_counter elif SMS in type_or_name: store = SMSDocumentStore() load_counter = sms_load_counter elif LEDGER_V2 in type_or_name: store = LedgerV2DocumentStore(domain) load_counter = ledger_load_counter elif LEDGER_V1 in type_or_name: store = LedgerV1DocumentStore(domain) load_counter = ledger_load_counter elif LOCATION in type_or_name: return LocationDocumentStore(domain) elif SYNCLOG_SQL in type_or_name: return SyncLogDocumentStore() else: raise UnknownDocumentStore( 'getting document stores for backend {} is not supported!'.format( data_source_type)) track_load = load_counter(load_source, domain) return DocStoreLoadTracker(store, track_load)