def test_filter_barrier_tags__multiple_tags(self): tag1 = BarrierTagFactory() tag2 = BarrierTagFactory() barrier1 = BarrierFactory(tags=(tag1, )) barrier2 = BarrierFactory(tags=(tag2, )) BarrierFactory() url = f'{reverse("list-barriers")}?tags={tag1.id},{tag2.id}' response = self.api_client.get(url) assert status.HTTP_200_OK == response.status_code assert 2 == response.data["count"] barrier_ids = [b["id"] for b in response.data["results"]] assert {str(barrier1.id), str(barrier2.id)} == set(barrier_ids)
def test_data_warehouse_is_not_top_priority_barrier(self): tag_title = "Very Important Thing" tag = BarrierTagFactory(title=tag_title, is_top_priority_tag=False) barrier = BarrierFactory(tags=(tag, ), status_date=date.today()) serialised_data = DataWorkspaceSerializer(barrier).data assert ("is_top_priority" in serialised_data.keys() and serialised_data["is_top_priority"] is False)
def test_is_top_priority_barrier(self): tag_title = "Very Important Thing" tag = BarrierTagFactory(title=tag_title, is_top_priority_tag=True) barrier = BarrierFactory(tags=(tag, ), status_date=datetime.date.today()) serialised_data = BarrierCsvExportSerializer(barrier).data assert ("is_top_priority" in serialised_data.keys() and serialised_data["is_top_priority"] is True)
def test_is_not_top_priority_barrier(self): tag_title = "Very Important Thing" tag = BarrierTagFactory(title=tag_title, is_top_priority_tag=False) BarrierFactory(tags=(tag, )) response = self.api_client.get(self.url) assert status.HTTP_200_OK == response.status_code serialised_data = response.data assert ("is_top_priority" in serialised_data["results"][0].keys() and serialised_data["results"][0]["is_top_priority"] is False)
def test_tag_ordering(self): new_tag = BarrierTagFactory() tag_count = BarrierTag.objects.count() assert tag_count == new_tag.order tags = BarrierTag.objects.all() assert 1 == tags[0].order assert 2 == tags[1].order assert 3 == tags[2].order
def test_get_report_with_tags(self): tag_title = "wobble" tag = BarrierTagFactory(title=tag_title) self.report.tags.add(tag) response = self.api_client.get(self.url) assert status.HTTP_200_OK == response.status_code assert 1 == len(response.data["tags"]) assert tag_title == response.data["tags"][0]["title"]
def test_is_not_top_priority_barrier(self): tag_title = "Very Important Thing" tag = BarrierTagFactory(title=tag_title, is_top_priority_tag=False) barrier = BarrierFactory(tags=(tag, )) url = reverse("get-barrier", kwargs={"pk": barrier.id}) response = self.api_client.get(url) assert status.HTTP_200_OK == response.status_code serialised_data = response.data assert ("is_top_priority" in serialised_data.keys() and serialised_data["is_top_priority"] is False)
def test_patch_report_swapping_tags(self): # existing tag tag01_title = "wobble" tag01 = BarrierTagFactory(title=tag01_title) self.report.tags.add(tag01) # the tag we want to switch to tag02_title = "wibble" tag02 = BarrierTagFactory(title=tag02_title) assert (1 == self.report.tags.count() ), f"Expected only 1 tag, got {self.report.tags.count()}" assert tag01.id == self.report.tags.first().id payload = {"tags": [tag02.id]} response = self.api_client.patch(self.url, format="json", data=payload) assert status.HTTP_200_OK == response.status_code assert (1 == self.report.tags.count() ), f"Expected only 1 tag, got {self.report.tags.count()}" assert tag02.id == self.report.tags.first().id
def test_filter_barrier_tags__no_match(self): tag1 = BarrierTagFactory() BarrierFactory(tags=(tag1, )) BarrierFactory() url = f'{reverse("list-barriers")}?tags=123,321' response = self.api_client.get(url) assert status.HTTP_200_OK == response.status_code assert 0 == response.data["count"]
def test_get_barrier_with_tags(self): tag_title = "wobble" tag = BarrierTagFactory(title=tag_title) barrier = BarrierFactory(tags=(tag, )) url = reverse("get-barrier", kwargs={"pk": barrier.id}) response = self.api_client.get(url) assert status.HTTP_200_OK == response.status_code assert 1 == len(response.data["tags"]) assert tag_title == response.data["tags"][0]["title"]
def test_patch_report_extending_tags(self): # existing tag tag01_title = "wobble" tag01 = BarrierTagFactory(title=tag01_title) self.report.tags.add(tag01) # tag to be added tag02_title = "wibble" tag02 = BarrierTagFactory(title=tag02_title) assert (1 == self.report.tags.count() ), f"Expected only 1 tag, got {self.report.tags.count()}" assert tag01.id == self.report.tags.first().id payload = {"tags": (tag01.id, tag02.id)} response = self.api_client.patch(self.url, format="json", data=payload) assert status.HTTP_200_OK == response.status_code assert (2 == self.report.tags.count() ), f"Expected only 2 tags, got {self.report.tags.count()}" tag_ids = list(self.report.tags.values_list("id", flat=True)) assert {tag01.id, tag02.id} == set(tag_ids)
def test_filter_barrier_tags__single_tag(self): tag = BarrierTagFactory() barrier = BarrierFactory(tags=(tag, )) BarrierFactory() url = f'{reverse("list-barriers")}?tags={tag.id}' response = self.api_client.get(url) assert status.HTTP_200_OK == response.status_code assert 1 == response.data["count"] assert str(barrier.id) == response.data["results"][0]["id"]
def test_patch_barrier_swapping_tags(self): # existing tag tag01_title = "wobble" tag01 = BarrierTagFactory(title=tag01_title) barrier = BarrierFactory(tags=(tag01, )) # the tag we want to switch to tag02_title = "wibble" tag02 = BarrierTagFactory(title=tag02_title) url = reverse("get-barrier", kwargs={"pk": barrier.id}) assert (1 == barrier.tags.count() ), f"Expected only 1 tag, got {barrier.tags.count()}" assert tag01.id == barrier.tags.first().id payload = {"tags": [tag02.id]} response = self.api_client.patch(url, format="json", data=payload) assert status.HTTP_200_OK == response.status_code assert (1 == barrier.tags.count() ), f"Expected only 1 tag, got {barrier.tags.count()}" assert tag02.id == barrier.tags.first().id
def test_patch_report_remove_all_tags(self): # existing tags tags = BarrierTagFactory.create_batch(2) self.report.tags.add(*tags) assert (2 == self.report.tags.count() ), f"Expected only 2 tags, got {self.report.tags.count()}" payload = {"tags": []} response = self.api_client.patch(self.url, format="json", data=payload) assert status.HTTP_200_OK == response.status_code tags_count = self.report.tags.count() assert 0 == tags_count, f"Expected 0 tags, got {tags_count}."
def test_patch_barrier_extending_tags(self): # existing tag tag01_title = "wobble" tag01 = BarrierTagFactory(title=tag01_title) barrier = BarrierFactory(tags=(tag01, )) # tag to be added tag02_title = "wibble" tag02 = BarrierTagFactory(title=tag02_title) url = reverse("get-barrier", kwargs={"pk": barrier.id}) assert (1 == barrier.tags.count() ), f"Expected only 1 tag, got {barrier.tags.count()}" assert tag01.id == barrier.tags.first().id payload = {"tags": (tag01.id, tag02.id)} response = self.api_client.patch(url, format="json", data=payload) assert status.HTTP_200_OK == response.status_code assert (2 == barrier.tags.count() ), f"Expected only 2 tags, got {barrier.tags.count()}" tag_ids = list(barrier.tags.values_list("id", flat=True)) assert {tag01.id, tag02.id} == set(tag_ids)
def test_patch_report_with_valid_tags(self): tag_title = "wobble" tag = BarrierTagFactory(title=tag_title) assert not self.report.tags.exists(), "Expected no tags to start with." payload = {"tags": [tag.id]} response = self.api_client.patch(self.url, format="json", data=payload) assert status.HTTP_200_OK == response.status_code self.report.refresh_from_db() assert 1 == self.report.tags.count() assert tag.id == self.report.tags.first().id
def test_patch_barrier_remove_all_tags(self): # existing tags tags = BarrierTagFactory.create_batch(2) barrier = BarrierFactory(tags=tags) url = reverse("get-barrier", kwargs={"pk": barrier.id}) assert (2 == barrier.tags.count() ), f"Expected only 2 tags, got {barrier.tags.count()}" payload = {"tags": []} response = self.api_client.patch(url, format="json", data=payload) assert status.HTTP_200_OK == response.status_code tags_count = barrier.tags.count() assert 0 == tags_count, f"Expected 0 tags, got {tags_count}."
def test_patch_barrier_with_valid_tags(self): barrier = BarrierFactory() tag_title = "wobble" tag = BarrierTagFactory(title=tag_title) assert not barrier.tags.exists(), "Expected no tags to start with." url = reverse("get-barrier", kwargs={"pk": barrier.id}) payload = {"tags": [tag.id]} response = self.api_client.patch(url, format="json", data=payload) assert status.HTTP_200_OK == response.status_code barrier.refresh_from_db() assert 1 == barrier.tags.count() assert tag.id == barrier.tags.first().id
def create_data_records( self, test_user: models.Model) -> Dict[str, models.Model]: rand_str: str = str(uuid.uuid4())[:20] data_row: Dict[str, models.Model] = {} data_row["Barrier"] = Barrier.objects.create( created_by=test_user, modified_by=test_user, archived_by=test_user, unarchived_by=test_user, ) stage = Stage.objects.create( code="test", description="this is a test") # Need for fixture data_row["BarrierReportStage"] = BarrierReportStage.objects.create( created_by=test_user, modified_by=test_user, barrier=data_row["Barrier"], stage=stage, ) data_row["BarrierTag"] = BarrierTagFactory(created_by=test_user, modified_by=test_user, title=rand_str) data_row["Document"] = Document.objects.create( created_by=test_user, modified_by=test_user, archived_by=test_user, path=rand_str, ) data_row["EconomicAssessment"] = EconomicAssessment.objects.create( created_by=test_user, modified_by=test_user, archived_by=test_user, reviewed_by=test_user, barrier=data_row["Barrier"], ) data_row[ "EconomicImpactAssessment"] = EconomicImpactAssessment.objects.create( created_by=test_user, modified_by=test_user, archived_by=test_user, economic_assessment=data_row["EconomicAssessment"], barrier=data_row["Barrier"], impact=4, ) data_row[ "ExcludeFromNotification"] = ExcludeFromNotification.objects.create( created_by=test_user, modified_by=test_user, excluded_user=test_user, ) data_row["Interaction"] = Interaction.objects.create( created_by=test_user, modified_by=test_user, barrier=data_row["Barrier"], archived_by=test_user, ) data_row["Mention"] = Mention.objects.create( created_by=test_user, modified_by=test_user, recipient=test_user, barrier=data_row["Barrier"], ) data_row["PublicBarrier"] = PublicBarrier.objects.get( barrier=data_row["Barrier"]) data_row["PublicBarrier"].created_by = test_user data_row["PublicBarrier"].modified_by = test_user data_row["PublicBarrier"].archived_by = test_user data_row["PublicBarrier"].unarchived_by = test_user data_row["PublicBarrier"].save() data_row["PublicBarrierNote"] = PublicBarrierNote.objects.create( created_by=test_user, modified_by=test_user, archived_by=test_user, public_barrier=data_row["PublicBarrier"], ) data_row[ "ResolvabilityAssessment"] = ResolvabilityAssessment.objects.create( created_by=test_user, modified_by=test_user, reviewed_by=test_user, barrier=data_row["Barrier"], time_to_resolve=2, effort_to_resolve=2, ) data_row["StrategicAssessment"] = StrategicAssessment.objects.create( created_by=test_user, modified_by=test_user, archived_by=test_user, reviewed_by=test_user, barrier=data_row["Barrier"], scale=2, ) data_row["TeamMember"] = TeamMember.objects.create( created_by=test_user, modified_by=test_user, archived_by=test_user, user=test_user, barrier=data_row["Barrier"], ) data_row["BarrierUserHit"] = BarrierUserHit.objects.create( user=test_user, barrier=data_row["Barrier"], ) data_row[ "MyBarriersSavedSearch"] = MyBarriersSavedSearch.objects.create( user=test_user, ) data_row["SavedSearch"] = SavedSearch.objects.create(user=test_user, filters={}) data_row[ "TeamBarriersSavedSearch"] = TeamBarriersSavedSearch.objects.create( user=test_user, ) data_row["UserEvent"] = UserEvent.objects.create(user=test_user, ) return data_row