Beispiel #1
0
    def test_deleted_filter(self):
        return  ## disabled by james on 9/6/16 to be replaced by proper unit tests

        # insert a filter.
        filter_id = self._insert_filter()

        # force the status to be new.
        self.db['match'].update_many({'FILTER_ID': ObjectId(filter_id)},
                                     {'$set': {
                                         'MATCH_STATUS': 0
                                     }})

        # call update.
        msgs = miner.email_matches()

        # check that email was created
        self._check_email()

        # assert we have messages, matches and filter.
        assert len(msgs) > 0
        assert self.db['match'].count() > 0
        assert self.db['filter'].count() > 0

        # delete the filter by setting status to 2
        self.user_token = self.tmp_token
        r, status_code = self.get('filter/%s' % filter_id)
        self.assert200(status_code)
        etag = r['_etag']
        r['status'] = 2

        # patch it.
        for key in r.keys():
            if key[0] == "_" and key != "_id":
                del r[key]
        r, status_code = self.put('filter/%s' % filter_id,
                                  r,
                                  headers=[('If-Match', etag)])

        # call update.
        msgs = miner.email_matches()
        self._check_email()

        # should be no messages.
        assert len(msgs) == 0
        assert self.db['match'].count() == 0
        assert self.db['filter'].count() > 0
Beispiel #2
0
def status_insert(items):

    # loop over each item.
    for item in items:

        # check if its a pre-or-post status.
        #if item['pre']:

        # log this.
        logging.info("recieved pre-status post")

        # archive the site.
        #backup_dir = utilities.backup_event(None, settings.BACKUP_STATUS_DIR, -1, settings.BACKUP_STATUS_MAX, True)

        # add this to the resource.
        #item['backup_path'] = backup_dir

        # this is the unique data push id to be assigned to all matches
        dpi = None
        if 'data_push_id' in item and item['data_push_id']:
            dpi = item['data_push_id']

        # re-run all filters.
        miner.rerun_filters(dpi)

        # trigger email.
        if not item['silent']:
            miner.email_matches()
        else:
            logging.info("status post was silent, no email sent")

        #else:
        #    abort(422, "Not allowed to POST status which isn't pre=True")

        # adds a row to the MatchMiner Stats dashboard datatable for the new CAMD update
        if not item['silent']:
            add_dashboard_row(item)

        # run matchengine on the entire database
        utilities.run_matchengine()
Beispiel #3
0
def status_insert(items):

    # loop over each item.
    for item in items:

        # check if its a pre-or-post status.
        #if item['pre']:

        # log this.
        logging.info("recieved pre-status post")

        # archive the site.
        #backup_dir = utilities.backup_event(None, settings.BACKUP_STATUS_DIR, -1, settings.BACKUP_STATUS_MAX, True)

        # add this to the resource.
        #item['backup_path'] = backup_dir

        # this is the unique data push id to be assigned to all matches
        dpi = None
        if 'data_push_id' in item and item['data_push_id']:
            dpi = item['data_push_id']

        # re-run all filters.
        miner.rerun_filters(dpi)

        # trigger email.
        if not item['silent']:
            miner.email_matches()
        else:
            logging.info("status post was silent, no email sent")

        #else:
        #    abort(422, "Not allowed to POST status which isn't pre=True")

        # adds a row to the MatchMiner Stats dashboard datatable for the new CAMD update
        if not item['silent']:
            add_dashboard_row(item)

        # run matchengine on the entire database
        utilities.run_matchengine()
Beispiel #4
0
def status_replaced(item, original):

    # check if its a pre-or-post status.
    if item['pre']:
        abort(422, "Not allowed to UPDATE status which isn't pre=False")

    # log this.
    logging.info("received update status")

    # this is the unique data push id to be assigned to all matches
    dpi = None
    if 'data_push_id' in item and item['data_push_id']:
        dpi = item['data_push_id']

    # re-run all filters.
    miner.rerun_filters(dpi)

    # trigger email.
    if not item['silent']:
        miner.email_matches()
    else:
        logging.info("status post was silent, no email sent")
Beispiel #5
0
def status_replaced(item, original):

    # check if its a pre-or-post status.
    if item['pre']:
        abort(422, "Not allowed to UPDATE status which isn't pre=False")

    # log this.
    logging.info("received update status")

    # this is the unique data push id to be assigned to all matches
    dpi = None
    if 'data_push_id' in item and item['data_push_id']:
        dpi = item['data_push_id']

    # re-run all filters.
    miner.rerun_filters(dpi)

    # trigger email.
    if not item['silent']:
        miner.email_matches()
    else:
        logging.info("status post was silent, no email sent")
Beispiel #6
0
    def test_email_matches(self):

        self.db['email'].drop()

        # add a team with two users
        team = {'_id': ObjectId(), 'first_name': 'Multiple_team_members_test'}
        users = [{
            '_id': ObjectId(),
            'first_name': 'user1',
            'last_name': 'user1',
            'user_name': 'u1',
            'roles': ['user'],
            'teams': [team['_id']],
            'email': '*****@*****.**'
        }, {
            '_id': ObjectId(),
            'first_name': 'user2',
            'last_name': 'user2',
            'user_name': 'u2',
            'roles': ['user'],
            'teams': [team['_id']],
            'email': '*****@*****.**'
        }]
        self.db['team'].insert_one(team)
        self.db['user'].insert_many(users)

        # add five old matches into the new bin
        matches = []
        for _ in range(5):
            tmp_match = self.match.copy()
            del tmp_match['_id']
            tmp_match['TEAM_ID'] = team['_id']
            tmp_match['USER_ID'] = users[0]['_id']
            tmp_match['_new_match'] = True
            matches.append(tmp_match)
        self.db['match'].insert_many(matches)

        # add five new matches into the new bin
        matches = []
        for _ in range(5):
            tmp_match = self.match.copy()
            del tmp_match['_id']
            tmp_match['TEAM_ID'] = team['_id']
            tmp_match['USER_ID'] = users[0]['_id']
            matches.append(tmp_match)
        self.db['match'].insert_many(matches)

        # call the email count function
        email_matches()

        # check the database
        matches = list(self.db['match'].find({'TEAM_ID': team['_id']}))
        for match in matches:
            assert '_new_match' in match and match['_new_match']
            assert match['MATCH_STATUS'] == 0

        emails = list(self.db['email'].find())
        assert len(emails) == 2
        for email in emails:
            assert int(
                email['body'].split('identified ')[1].split(' new')[0]) == 5