def setUpClass(cls):
     super(PhotoReviewTests, cls).setUpClass()
     storage = FileSystemStorage()
     desired_storage_path = join('queued-images', 'pilot.jpg')
     with open(cls.example_image_filename, 'rb') as f:
         cls.storage_filename = storage.save(desired_storage_path, f)
     mkdir_p(TEST_MEDIA_ROOT)
 def setUpClass(cls):
     super(PhotoUploadImageTests, cls).setUpClass()
     storage = FileSystemStorage()
     desired_storage_path = join("queued-images", "pilot.jpg")
     with open(cls.example_image_filename, "rb") as f:
         cls.storage_filename = storage.save(desired_storage_path, f)
     mkdir_p(TEST_MEDIA_ROOT)
Exemple #3
0
 def handle(self, *args, **options):
     self.client = Client()
     self.directory_url = options['DIRECTORY-URL']
     if not self.directory_url.endswith('/'):
         self.directory_url = self.directory_url + '/'
     self.hostname, self.secure = hostname_and_secure(self.directory_url)
     mkdir_p(options['OUTPUT-DIRECTORY'])
     self.timestamp = datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
     json_directory = join(options['OUTPUT-DIRECTORY'], self.timestamp)
     mkdir_p(json_directory)
     page_size = options['page_size']
     if not page_size:
         page_size = 200
     for endpoint in self.endpoints:
         self.get_api_results_to_directory(endpoint, json_directory, page_size)
     update_latest_symlink(options['OUTPUT-DIRECTORY'], self.timestamp)
     if options['prune']:
         prune(options['OUTPUT-DIRECTORY'])
 def setUp(self):
     super().setUp()
     mkdir_p(TEST_MEDIA_ROOT)
     # Create Tessa Jowell (the primary person)
     person = people.tests.factories.PersonFactory.create(
         id=2009,
         name="Tessa Jowell",
         gender="female",
         honorific_suffix="DBE",
         email="*****@*****.**",
         versions="""
             [
               {
                 "username": "******",
                 "information_source": "Just adding example data",
                 "ip": "127.0.0.1",
                 "version_id": "35ec2d5821176ccc",
                 "timestamp": "2014-10-28T14:32:36.835429",
                 "data": {
                   "name": "Tessa Jowell",
                   "id": "2009",
                   "honorific_suffix": "DBE",
                   "twitter_username": "",
                   "standing_in": {
                     "2010": {
                       "post_id": "65808",
                       "name": "Dulwich and West Norwood",
                       "mapit_url": "http://mapit.mysociety.org/area/65808"
                     },
                     "2015": {
                       "post_id": "65808",
                       "name": "Dulwich and West Norwood",
                       "mapit_url": "http://mapit.mysociety.org/area/65808"
                     }
                   },
                   "gender": "female",
                   "homepage_url": "",
                   "birth_date": null,
                   "wikipedia_url": "https://en.wikipedia.org/wiki/Tessa_Jowell",
                   "party_memberships": {
                     "2010": {
                       "id": "party:53",
                       "name": "Labour Party"
                     },
                     "2015": {
                       "id": "party:53",
                       "name": "Labour Party"
                     }
                   },
                   "email": "*****@*****.**"
                 }
               },
               {
                 "username": "******",
                 "information_source": "An initial version",
                 "ip": "127.0.0.1",
                 "version_id": "5469de7db0cbd155",
                 "timestamp": "2014-10-01T15:12:34.732426",
                 "data": {
                   "name": "Tessa Jowell",
                   "id": "2009",
                   "twitter_username": "",
                   "standing_in": {
                     "2010": {
                       "post_id": "65808",
                       "name": "Dulwich and West Norwood",
                       "mapit_url": "http://mapit.mysociety.org/area/65808"
                     }
                   },
                   "homepage_url": "http://example.org/tessajowell",
                   "birth_date": "1947-09-17",
                   "wikipedia_url": "",
                   "party_memberships": {
                     "2010": {
                       "id": "party:53",
                       "name": "Labour Party"
                     }
                   },
                   "email": "*****@*****.**"
                 }
               }
             ]
         """,
     )
     PersonImage.objects.create_from_file(
         EXAMPLE_IMAGE_FILENAME,
         "images/jowell-pilot.jpg",
         defaults={
             "person": person,
             "is_primary": True,
             "source": "Taken from Wikipedia",
             "copyright": "example-license",
             "uploading_user": self.user,
             "user_notes": "A photo of Tessa Jowell",
         },
     )
     factories.MembershipFactory.create(
         person=person,
         post=self.dulwich_post,
         party=self.labour_party,
         post_election=self.dulwich_post_pee,
     )
     factories.MembershipFactory.create(
         person=person,
         post=self.dulwich_post,
         party=self.labour_party,
         post_election=self.dulwich_post_pee_earlier,
     )
     # Now create Shane Collins (who we'll merge into Tessa Jowell)
     person = people.tests.factories.PersonFactory.create(
         id=2007,
         name="Shane Collins",
         gender="male",
         honorific_prefix="Mr",
         email="*****@*****.**",
         versions="""
             [
               {
                 "data": {
                   "birth_date": null,
                   "email": "*****@*****.**",
                   "facebook_page_url": "",
                   "facebook_personal_url": "",
                   "gender": "male",
                   "homepage_url": "",
                   "honorific_prefix": "Mr",
                   "honorific_suffix": "",
                   "id": "2007",
                   "identifiers": [
                     {
                       "id": "547786cc737edc5252ce5af1",
                       "identifier": "2961",
                       "scheme": "yournextmp-candidate"
                     }
                   ],
                   "image": null,
                   "linkedin_url": "",
                   "name": "Shane Collins",
                   "other_names": [],
                   "party_memberships": {
                     "2010": {
                       "id": "party:63",
                       "name": "Green Party"
                     }
                   },
                   "party_ppc_page_url": "",
                   "proxy_image": null,
                   "standing_in": {
                     "2010": {
                       "mapit_url": "http://mapit.mysociety.org/area/65808",
                       "name": "Dulwich and West Norwood",
                       "post_id": "65808"
                     },
                     "2015": null
                   },
                   "twitter_username": "",
                   "wikipedia_url": ""
                 },
                 "information_source": "http://www.lambeth.gov.uk/sites/default/files/ec-dulwich-and-west-norwood-candidates-and-notice-of-poll-2015.pdf",
                 "timestamp": "2015-04-09T20:32:09.237610",
                 "username": "******",
                 "version_id": "274e50504df330e4"
               },
               {
                 "data": {
                   "birth_date": null,
                   "email": "*****@*****.**",
                   "facebook_page_url": null,
                   "facebook_personal_url": null,
                   "gender": "male",
                   "homepage_url": null,
                   "id": "2007",
                   "identifiers": [
                     {
                       "identifier": "2961",
                       "scheme": "yournextmp-candidate"
                     }
                   ],
                   "name": "Shane Collins",
                   "party_memberships": {
                     "2010": {
                       "id": "party:63",
                       "name": "Green Party"
                     }
                   },
                   "party_ppc_page_url": null,
                   "phone": "07939 196612",
                   "slug": "shane-collins",
                   "standing_in": {
                     "2010": {
                       "mapit_url": "http://mapit.mysociety.org/area/65808",
                       "name": "Dulwich and West Norwood",
                       "post_id": "65808"
                     }
                   },
                   "twitter_username": null,
                   "wikipedia_url": null
                 },
                 "information_source": "Imported from YourNextMP data from 2010",
                 "timestamp": "2014-11-21T18:16:47.670167",
                 "version_id": "68a452284d95d9ab"
               }
             ]
         """,
     )
     PersonImage.objects.create_from_file(
         EXAMPLE_IMAGE_FILENAME,
         "images/collins-pilot.jpg",
         defaults={
             "person": person,
             "is_primary": True,
             "source": "Taken from Twitter",
             "copyright": "profile-photo",
             "uploading_user": self.user,
             "user_notes": "A photo of Shane Collins",
         },
     )
     factories.MembershipFactory.create(
         person=person,
         post=self.dulwich_post,
         party=self.green_party,
         post_election=self.dulwich_post_pee,
     )
     factories.MembershipFactory.create(
         person=person,
         post=self.dulwich_post,
         party=self.green_party,
         post_election=self.edinburgh_east_post_pee,
     )
    def setUp(self):
        super().setUp()
        mkdir_p(TEST_MEDIA_ROOT)
        # Create Tessa Jowell (the primary person)
        person = people.tests.factories.PersonFactory.create(
            id=2009,
            name="Tessa Jowell",
            gender="female",
            honorific_suffix="DBE",
            versions=EXAMPLE_VERSIONS,
        )
        person.tmp_person_identifiers.create(
            value="*****@*****.**", value_type="email"
        )
        PersonImage.objects.create_from_file(
            EXAMPLE_IMAGE_FILENAME,
            "images/jowell-pilot.jpg",
            defaults={
                "person": person,
                "is_primary": True,
                "source": "Taken from Wikipedia",
                "copyright": "example-license",
                "uploading_user": self.user,
                "user_notes": "A photo of Tessa Jowell",
            },
        )
        factories.MembershipFactory.create(
            person=person,
            post=self.local_post,
            party=self.labour_party,
            ballot=self.local_ballot,
        )
        factories.MembershipFactory.create(
            person=person,
            post=self.dulwich_post,
            party=self.labour_party,
            ballot=self.dulwich_post_ballot_earlier,
        )
        # Now create Shane Collins (who we'll merge into Tessa Jowell)
        person = people.tests.factories.PersonFactory.create(
            id=2007,
            name="Shane Collins",
            gender="male",
            honorific_prefix="Mr",
            versions="""
                [
                  {
                    "data": {
                      "birth_date": null,
                      "email": "*****@*****.**",
                      "facebook_page_url": "",
                      "facebook_personal_url": "",
                      "gender": "male",
                      "homepage_url": "",
                      "honorific_prefix": "Mr",
                      "honorific_suffix": "",
                      "id": "2007",
                      "identifiers": [],
                      "image": null,
                      "linkedin_url": "",
                      "name": "Shane Collins",
                      "other_names": [],
                      "party_ppc_page_url": "",
                      "proxy_image": null,
                      "candidacies": {
                        "parl.65808.2010-05-06": {
                          "party": "PP63"
                        }
                      },
                      "not_standing": ["parl.2015"],
                      "twitter_username": "",
                      "wikipedia_url": ""
                    },
                    "information_source": "http://www.lambeth.gov.uk/sites/default/files/ec-dulwich-and-west-norwood-candidates-and-notice-of-poll-2015.pdf",
                    "timestamp": "2015-04-09T20:32:09.237610",
                    "username": "******",
                    "version_id": "274e50504df330e4"
                  },
                  {
                    "data": {
                      "birth_date": null,
                      "email": "*****@*****.**",
                      "facebook_page_url": null,
                      "facebook_personal_url": null,
                      "gender": "male",
                      "homepage_url": null,
                      "id": "2007",
                      "identifiers": [],
                      "name": "Shane Collins",
                      "party_ppc_page_url": null,
                      "phone": "07939 196612",
                      "slug": "shane-collins",
                      "candidacies": {
                        "parl.65808.2010-05-06": {
                          "party": "PP63"
                        }
                      },
                      "twitter_username": null,
                      "wikipedia_url": null
                    },
                    "information_source": "Imported from YourNextMP data from 2010",
                    "timestamp": "2014-11-21T18:16:47.670167",
                    "username": "******",
                    "version_id": "68a452284d95d9ab"
                  }
                ]
            """,
        )
        person.tmp_person_identifiers.create(
            value="*****@*****.**", value_type="email"
        )

        PersonImage.objects.create_from_file(
            EXAMPLE_IMAGE_FILENAME,
            "images/collins-pilot.jpg",
            defaults={
                "person": person,
                "is_primary": True,
                "source": "Taken from Twitter",
                "copyright": "profile-photo",
                "uploading_user": self.user,
                "user_notes": "A photo of Shane Collins",
            },
        )
        factories.MembershipFactory.create(
            person=person,
            post=self.dulwich_post,
            party=self.green_party,
            ballot=self.dulwich_post_ballot_earlier,
        )
        factories.MembershipFactory.create(
            person=person,
            post=self.dulwich_post,
            party=self.green_party,
            ballot=self.edinburgh_east_post_ballot,
        )
Exemple #6
0
 def setUp(self):
     super(TestMergePeopleView, self).setUp()
     mkdir_p(TEST_MEDIA_ROOT)
     # Create Tessa Jowell (the primary person)
     person_extra = factories.PersonExtraFactory.create(
         base__id=2009,
         base__name='Tessa Jowell',
         base__gender='female',
         base__honorific_suffix='DBE',
         base__email='*****@*****.**',
         versions='''
             [
               {
                 "username": "******",
                 "information_source": "Just adding example data",
                 "ip": "127.0.0.1",
                 "version_id": "35ec2d5821176ccc",
                 "timestamp": "2014-10-28T14:32:36.835429",
                 "data": {
                   "name": "Tessa Jowell",
                   "id": "2009",
                   "honorific_suffix": "DBE",
                   "twitter_username": "",
                   "standing_in": {
                     "2010": {
                       "post_id": "65808",
                       "name": "Dulwich and West Norwood",
                       "mapit_url": "http://mapit.mysociety.org/area/65808"
                     },
                     "2015": {
                       "post_id": "65808",
                       "name": "Dulwich and West Norwood",
                       "mapit_url": "http://mapit.mysociety.org/area/65808"
                     }
                   },
                   "gender": "female",
                   "homepage_url": "",
                   "birth_date": null,
                   "wikipedia_url": "https://en.wikipedia.org/wiki/Tessa_Jowell",
                   "party_memberships": {
                     "2010": {
                       "id": "party:53",
                       "name": "Labour Party"
                     },
                     "2015": {
                       "id": "party:53",
                       "name": "Labour Party"
                     }
                   },
                   "email": "*****@*****.**"
                 }
               },
               {
                 "username": "******",
                 "information_source": "An initial version",
                 "ip": "127.0.0.1",
                 "version_id": "5469de7db0cbd155",
                 "timestamp": "2014-10-01T15:12:34.732426",
                 "data": {
                   "name": "Tessa Jowell",
                   "id": "2009",
                   "twitter_username": "",
                   "standing_in": {
                     "2010": {
                       "post_id": "65808",
                       "name": "Dulwich and West Norwood",
                       "mapit_url": "http://mapit.mysociety.org/area/65808"
                     }
                   },
                   "homepage_url": "http://example.org/tessajowell",
                   "birth_date": "1947-09-17",
                   "wikipedia_url": "",
                   "party_memberships": {
                     "2010": {
                       "id": "party:53",
                       "name": "Labour Party"
                     }
                   },
                   "email": "*****@*****.**"
                 }
               }
             ]
         ''',
     )
     ImageExtra.objects.create_from_file(
         EXAMPLE_IMAGE_FILENAME,
         'images/jowell-pilot.jpg',
         base_kwargs={
             'content_object': person_extra,
             'is_primary': True,
             'source': 'Taken from Wikipedia',
         },
         extra_kwargs={
             'copyright': 'example-license',
             'uploading_user': self.user,
             'user_notes': 'A photo of Tessa Jowell',
         },
     )
     factories.CandidacyExtraFactory.create(
         election=self.election,
         base__person=person_extra.base,
         base__post=self.dulwich_post_extra.base,
         base__on_behalf_of=self.labour_party_extra.base,
         post_election=self.dulwich_post_extra_pee,
     )
     factories.CandidacyExtraFactory.create(
         election=self.earlier_election,
         base__person=person_extra.base,
         base__post=self.dulwich_post_extra.base,
         base__on_behalf_of=self.labour_party_extra.base,
         post_election=self.dulwich_post_extra_pee_earlier,
     )
     # Now create Shane Collins (who we'll merge into Tessa Jowell)
     person_extra = factories.PersonExtraFactory.create(
         base__id=2007,
         base__name='Shane Collins',
         base__gender='male',
         base__honorific_prefix='Mr',
         base__email='*****@*****.**',
         versions='''
             [
               {
                 "data": {
                   "birth_date": null,
                   "email": "*****@*****.**",
                   "facebook_page_url": "",
                   "facebook_personal_url": "",
                   "gender": "male",
                   "homepage_url": "",
                   "honorific_prefix": "Mr",
                   "honorific_suffix": "",
                   "id": "2007",
                   "identifiers": [
                     {
                       "id": "547786cc737edc5252ce5af1",
                       "identifier": "2961",
                       "scheme": "yournextmp-candidate"
                     }
                   ],
                   "image": null,
                   "linkedin_url": "",
                   "name": "Shane Collins",
                   "other_names": [],
                   "party_memberships": {
                     "2010": {
                       "id": "party:63",
                       "name": "Green Party"
                     }
                   },
                   "party_ppc_page_url": "",
                   "proxy_image": null,
                   "standing_in": {
                     "2010": {
                       "mapit_url": "http://mapit.mysociety.org/area/65808",
                       "name": "Dulwich and West Norwood",
                       "post_id": "65808"
                     },
                     "2015": null
                   },
                   "twitter_username": "",
                   "wikipedia_url": ""
                 },
                 "information_source": "http://www.lambeth.gov.uk/sites/default/files/ec-dulwich-and-west-norwood-candidates-and-notice-of-poll-2015.pdf",
                 "timestamp": "2015-04-09T20:32:09.237610",
                 "username": "******",
                 "version_id": "274e50504df330e4"
               },
               {
                 "data": {
                   "birth_date": null,
                   "email": "*****@*****.**",
                   "facebook_page_url": null,
                   "facebook_personal_url": null,
                   "gender": "male",
                   "homepage_url": null,
                   "id": "2007",
                   "identifiers": [
                     {
                       "identifier": "2961",
                       "scheme": "yournextmp-candidate"
                     }
                   ],
                   "name": "Shane Collins",
                   "party_memberships": {
                     "2010": {
                       "id": "party:63",
                       "name": "Green Party"
                     }
                   },
                   "party_ppc_page_url": null,
                   "phone": "07939 196612",
                   "slug": "shane-collins",
                   "standing_in": {
                     "2010": {
                       "mapit_url": "http://mapit.mysociety.org/area/65808",
                       "name": "Dulwich and West Norwood",
                       "post_id": "65808"
                     }
                   },
                   "twitter_username": null,
                   "wikipedia_url": null
                 },
                 "information_source": "Imported from YourNextMP data from 2010",
                 "timestamp": "2014-11-21T18:16:47.670167",
                 "version_id": "68a452284d95d9ab"
               }
             ]
         ''')
     ImageExtra.objects.create_from_file(
         EXAMPLE_IMAGE_FILENAME,
         'images/collins-pilot.jpg',
         base_kwargs={
             'content_object': person_extra,
             'is_primary': True,
             'source': 'Taken from Twitter',
         },
         extra_kwargs={
             'copyright': 'profile-photo',
             'uploading_user': self.user,
             'user_notes': 'A photo of Shane Collins',
         },
     )
     factories.CandidacyExtraFactory.create(
         election=self.election,
         base__person=person_extra.base,
         base__post=self.dulwich_post_extra.base,
         base__on_behalf_of=self.green_party_extra.base,
         post_election=self.dulwich_post_extra_pee,
     )
     factories.CandidacyExtraFactory.create(
         election=self.earlier_election,
         base__person=person_extra.base,
         base__post=self.dulwich_post_extra.base,
         base__on_behalf_of=self.green_party_extra.base,
         post_election=self.dulwich_post_extra_pee,
     )