def test_count_matches(self): user = {'_id': ObjectId(), 'teams': [self.match['TEAM_ID']]} # one new matches counts = _count_matches( list(self.db['match'].find({'_id': ObjectId(self.match['_id'])})), self.db['match']) assert counts['new_matches'] == 1 assert self._new_match() is True # should be updated counts = _count_matches( list(self.db['match'].find({'_id': ObjectId(self.match['_id'])})), self.db['match']) assert counts['new_matches'] == 0 assert self._new_match() is True # check ther other condition that will evaluate to a new match self.db['match'].update({'_id': self.match['_id']}, {'$set': { '_new_match': False }}) counts = _count_matches( list(self.db['match'].find({'_id': ObjectId(self.match['_id'])})), self.db['match']) assert counts['new_matches'] == 1 assert self._new_match() is True counts = _count_matches( list(self.db['match'].find({'_id': ObjectId(self.match['_id'])})), self.db['match']) assert counts['new_matches'] == 0 assert self._new_match() is True
def _email_counts(teamid, match_db, filter_db): num_matches = 0 num_filters = 0 # look for matches. matches = list(match_db.find({'TEAM_ID': ObjectId(teamid)})) # calculate number of matches. counts = custom._count_matches(matches, match_db) num_matches += counts['new_matches'] # get the number of filters. num_filters += filter_db.find({'TEAM_ID': teamid, 'status': 1}).count() # return the counts return num_filters, num_matches