예제 #1
0
def test_get_query_remaining(key):
    """
    Some fields are simply copied to the query as-is
    """
    vals = {key: "some-value"}
    filters = Filters(vals)
    query = filters.getQuery()
    assert query[key] == "some-value"
예제 #2
0
def test_get_query_not_subscribed(key):
    """
    Unsubscribed is treated the same way as unknown: it is omitted from the query
    """
    vals = {key: False}
    filters = Filters(vals)
    query = filters.getQuery()
    assert key not in query
예제 #3
0
def test_get_query_subscribed(key):
    """
    Subscription status is included when it is in the affirmative
    """
    vals = {key: True}
    filters = Filters(vals)
    query = filters.getQuery()
    assert query[key] is True
예제 #4
0
def test_get_query_multi_state():
    """
    Multiple states should be added to the query as a comma-separated list, enclosed by parentheses
    """
    vals = {"state_cd": ["AZ", "WY"]}
    filters = Filters(vals)
    query = filters.getQuery()
    assert query["state_cd"] == "(AZ,WY)"
예제 #5
0
def test_get_query_single_state(state_cd):
    """
    A single state_cd should be added to the query as-is
    """
    vals = {"state_cd": state_cd}
    filters = Filters(vals)
    query = filters.getQuery()
    assert query["state_cd"] == "AZ"
예제 #6
0
def test_get_query_failure():
    """
    Filters does not produce a query if any of the keys are not known
    """
    vals = {"this_key_does_not_exist": 123}
    filters = Filters(vals)

    with pytest.raises(FilterError):
        filters.getQuery()
예제 #7
0
    def cons_getConstituents(self, filter, bundles=None):
        query = {'filter': str(Filters(filter))}

        if bundles:
            query['bundles'] = str(Bundles(bundles))

        url_secure = self._generateRequest('/cons/get_constituents', query)
        return self._makeGETRequest(url_secure)
예제 #8
0
    def cons_getBulkConstituentData(self, request_format, fields, cons_ids=None, request_filter=None):
        query = {'format': str(request_format), 'fields': ','.join([str(field) for field in fields])}

        if cons_ids:
            query['cons_ids'] = ','.join([str(cons) for cons in cons_ids])

        if request_filter:
            query['filter'] = str(Filters(request_filter))

        url_secure = self._generateRequest('/cons/get_bulk_constituent_data', {})
        return self._makePOSTRequest(url_secure, query)
예제 #9
0
    def cons_getUpdatedConstituents(self, changed_since, request_filter=None, bundles=None):
        query = {'changed_since': str(changed_since)}

        if request_filter:
            query['filter'] = str(Filters(request_filter))

        if bundles:
            query['bundles'] = str(Bundles(bundles))

        url_secure = self._generateRequest('/cons/get_updated_constituents', query)
        return self._makeGETRequest(url_secure)
예제 #10
0
    def cons_getConstituentsByExtId(self, ext_type, ext_ids, request_filter=None, bundles=None):
        query = {'ext_type': ext_type, 'ext_ids': ','.join([str(elem) for elem in ext_ids])}

        if request_filter:
            query['filter'] = str(Filters(request_filter))

        if bundles:
            query['bundles'] = str(Bundles(bundles))

        url_secure = self._generateRequest('/cons/get_constituents_by_ext_id', query)
        return self._makeGETRequest(url_secure)
예제 #11
0
    def cons_getConstituentsById(self, cons_ids, request_filter=None, bundles=None):
        """Retrieves constituents by ID """
        query = {'cons_ids': ','.join([str(elem) for elem in cons_ids])}

        if request_filter:
            query['filter'] = str(Filters(request_filter))

        if bundles:
            query['bundles'] = str(Bundles(bundles))

        url_secure = self._generateRequest('/cons/get_constituents_by_id', query)
        return self._makeGETRequest(url_secure)
예제 #12
0
    def cons_get_constituents_by_id(self, cons_ids, filter=None, bundles=None):
        '''Retrieves constituents by ID '''
        query = {'cons_ids': ','.join([str(elem) for elem in cons_ids])}

        if filter:
            query['filter'] = str(Filters(filter))

        if bundles:
            query['bundles'] = str(Bundles(bundles))

        url_secure = self._generate_request('/cons/get_constituents_by_id',
                                            query)
        return self._make_get_request(url_secure)
예제 #13
0
 def cons_getUpdatedConstituentIds(self, changed_since, filter=None):
     query = {'changed_since': str(changed_since)}
     if filter:
         query['filter'] = str(Filters(filter))
     url_secure = self._generateRequest('/cons/get_updated_constituent_ids', query)
     return self._makeGETRequest(url_secure)