diff --git a/tests/factories.py b/tests/factories.py index 132b007f..379556ca 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -229,20 +229,6 @@ class StorageEntryFactory(Factory): value = factory.Sequence(lambda n: {"value": "value-{}".format(n)}) -class UserStoryFactory(Factory): - class Meta: - model = "userstories.UserStory" - strategy = factory.CREATE_STRATEGY - - ref = factory.Sequence(lambda n: n) - project = factory.SubFactory("tests.factories.ProjectFactory") - owner = factory.SubFactory("tests.factories.UserFactory") - subject = factory.Sequence(lambda n: "User Story {}".format(n)) - description = factory.Sequence(lambda n: "User Story {} description".format(n)) - status = factory.SubFactory("tests.factories.UserStoryStatusFactory") - milestone = factory.SubFactory("tests.factories.MilestoneFactory") - - class UserStoryStatusFactory(Factory): class Meta: model = "projects.UserStoryStatus" @@ -273,21 +259,19 @@ class MilestoneFactory(Factory): estimated_finish = factory.LazyAttribute(lambda o: o.estimated_start + timedelta(days=7)) -class IssueFactory(Factory): +class UserStoryFactory(Factory): class Meta: - model = "issues.Issue" + model = "userstories.UserStory" strategy = factory.CREATE_STRATEGY ref = factory.Sequence(lambda n: n) - subject = factory.Sequence(lambda n: "Issue {}".format(n)) - description = factory.Sequence(lambda n: "Issue {} description".format(n)) - owner = factory.SubFactory("tests.factories.UserFactory") project = factory.SubFactory("tests.factories.ProjectFactory") - status = factory.SubFactory("tests.factories.IssueStatusFactory") - severity = factory.SubFactory("tests.factories.SeverityFactory") - priority = factory.SubFactory("tests.factories.PriorityFactory") - type = factory.SubFactory("tests.factories.IssueTypeFactory") + owner = factory.SubFactory("tests.factories.UserFactory") + subject = factory.Sequence(lambda n: "User Story {}".format(n)) + description = factory.Sequence(lambda n: "User Story {} description".format(n)) + status = factory.SubFactory("tests.factories.UserStoryStatusFactory") milestone = factory.SubFactory("tests.factories.MilestoneFactory") + tags = factory.Faker("words") class TaskFactory(Factory): @@ -303,7 +287,25 @@ class TaskFactory(Factory): status = factory.SubFactory("tests.factories.TaskStatusFactory") milestone = factory.SubFactory("tests.factories.MilestoneFactory") user_story = factory.SubFactory("tests.factories.UserStoryFactory") - tags = [] + tags = factory.Faker("words") + + +class IssueFactory(Factory): + class Meta: + model = "issues.Issue" + strategy = factory.CREATE_STRATEGY + + ref = factory.Sequence(lambda n: n) + subject = factory.Sequence(lambda n: "Issue {}".format(n)) + description = factory.Sequence(lambda n: "Issue {} description".format(n)) + owner = factory.SubFactory("tests.factories.UserFactory") + project = factory.SubFactory("tests.factories.ProjectFactory") + status = factory.SubFactory("tests.factories.IssueStatusFactory") + severity = factory.SubFactory("tests.factories.SeverityFactory") + priority = factory.SubFactory("tests.factories.PriorityFactory") + type = factory.SubFactory("tests.factories.IssueTypeFactory") + milestone = factory.SubFactory("tests.factories.MilestoneFactory") + tags = factory.Faker("words") class WikiPageFactory(Factory): diff --git a/tests/integration/test_searches.py b/tests/integration/test_searches.py index 342b14ea..1ccd5233 100644 --- a/tests/integration/test_searches.py +++ b/tests/integration/test_searches.py @@ -52,37 +52,30 @@ def searches_initial_data(): role__project=m.project1, role__permissions=list(map(lambda x: x[0], MEMBERS_PERMISSIONS))) - f.RoleFactory(project=m.project2) - m.points1 = f.PointsFactory(project=m.project1, value=None) - m.points2 = f.PointsFactory(project=m.project2, value=None) + m.us11 = f.UserStoryFactory(project=m.project1, subject="Back to the future") + m.us12 = f.UserStoryFactory(project=m.project1, description="Back to the future") + m.us13 = f.UserStoryFactory(project=m.project1, tags=["Backend", "future"]) + m.us14 = f.UserStoryFactory(project=m.project1) + m.us21 = f.UserStoryFactory(project=m.project2, subject="Backend to the future") - m.role_points1 = f.RolePointsFactory.create(role=m.project1.roles.all()[0], - points=m.points1, - user_story__project=m.project1) - m.role_points2 = f.RolePointsFactory.create(role=m.project1.roles.all()[0], - points=m.points1, - user_story__project=m.project1, - user_story__description="Back to the future") - m.role_points3 = f.RolePointsFactory.create(role=m.project2.roles.all()[0], - points=m.points2, - user_story__project=m.project2) + m.task11 = f.TaskFactory(project=m.project1, subject="Back to the future") + m.task12 = f.TaskFactory(project=m.project1, tags=["Back", "future"]) + m.task13 = f.TaskFactory(project=m.project1) + m.task14 = f.TaskFactory(project=m.project1, description="Backend to the future") + m.task21 = f.TaskFactory(project=m.project2, subject="Back to the future") - m.us1 = m.role_points1.user_story - m.us2 = m.role_points2.user_story - m.us3 = m.role_points3.user_story + m.issue11 = f.IssueFactory(project=m.project1, description="Back to the future") + m.issue12 = f.IssueFactory(project=m.project1, tags=["back", "future"]) + m.issue13 = f.IssueFactory(project=m.project1) + m.issue14 = f.IssueFactory(project=m.project1, subject="Backend to the future") + m.issue21 = f.IssueFactory(project=m.project2, subject="Back to the future") - m.tsk1 = f.TaskFactory.create(project=m.project2) - m.tsk2 = f.TaskFactory.create(project=m.project1) - m.tsk3 = f.TaskFactory.create(project=m.project1, subject="Back to the future") - - m.iss1 = f.IssueFactory.create(project=m.project1, subject="Backend and Frontend") - m.iss2 = f.IssueFactory.create(project=m.project2) - m.iss3 = f.IssueFactory.create(project=m.project1) - - m.wiki1 = f.WikiPageFactory.create(project=m.project1) - m.wiki2 = f.WikiPageFactory.create(project=m.project1, content="Frontend, future") - m.wiki3 = f.WikiPageFactory.create(project=m.project2) + m.wikipage11 = f.WikiPageFactory(project=m.project1) + m.wikipage12 = f.WikiPageFactory(project=m.project1) + m.wikipage13 = f.WikiPageFactory(project=m.project1, content="Backend to the black") + m.wikipage14 = f.WikiPageFactory(project=m.project1, slug="Back to the black") + m.wikipage21 = f.WikiPageFactory(project=m.project2, slug="Backend to the orange") return m @@ -94,11 +87,11 @@ def test_search_all_objects_in_my_project(client, searches_initial_data): response = client.get(reverse("search-list"), {"project": data.project1.id}) assert response.status_code == 200 - assert response.data["count"] == 8 - assert len(response.data["userstories"]) == 2 - assert len(response.data["tasks"]) == 2 - assert len(response.data["issues"]) == 2 - assert len(response.data["wikipages"]) == 2 + assert response.data["count"] == 16 + assert len(response.data["userstories"]) == 4 + assert len(response.data["tasks"]) == 4 + assert len(response.data["issues"]) == 4 + assert len(response.data["wikipages"]) == 4 def test_search_all_objects_in_project_is_not_mine(client, searches_initial_data): @@ -118,20 +111,20 @@ def test_search_text_query_in_my_project(client, searches_initial_data): response = client.get(reverse("search-list"), {"project": data.project1.id, "text": "future"}) assert response.status_code == 200 - assert response.data["count"] == 3 - assert len(response.data["userstories"]) == 1 - assert len(response.data["tasks"]) == 1 - assert len(response.data["issues"]) == 0 - assert len(response.data["wikipages"]) == 1 + assert response.data["count"] == 9 + assert len(response.data["userstories"]) == 3 + assert len(response.data["tasks"]) == 3 + assert len(response.data["issues"]) == 3 + assert len(response.data["wikipages"]) == 0 response = client.get(reverse("search-list"), {"project": data.project1.id, "text": "back"}) assert response.status_code == 200 - assert response.data["count"] == 3 - assert len(response.data["userstories"]) == 1 - assert len(response.data["tasks"]) == 1 + assert response.data["count"] == 11 + assert len(response.data["userstories"]) == 3 + assert len(response.data["tasks"]) == 3 + assert len(response.data["issues"]) == 3 # Back is a backend substring - assert len(response.data["issues"]) == 1 - assert len(response.data["wikipages"]) == 0 + assert len(response.data["wikipages"]) == 2 def test_search_text_query_with_an_invalid_project_id(client, searches_initial_data):