def test_create_search_count_company(self):
        """
        Should be able to search and count companies after creation.

        """
        with transaction():
            company1 = Company(name="name1").create()
            company2 = Company(name="name2").create()

        assert_that(Company.count(), is_(equal_to(2)))

        # Pagination fields do not affect count calculations
        assert_that(self.company_store.count(offset=1, limit=1), is_(equal_to(2)))

        assert_that([company.id for company in Company.search()], contains_inanyorder(company1.id, company2.id))
Example #2
0
    def test_create_search_count_company(self):
        """
        Should be able to search and count companies after creation.

        """
        with transaction():
            company1 = Company(name="name1").create()
            company2 = Company(name="name2").create()

        assert_that(Company.count(), is_(equal_to(2)))

        # Pagination fields do not affect count calculations
        assert_that(self.company_store.count(offset=1, limit=1),
                    is_(equal_to(2)))

        assert_that([company.id for company in Company.search()],
                    contains_inanyorder(company1.id, company2.id))
Example #3
0
    def test_create_delete_company_complicated_expression(self):
        """
        Delete should support more complicated criterion with the `fetch` synchronization strategy enabled.

        """
        with transaction():
            company = Company(name="name").create()
            Company(name="other-name").create()

        with transaction():
            self.company_store._delete(Company.name.in_(["name"]),
                                       synchronize_session="fetch")

        assert_that(
            calling(Company.retrieve).with_args(company.id),
            raises(ModelNotFoundError, pattern="Company not found"),
        )

        assert_that(Company.count(), is_(equal_to(1)))