def test_filter_categories_by_one_condition(self):
        """Test filter_categories_by returns a list of categories that meet
        the filtering condition"""

        CategoryFactory.create_batch(3, description='generic category')
        should_be_missing = CategoryFactory.create(description='other category')

        retrieved_categories = (self.project_repo
            .filter_categories_by(description='generic category'))

        assert len(retrieved_categories) == 3, retrieved_categories
        assert should_be_missing not in retrieved_categories, retrieved_categories
    def test_filter_categories_by_one_condition(self):
        """Test filter_categories_by returns a list of categories that meet
        the filtering condition"""

        CategoryFactory.create_batch(3, description='generic category')
        should_be_missing = CategoryFactory.create(description='other category')

        retrieved_categories = (self.project_repo
            .filter_categories_by(description='generic category'))

        assert len(retrieved_categories) == 3, retrieved_categories
        assert should_be_missing not in retrieved_categories, retrieved_categories
Example #3
0
    def test_filter_categories_by_limit_offset(self):
        """Test that filter_categories_by supports limit and offset options"""

        CategoryFactory.create_batch(4)
        all_categories = self.project_repo.filter_categories_by()

        first_two = self.project_repo.filter_categories_by(limit=2)
        last_two = self.project_repo.filter_categories_by(limit=2, offset=2)

        assert len(first_two) == 2, first_two
        assert len(last_two) == 2, last_two
        assert first_two == all_categories[:2]
        assert last_two == all_categories[2:]
    def test_filter_categories_by_limit_offset(self):
        """Test that filter_categories_by supports limit and offset options"""

        CategoryFactory.create_batch(4)
        all_categories = self.project_repo.filter_categories_by()

        first_two = self.project_repo.filter_categories_by(limit=2)
        last_two = self.project_repo.filter_categories_by(limit=2, offset=2)

        assert len(first_two) == 2, first_two
        assert len(last_two) == 2, last_two
        assert first_two == all_categories[:2]
        assert last_two == all_categories[2:]
Example #5
0
    def test_avg_tasks_per_category(self):
        """Test average tasks per category created since current time"""
        date_recent = (datetime.datetime.utcnow() -
                       datetime.timedelta(31)).isoformat()
        date_now = (datetime.datetime.utcnow() -
                    datetime.timedelta(1)).isoformat()
        expected_avg_tasks = 3

        categories = CategoryFactory.create_batch(3)
        project1 = ProjectFactory.create(category=categories[0],
                                         created=date_now)
        project2 = ProjectFactory.create(category=categories[1],
                                         created=date_recent)
        project3 = ProjectFactory.create(category=categories[2],
                                         created=date_recent)

        for i in range(5):
            TaskFactory.create(project=project1, created=date_now)

        for i in range(2):
            TaskFactory.create(project=project2, created=date_recent)

        for i in range(3):
            TaskFactory.create(project=project3, created=date_recent)

        avg_tasks = round(stats.tasks_per_category())
        assert avg_tasks == expected_avg_tasks, "Average tasks created per category should be {}".format(
            expected_avg_tasks)
    def get_all_returns_list_of_all_categories(self):
        """Test get_all_categories returns a list of all the existing categories"""

        categories = CategoryFactory.create_batch(3)

        retrieved_categories = self.project_repo.get_all_categories()

        assert isinstance(retrieved_categories, list)
        assert len(retrieved_categories) == len(categories), retrieved_categories
        for category in retrieved_categories:
            assert category in categories, category
    def get_all_returns_list_of_all_categories(self):
        """Test get_all_categories returns a list of all the existing categories"""

        categories = CategoryFactory.create_batch(3)

        retrieved_categories = self.project_repo.get_all_categories()

        assert isinstance(retrieved_categories, list)
        assert len(retrieved_categories) == len(categories), retrieved_categories
        for category in retrieved_categories:
            assert category in categories, category
Example #8
0
    def test_get_categories_with_recent_projects(self):
        """Test categories with projects created in last 30 days"""
        date_now = datetime.datetime.utcnow()
        date_60_days_old = (datetime.datetime.utcnow() -  datetime.timedelta(60)).isoformat()

        categories = CategoryFactory.create_batch(3)
        unused_category = CategoryFactory.create()

        ProjectFactory.create(category=categories[0], created=date_now)
        ProjectFactory.create(category=categories[1], created=date_now)
        ProjectFactory.create(category=categories[0], created=date_now)

        ProjectFactory.create(category=categories[2], created=date_60_days_old)
        total_categories = stats.categories_with_new_projects()
        assert total_categories == 2, "Total categories with recent projects should be 2"