Ejemplo n.º 1
0
    def test_edit_fields(self):
        bot = CandidateBot(self.person.pk)

        edit = {"email": "*****@*****.**"}

        self.assertFalse(LoggedAction.objects.all().exists())
        self.assertEqual(self.person.versions, "[]")
        person = bot.edit_fields(edit, "a source", save=True)
        expected = {
            "biography": "",
            "birth_date": "",
            "blog_url": "",
            "death_date": "",
            "email": "*****@*****.**",
            "extra_fields": {
                "favourite_biscuits": ""
            },
            "facebook_page_url": "",
            "facebook_personal_url": "",
            "gender": "",
            "homepage_url": "",
            "honorific_prefix": "",
            "honorific_suffix": "",
            "id": "2009",
            "instagram_url": "",
            "linkedin_url": "",
            "name": "Tessa Jowell",
            "other_names": [],
            "party_ppc_page_url": "",
            "candidacies": {},
            "twitter_username": "",
            "wikidata_id": "",
            "wikipedia_url": "",
            "youtube_profile": "",
        }
        got = json.loads(person.versions)
        self.assertEqual(got[0]["data"], expected)
        self.assertEqual(got[0]["information_source"], "a source")
        self.assertEqual(got[0]["username"], settings.CANDIDATE_BOT_USERNAME)
        la = LoggedAction.objects.first()
        self.assertEqual(la.user.username, settings.CANDIDATE_BOT_USERNAME)
    def test_edit_fields(self):
        bot = CandidateBot(self.person_extra.base.pk)

        edit = {
            'email': '*****@*****.**'
        }

        self.assertFalse(LoggedAction.objects.all().exists())
        self.assertEqual(self.person_extra.versions, '[]')
        person = bot.edit_fields(edit, 'a source', save=True)
        expected = {
            "twitter_username": "",
            "standing_in": {},
            "name": "Tessa Jowell",
            "honorific_suffix": "",
            "facebook_page_url": "",
            "gender": "",
            "image": None,
            "facebook_personal_url": "",
            "id": "2009",
            "honorific_prefix": "",
            "linkedin_url": "",
            "homepage_url": "",
            "extra_fields": {"favourite_biscuits": ""},
            "wikipedia_url": "",
            "party_memberships": {},
            "birth_date": "",
            "party_ppc_page_url": "",
            "other_names": [],
            "email": "*****@*****.**",
            "biography": ""
        }
        got = json.loads(person.extra.versions)
        self.assertEqual(got[0]['data'], expected)
        self.assertEqual(got[0]['information_source'], "a source")
        self.assertEqual(got[0]['username'], settings.CANDIDATE_BOT_USERNAME)
        la = LoggedAction.objects.first()
        self.assertEqual(la.user.username, settings.CANDIDATE_BOT_USERNAME)