def validate_unique_candidates():
    msg = "%s candidates expected for election {} and contest {}, but {} found"
    for contest in Contest.objects.all():
        election_id = contest.election_id
        candidates = Candidate.objects.filter(election_id=election_id,
            contest_slug=contest.slug)
        expected = len(candidates.distinct('slug'))
        count = candidates.count()
        assert count == expected, msg.format(expected, election_id,
            contest.slug, count) 
    print "PASS: unique candidates found for all elections"
Should have a unique set of candidates for all contests
dataset/ETHPy150Open openelections/openelections-core/openelex/us/md/validate/__init__.py/validate_unique_candidates