def test_date_time_datetime(self):
        filter = FilterBuilder()
        filter.date_time(
            "updated_since",
            datetime(year=2020, month=10, day=17, hour=13, minute=14,
                     second=7))

        assert filter.build() == "&updated_since=2020-10-17T13:14:07"
    def test_between_datetime_object(self):
        filter = FilterBuilder()
        filter.between("start_date",
                       min=datetime(year=2020,
                                    month=10,
                                    day=17,
                                    hour=13,
                                    minute=14))

        assert filter.build() == "&search[start_date]=2020-10-17"
示例#3
0
    def test_list_projects__filtered(self):
        url = "{}/projects/business/{}/projects?page=2&per_page=1".format(API_BASE_URL, self.business_id)
        httpretty.register_uri(
            httpretty.GET,
            url,
            body=json.dumps(get_fixture("list_projects_response")),
            status=200
        )

        filter = FilterBuilder()
        filter.boolean("active", True)
        self.freshBooksClient.projects.list(self.business_id, builders=[filter])

        expected_params = {"active": ["True"]}
        assert httpretty.last_request().querystring == expected_params
示例#4
0
    def test_list_callbacks__filtered(self):
        url = (
            "{}/events/account/{}/events/callbacks?search[event]=estimate.create"
        ).format(API_BASE_URL, self.account_id)
        httpretty.register_uri(
            httpretty.GET,
            url,
            body=json.dumps(get_fixture("list_callbacks_response")),
            status=200
        )

        filter = FilterBuilder()
        filter.equals("event", "estimate.create")

        self.freshBooksClient.callbacks.list(self.account_id, builders=[filter])

        expected_params = {"search[event]": ["estimate.create"]}
        assert httpretty.last_request().querystring == expected_params
    def test_list_clients__filtered(self):
        url = (
            "{}/accounting/account/{}/users/clients?search[userids][]=1&search[userids][]=2"
            "&search[date_min]=2010-10-17&search[date_max]=2012-11-21").format(
                API_BASE_URL, self.account_id)
        httpretty.register_uri(httpretty.GET,
                               url,
                               body=json.dumps(
                                   get_fixture("list_clients_response")),
                               status=200)

        date_min = datetime(year=2010, month=10, day=17, hour=5, minute=47)
        date_max = datetime(year=2012, month=11, day=21, hour=12, minute=34)
        filter = FilterBuilder()
        filter.in_list("userid", [1, 2])

        filter.between("date", min=date_min, max=date_max)
        self.freshBooksClient.clients.list(self.account_id, builders=[filter])

        expected_params = {
            "search[date_max]": ["2012-11-21"],
            "search[date_min]": ["2010-10-17"],
            "search[userids][]": ["1", "2"]
        }
        assert httpretty.last_request().querystring == expected_params
    def test_boolean_false(self):
        filter = FilterBuilder()
        filter.boolean("active", False)

        assert filter.build() == "&active=False"
    def test_between_min_max(self):
        filter = FilterBuilder()
        filter.between("amount", 1, 10)

        assert filter.build() == "&search[amount_min]=1&search[amount_max]=10"
    def test_between_max_specified(self):
        filter = FilterBuilder()
        filter.between("amount_max", max=10)

        assert filter.build() == "&search[amount_max]=10"
    def test_in_list__pluralized(self):
        filter = FilterBuilder()
        filter.in_list("userid", [1, 2])

        assert filter.build() == "&search[userids][]=1&search[userids][]=2"
    def test_like(self):
        filter = FilterBuilder()
        filter.like("user_like", "leaf")

        assert filter.build() == "&search[user_like]=leaf"
    def test_equals__resource_not_specified(self):
        filter = FilterBuilder()
        filter.equals("username", "Bob")

        assert filter.build() == "&search[username]=Bob"
    def test_equals__project(self):
        filter = FilterBuilder()
        filter.equals("username", "Bob")

        assert filter.build("ProjectResource") == "&username=Bob"
    def test_equals__accounting(self):
        filter = FilterBuilder()
        filter.equals("username", "Bob")

        assert filter.build("AccountingResource") == "&search[username]=Bob"
    def test_between_min_specified(self):
        filter = FilterBuilder()
        filter.between("amount_min", min=1)

        assert filter.build() == "&search[amount_min]=1"
    def test_boolean_true(self):
        filter = FilterBuilder()
        filter.boolean("active", True)

        assert filter.build() == "&active=True"
        assert str(filter) == "FilterBuilder(&active=True)"
    def test_between_date_string(self):
        filter = FilterBuilder()
        filter.between("start_date", min="2020-10-17")

        assert filter.build() == "&search[start_date]=2020-10-17"
    def test_date_time_string(self):
        filter = FilterBuilder()
        filter.date_time("updated_since", "2020-10-17T13:14:07")

        assert filter.build() == "&updated_since=2020-10-17T13:14:07"