def test_status_history(self): self.barrier.status = 5 self.barrier.status_summary = "Summary" self.barrier.sub_status = "UK_GOVT" self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "status" assert data["old_value"] == { "status": "1", "status_date": datetime.date(2019, 4, 9), "status_summary": "", "sub_status": "", "sub_status_other": "", } assert data["new_value"] == { "status": "5", "status_date": datetime.date(2019, 4, 9), "status_summary": "Summary", "sub_status": "UK_GOVT", "sub_status_other": "", }
def test_categories_history(self): self.barrier.categories.add("109", "115") items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "categories" assert data["old_value"] == [] assert set(data["new_value"]) == {109, 115}
def test_companies_history(self): self.barrier.companies = ["1", "2", "3"] self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "companies" assert data["old_value"] == [] assert data["new_value"] == ["1", "2", "3"]
def test_commercial_value_explanation_history(self): self.barrier.commercial_value_explanation = "wobble" self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "commercial_value_explanation" assert data["old_value"] == "" assert data["new_value"] == "wobble"
def test_commercial_value_history(self): self.barrier.commercial_value = 1111 self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "commercial_value" assert data["old_value"] is None assert data["new_value"] == 1111
def test_title_history(self): self.barrier.title = "New title" self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "title" assert data["old_value"] == "Some title" assert data["new_value"] == "New title"
def test_scope_history(self): self.barrier.term = 1 self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "term" assert data["old_value"] == 2 assert data["new_value"] == 1
def test_product_history(self): self.barrier.product = "New product" self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "product" assert data["old_value"] == "Some product" assert data["new_value"] == "New product"
def test_description_history(self): self.barrier.summary = "New summary" self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "summary" assert data["old_value"] == "Some summary" assert data["new_value"] == "New summary"
def test_organisations_history(self): org1 = OrganisationFactory() self.barrier.organisations.add(org1) self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "organisations" assert data["old_value"] == [] assert set(data["new_value"]) == {org1.id}
def test_sectors_history(self): self.barrier.sectors = ["9538cecc-5f95-e211-a939-e4115bead28a"] self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "sectors" assert data["old_value"]["sectors"] == [ "af959812-6095-e211-a939-e4115bead28a", "9538cecc-5f95-e211-a939-e4115bead28a", ] assert data["new_value"]["sectors"] == ["9538cecc-5f95-e211-a939-e4115bead28a"]
def test_location_history(self): self.barrier.country = "81756b9a-5d95-e211-a939-e4115bead28a" # USA self.barrier.admin_areas = [ "a88512e0-62d4-4808-95dc-d3beab05d0e9" ] # California self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "location" assert data["old_value"] == "France" assert data["new_value"] == "California (United States)"
def test_source_history(self): self.barrier.source = "COMPANY" self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "source" assert data["old_value"] == { "source": "OTHER", "other_source": "Other source", } assert data["new_value"] == { "source": "COMPANY", "other_source": "", }
def test_priority_history(self): self.barrier.priority_id = 2 self.barrier.save() items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "priority" assert data["old_value"] == { "priority": "UNKNOWN", "priority_summary": "", } assert data["new_value"] == { "priority": "HIGH", "priority_summary": "", }
def test_modified_on_set_to_value_of_last_history_item_date(self): self.barrier.companies = ["1", "2", "3"] self.barrier.save() # set the modified_on date of the barrier far in the future far_future_date = datetime.datetime.now( tz=datetime.timezone.utc) + datetime.timedelta(days=365000) Barrier.objects.filter(pk=self.barrier.pk).update( modified_on=far_future_date) # the following isn't necessary, but makes it possible to inspect the new date when debugging self.barrier.refresh_from_db() items = BarrierHistoryFactory.get_history_items( barrier_id=self.barrier.pk) most_recent_history_item = items[-1].data management.call_command("ugly_hack_fixing_modified_on_field") self.barrier.refresh_from_db() assert self.barrier.modified_on == most_recent_history_item["date"]
def test_archived_history(self): self.barrier.archive( user=self.user, reason="DUPLICATE", explanation="It was a duplicate" ) items = BarrierHistoryFactory.get_history_items(barrier_id=self.barrier.pk) data = items[-1].data assert data["model"] == "barrier" assert data["field"] == "archived" assert data["old_value"] == { "archived": False, "unarchived_reason": "", } assert data["new_value"] == { "archived": True, "archived_reason": "DUPLICATE", "archived_explanation": "It was a duplicate", }