def testDisableEnable(self): """Tests for the state file upon switching to disabled.""" self.metadata_watcher_.SetGetMetadataResult('{"enabled": true}') iap_watcher.Main(Object({ 'iap_metadata_key': 'AEF_IAP_state', 'output_state_file': self.path, 'polling_interval': 1, }), watcher=self.metadata_watcher_, loop_watcher=False) self.assertTrue(os.path.isfile(self.path)) self.metadata_watcher_.SetGetMetadataResult('{"enabled": false}') iap_watcher.Main(Object({ 'iap_metadata_key': 'AEF_IAP_state', 'output_state_file': self.path, 'polling_interval': 1, }), watcher=self.metadata_watcher_, loop_watcher=False) self.assertFalse(os.path.isfile(self.path)) self.metadata_watcher_.SetGetMetadataResult('{"enabled": true}') iap_watcher.Main(Object({ 'iap_metadata_key': 'AEF_IAP_state', 'output_state_file': self.path, 'polling_interval': 1, }), watcher=self.metadata_watcher_, loop_watcher=False) self.assertTrue(os.path.isfile(self.path))
def play_transactions(transactions, accountId=None, categoryId=None, decorate=False, starting_balance=0): """ Play all the transactions in a accountID, and in categoryId, respecting split transactions. If decorate is True, returns the list of transactions decorated with a running balance, starting with `starting_balance` """ balance = starting_balance result = [] for t in transactions: balance += play_transaction(t, accountId, categoryId) if decorate: with_balance = Object(t.copy()) with_balance.balance = balance result.append(with_balance) if decorate: return result else: return balance
def testUnparseableMetadata(self): """Tests for the state file does not exist on metadata unparseable.""" self.metadata_watcher_.SetGetMetadataResult('"enabled": true') iap_watcher.Main(Object({ 'iap_metadata_key': 'AEF_IAP_state', 'output_state_file': self.path, 'polling_interval': 1, }), watcher=self.metadata_watcher_, loop_watcher=False) self.assertFalse(os.path.isfile(self.path))
def testEmptyMetadata(self): """Tests that the state file does not exist if the metadata is empty.""" self.metadata_watcher_.SetGetMetadataResult('') iap_watcher.Main(Object({ 'iap_metadata_key': 'AEF_IAP_state', 'output_state_file': self.path, 'polling_interval': 1, }), watcher=self.metadata_watcher_, loop_watcher=False) self.assertFalse(os.path.isfile(self.path))
def testEnabledKeyNotPresentInParsedMetadata(self): """Tests that absence of the key 'enabled' in the parsed metadata results in verification being disabled.""" self.metadata_watcher_.SetGetMetadataResult('{"asdf": true}') iap_watcher.Main(Object({ 'iap_metadata_key': 'AEF_IAP_state', 'output_state_file': self.path, 'polling_interval': 1, }), watcher=self.metadata_watcher_, loop_watcher=False) self.assertFalse(os.path.isfile(self.path))
def testDisable(self): """Tests for the state file does not exist on metadata disabled.""" self.metadata_watcher_.SetGetMetadataResult('{"enabled": false}') iap_watcher.Main(Object({ 'iap_metadata_key': 'AEF_IAP_state', 'output_state_file': self.path, 'polling_interval': 1, 'fetch_keys': False, }), watcher=self.metadata_watcher_, loop_watcher=False) self.assertFalse(os.path.isfile(self.path))
def testEnable(self): """Tests for the state file exists on metadata enable.""" path = '%s/tmp' % self.pathname_ self.metadata_watcher_.SetGetMetadataResult('{"enabled": true}') iap_watcher.Main(Object({ 'iap_metadata_key': 'AEF_IAP_state', 'output_state_file': path, 'polling_interval': 1, }), watcher=self.metadata_watcher_, loop_watcher=False) self.assertTrue(os.path.isfile(path))
def do_transaction(self, item, balances): result = Object(item.copy()) result.has_subtransactions = False sub_transactions = [] if 'subTransactions' in item: sub_transactions = item.subTransactions result.has_subtransactions = bool(item.subTransactions) result.pop('subTransactions') if 'matchedTransactions' in item: result.pop('matchedTransactions') balances[item.accountId] = balances.get(item.accountId, 0) + item.amount result['balance'] = balances[item.accountId] self.transactions_table.insert(result) for sub in sub_transactions: self.sub_transactions_table.insert(sub)
def getAllForSaleProperties(cursor): dataArray = [] query = (""" SELECT prop.street_address, prop.city, prop.state, prop.zip_code, prop.sqft, prop.beds, prop.baths, prop.neighborhood, MAX(details.rental_price) as rental_price, MAX(details.rental_price_sqft), prop.latitude, prop.longitude, prop.property_url FROM `properties` AS prop INNER JOIN `property_details` AS details ON prop.street_address = details.street_address WHERE `is_rental` = False AND prop.forsale_status = "active" AND prop.city = "Bentonville" GROUP BY prop.street_address; """) cursor.execute(query) tupleProperties = cursor.fetchall() # convert tuple to array for streetAddress, city, state, zipCode, sqft, beds, baths, neighborhood, rentalPrice, rentalPriceSqft, latitude, longitude, propertyURL in tupleProperties: dataObject = { "streetAddress": streetAddress, "city": city, "state": state, "zipCode": zipCode, "sqft": sqft, "beds": beds, "baths": baths, "neighborhood": neighborhood, "rentalPrice": rentalPrice, "rentalPriceSqft": rentalPriceSqft, "latitude": latitude, "longitude": longitude, "propertyURL": propertyURL, } jsObject = Object(dataObject) #store all houses in javascript-like array of objects dataArray.append(jsObject) return dataArray
def testFetchKeys(self): """Tests that keys are fetched when the fetch_keys argument is True.""" state_path = '%s/tmp' % self.pathname_ key_path = '%s/keys' % self.pathname_ self.metadata_watcher_.SetGetMetadataResult('{"enabled": true}') def mock_os_system(command): self.cmd = command iap_watcher.Main(Object({ 'iap_metadata_key': 'AEF_IAP_state', 'output_state_file': state_path, 'polling_interval': 1, 'fetch_keys': True, 'output_key_file': key_path, }), watcher=self.metadata_watcher_, loop_watcher=False, os_system=mock_os_system) self.assertEqual( self.cmd, 'curl "https://www.gstatic.com/iap/verify/public_key-jwk" > ' + key_path)
def walk_budget(budget, categoryId: str): """ Walk all budget months If an amount is budgeted, add to running total Play all the transactions in that categoryId for that month If at the end the balance is negative: If overspendingHandling is 'Affectsbuffer, reset balance to 0 If overspendingHandling is "Confined", keep balance Returns the state of the category across all month as an array """ transactions = [ t for t in budget.transactions if transaction_touches_category(t, categoryId) ] by_month = transactions_by_month(transactions) balance = 0.0 overspendingHandling = 'AffectsBuffer' non_empty_budgets = [ b for b in budget.monthlyBudgets if b.monthlySubCategoryBudgets ] monthly_budgets = sorted(non_empty_budgets, key=lambda k: k.month) result = [] for month_budget in monthly_budgets: year_month = month_budget.month[0:7] category_budget = find(lambda c: c.categoryId == categoryId, month_budget.monthlySubCategoryBudgets) or {} budgeted = category_budget.get('budgeted', 0) outflows = play_transactions_category(by_month.get(year_month, []), categoryId) balance = round(balance + budgeted + outflows, 2) overspendingHandling = category_budget.get( 'overspendingHandling') or overspendingHandling result_this_month = Object({ 'month': year_month, 'entityType': 'monthlyEnvelopResult', 'monthlySubCategoryBudgetsId': month_budget.entityId, 'balance': balance, 'outflows': outflows, 'budgeted': budgeted, 'overspendingHandling': overspendingHandling }) if balance < 0 and overspendingHandling == 'AffectsBuffer': # Category is overspent for this month balance = 0 result.append(result_this_month) return result
def getPropertiesByFilter(cursor, cities, minForsalePrice, maxForsalePrice, minSqft, maxSqft, minPriceSqft, maxPriceSqft, isForSale, isForeclosure, isPending, isSold, isRecentlySold, isForRent, isRented, isNoRentals, beds, baths): #init variables dataArray = [] params = "" formattedCities = "" counter = 1 #format cities into comma separated list for city in cities: formattedCities += '"' + city + '"' if (counter != len(cities)): formattedCities += "," counter += 1 #check if price was passed if ((minForsalePrice > 0) and (maxForsalePrice > 0)): params += " AND details.forsale_price BETWEEN " + str( minForsalePrice) + " AND " + str(maxForsalePrice) elif (minForsalePrice > 0): params += " AND details.forsale_price >= " + str(minForsalePrice) elif (maxForsalePrice > 0): params += " AND details.forsale_price <= " + str(maxForsalePrice) #check if minSqft was passed if ((minSqft > 0) and (maxSqft > 0)): params += " AND prop.sqft BETWEEN " + str(minSqft) + " AND " + str( maxSqft) elif (minSqft > 0): params += " AND prop.sqft >= " + str(minSqft) elif (maxSqft > 0): params += " AND prop.sqft <= " + str(maxSqft) #check if priceSqft was passed if ((minPriceSqft > 0) and (maxPriceSqft > 0)): params += " AND details.forsale_price_sqft BETWEEN " + str( minPriceSqft) + " AND " + str(maxPriceSqft) elif (minPriceSqft > 0): params += " AND details.forsale_price_sqft >= " + str(minPriceSqft) elif (maxPriceSqft > 0): params += " AND details.forsale_price_sqft <= " + str(maxPriceSqft) #check if beds was passed if (beds != ""): #check for the '+' char for exact or >= if (re.search(r"\+", beds)): pattern = re.compile(r'[0-9]+') beds = pattern.search(beds).group(0) params += " AND prop.beds >= " + beds else: params += " AND prop.beds = " + beds #check if baths was passed if (baths != ""): #check for the '+' char for exact or >= if (re.search(r"\+", baths)): pattern = re.compile(r'[0-9]+') baths = pattern.search(baths).group(0) params += " AND prop.baths >= " + baths else: params += " AND prop.baths = " + baths #for sale properties if (isForSale == True): params += " AND prop.forsale_status = 'active'" if (isForeclosure == True): #not tracking forclosures print("Foreclosure passed") if (isPending == True): #not tracking pending print("Pending passed") if (isSold == True): #need to write query print("Sold passed") if (isRecentlySold == True): #need to write query print("Recently Sold passed") #renting properties if (isForRent == True): params += " AND prop.is_rental = True AND prop.rental_status = 'active'" if (isRented == True): params += " AND prop.is_rental = True AND prop.rental_status = 'inactive'" if (isNoRentals == True): params += " AND prop.is_rental = False AND prop.rental_status = 'inactive'" #TODO use parameters for city query = (""" SELECT prop.street_address, prop.city, prop.state, prop.zip_code, prop.sqft, prop.beds, prop.baths, prop.neighborhood, MAX(details.forsale_price), MAX(details.forsale_price_sqft), MAX(details.rental_price), MAX(details.rental_price_sqft), details.date, details.event, prop.latitude, prop.longitude, prop.property_url FROM `properties` AS prop INNER JOIN `property_details` AS details ON prop.street_address = details.street_address WHERE prop.city in ({0}) {1} GROUP BY prop.street_address; """).format(formattedCities, params) cursor.execute(query) tupleProperties = cursor.fetchall() # convert tuple to array for streetAddress, city, state, zipCode, sqft, beds, baths, neighborhood, forsalePrice, forsalePriceSqft, rentalPrice, rentalPriceSqft, date, event, latitude, longitude, propertyURL in tupleProperties: dataObject = { "streetAddress": streetAddress, "city": city, "state": state, "zipCode": zipCode, "sqft": sqft, "beds": beds, "baths": baths, "neighborhood": neighborhood, "forsalePrice": forsalePrice, "forsalePriceSqft": forsalePriceSqft, "rentalPrice": rentalPrice, "rentalPriceSqft": rentalPriceSqft, "date": str(date), "event": event, "latitude": latitude, "longitude": longitude, "propertyURL": propertyURL, } jsObject = Object(dataObject) #store all houses in javascript-like array of objects dataArray.append(jsObject) return dataArray