Esempio n. 1
0
    def test_google_user_logged_for_the_first_time_with_conflict(self, log_main_user_in):
        google_account_user = self.mock_google_account_user()
        main_user = mommy.save_one(MainUser, email='*****@*****.**')

        cmd = facade.login_google(google_account_user, Mock()).execute()
        self.assertFalse(cmd.result)
        self.assertIsNone(cmd.main_user_from_external)

        self.assertEqual(1, len(GoogleUser.query().fetch()))
        self.assertEqual(1, len(MainUser.query().fetch()))
        self.assertIsNotNone(cmd.pending_link)
        self.assertEqual(PendingExternalToMainUser.query().get(), cmd.pending_link)
        self.assertEqual(cmd.external_user.key, cmd.pending_link.external_user)
        self.assertEqual(main_user.key, cmd.pending_link.main_user)
        self.assertEqual('123', cmd.external_user.external_id)
        self.assertFalse(log_main_user_in.called)
Esempio n. 2
0
    def test_facebook_user_logged_for_the_first_time_with_conflict(self, log_main_user_in):
        main_user = mommy.save_one(MainUser, email='*****@*****.**')

        response = Mock()
        fetch_mock = self.setup_fetch_mock()
        cmd = facade.login_facebook('', response)

        cmd._fetch_facebook = fetch_mock
        cmd.execute()
        self.assertFalse(cmd.result)
        self.assertIsNone(cmd.main_user_from_external)

        self.assertEqual(1, len(FacebookUser.query().fetch()))
        self.assertEqual(1, len(MainUser.query().fetch()))
        self.assertIsNotNone(cmd.pending_link)
        self.assertEqual(PendingExternalToMainUser.query().get(), cmd.pending_link)
        self.assertEqual(cmd.external_user.key, cmd.pending_link.external_user)
        self.assertEqual(main_user.key, cmd.pending_link.main_user)
        self.assertEqual('123', cmd.external_user.external_id)
        self.assertFalse(log_main_user_in.called)
Esempio n. 3
0
    def do_business(self):
        super(Login, self).do_business()

        # if no conflict
        if self.result:
            if self.external_user is None and self.main_user_from_external is None:
                self.external_user = self.external_user_class(
                    external_id=self.external_id)
                self.main_user_from_external = MainUser(name=self.user_name,
                                                        email=self.email)
                external_user_key, main_user_key = ndb.put_multi(
                    [self.external_user, self.main_user_from_external])
                self._arc = ExternalToMainUser(origin=external_user_key,
                                               destination=main_user_key)
            log_main_user_in(self.main_user_from_external, self.response,
                             self.user_cookie)
        else:
            if self.external_user is None:
                self.external_user = self.external_user_class(
                    external_id=self.external_id)
                self.external_user.put()
            self.pending_link = PendingExternalToMainUser(
                external_user=self.external_user.key,
                main_user=self.main_user_from_email.key)