def test_agglomerate_merges_two_nearest_clusters(scotland, england, goat): # Given we have 3 singleton clusters at the start assert Cluster.objects.all().count() == 3 Cluster.agglomerate() # Django will have cached these, so refresh to see latest memberships scotland.refresh_from_db() england.refresh_from_db() goat.refresh_from_db() # we should have lost a cluster assert Cluster.objects.all().count() == 2 # Check the goat is still in its own singleton cluster assert goat.cluster.item_set.count() == 1 # England and Scotland should have been merged assert scotland.cluster == england.cluster