def test_redirect_uniqueness_validation(self): # Validation should stop someone changing an organisation slug # to one that's redirecting via SlugRedirect. okind = models.OrganisationKind.objects.create( name="Example Organisations", slug="example-organisations", ) organisation_redirected_to = models.Organisation.objects.create( name='The Ministry of Silly Walks', slug='ms-walks', kind=okind, ) existing_redirect = SlugRedirect.objects.create( new_object=organisation_redirected_to, old_object_slug='msw', ) other_organisation = models.Organisation( name='Ministry of Sensible Walks', slug='msw', kind=okind, ) with self.assertRaises(ValidationError): other_organisation.clean_fields() existing_redirect.delete() organisation_redirected_to.delete() okind.delete()
def setUp(self): self.person = models.Person( legal_name='Test Person', slug='test-person', ) self.person.save() self.organisation_kind = models.OrganisationKind( name='Test OrgKind', slug='test-orgkind', ) self.organisation_kind.save() self.organisation = models.Organisation( name='Test Org', slug='test-org', kind=self.organisation_kind, ) self.organisation.save() self.title = models.PositionTitle.objects.create( name='Test PositionTitle', slug='test-positiontitle', ) SlugRedirect.objects.create( content_type=ContentType.objects.get_for_model( models.OrganisationKind), new_object=self.organisation_kind, old_object_slug='old-orgkind', ) SlugRedirect.objects.create( content_type=ContentType.objects.get_for_model( models.Organisation), new_object=self.organisation, old_object_slug='old-org', ) SlugRedirect.objects.create( content_type=ContentType.objects.get_for_model( models.PositionTitle), new_object=self.title, old_object_slug='old-positiontitle', ) self.election_list_kind = models.OrganisationKind.objects.create( name="Election List", slug="election-list", ) self.election_list_da = models.Organisation.objects.create( slug='da-election-list-2019', name="DA Election List", kind=self.election_list_kind, ) self.first_candidate = models.PositionTitle.objects.create( name="1st Candidate", slug="1st-candidate")
def setUp(self): self.person = models.Person( legal_name='Test Person', slug='test-person', ) self.person.save() self.organisation_kind = models.OrganisationKind( name='Test OrgKind', slug='test-orgkind', ) self.organisation_kind.save() self.organisation = models.Organisation( name='Test Org', slug='test-org', kind=self.organisation_kind, ) self.organisation.save() self.title = models.PositionTitle.objects.create( name='Test PositionTitle', slug='test-positiontitle', ) SlugRedirect.objects.create( content_type=ContentType.objects.get_for_model( models.OrganisationKind), new_object=self.organisation_kind, old_object_slug='old-orgkind', ) SlugRedirect.objects.create( content_type=ContentType.objects.get_for_model( models.Organisation), new_object=self.organisation, old_object_slug='old-org', ) SlugRedirect.objects.create( content_type=ContentType.objects.get_for_model( models.PositionTitle), new_object=self.title, old_object_slug='old-positiontitle', )
def setUp(self): self.organisation_kind = models.OrganisationKind( name='Foo', slug='foo', ) self.organisation_kind.save() self.organisation = models.Organisation( name='Test Org', slug='test-org', kind=self.organisation_kind, ) self.organisation.save() self.mysociety_id = models.Identifier.objects.create( identifier="/organisations/1", scheme="org.mysociety.za", object_id=self.organisation.id, content_type=ContentType.objects.get_for_model( models.Organisation))
def setUp(self): self.person = models.Person( legal_name='Test Person', slug='test-person', ) self.person.save() self.organisation_kind = models.OrganisationKind( name='Foo', slug='foo', ) self.organisation_kind.save() self.organisation = models.Organisation( name='Test Org', slug='test-org', kind=self.organisation_kind, ) self.organisation.save() self.title = models.PositionTitle.objects.create( name='Test title', slug='test-title', )
sys.path.append(os.path.abspath(os.path.dirname(__file__) + '../../..')) import simplejson from pprint import pprint from django.utils.text import slugify from django_date_extensions.fields import ApproximateDate from pombola.core import models party_kind = models.OrganisationKind.objects.get(slug="party") parties = simplejson.loads(sys.stdin.read()) for party in parties: pprint(party) try: org = models.Organisation.objects.get(slug=slugify(party['Acronym'])) except models.Organisation.DoesNotExist: org = models.Organisation(slug=slugify(party['Acronym'])) org.kind = party_kind org.original_id = party['PartyID'] org.name = party['Name'] if party.get('FoundationYear'): org.started = ApproximateDate(year=int(party['FoundationYear'])) org.save()