Exemple #1
0
 def set_up(self):
     parse_result = urlparse(self._url)
     domain = parse_result.netloc.split(':')[0] or self._url
     if domain:
         token = urandom(16).encode('hex')
         self.result = Site(domain=domain, token=token)
         self._future = self.result._put_async()
     else:
         self.add_error('domain', _('Domain should not be empty'))
Exemple #2
0
class SaveSite(Command):
    def __init__(self, user, url):
        super(SaveSite, self).__init__()
        self._user = user
        self._url = url
        self._to_commit = None


    def set_up(self):
        parse_result = urlparse(self._url)
        domain = parse_result.netloc.split(':')[0] or self._url
        if domain:
            token = urandom(16).encode('hex')
            self.result = Site(domain=domain, token=token)
            self._future = self.result._put_async()
        else:
            self.add_error('domain', _('Domain should not be empty'))

    def do_business(self, stop_on_error=False):
        if not self.errors:
            site_key = self._future.get_result()
            self._to_commit = SiteOwner(origin=to_node_key(self._user), destination=site_key)

    def commit(self):
        if not self.errors:
            return self._to_commit
Exemple #3
0
 def set_up(self):
     try:
         self.result = memcache(settings.APP_HOST)
     except:
         pass
     if not self.result:
         self._future = Site.find_by_domain(settings.APP_HOST).get_async()
Exemple #4
0
class SaveSite(Command):
    def __init__(self, user, url):
        super(SaveSite, self).__init__()
        self._user = user
        self._url = url
        self._to_commit = None

    def set_up(self):
        parse_result = urlparse(self._url)
        domain = parse_result.netloc.split(':')[0] or self._url
        if domain:
            token = urandom(16).encode('hex')
            self.result = Site(domain=domain, token=token)
            self._future = self.result._put_async()
        else:
            self.add_error('domain', _('Domain should not be empty'))

    def do_business(self, stop_on_error=False):
        if not self.errors:
            site_key = self._future.get_result()
            self._to_commit = SiteOwner(origin=to_node_key(self._user),
                                        destination=site_key)

    def commit(self):
        if not self.errors:
            return self._to_commit
Exemple #5
0
 def set_up(self):
     try:
         self.result = memcache(settings.APP_HOST)
     except:
         pass
     if not self.result:
         self._future = Site.find_by_domain(settings.APP_HOST).get_async()
Exemple #6
0
 def set_up(self):
     parse_result = urlparse(self._url)
     domain = parse_result.netloc.split(':')[0] or self._url
     if domain:
         token = urandom(16).encode('hex')
         self.result = Site(domain=domain, token=token)
         self._future = self.result._put_async()
     else:
         self.add_error('domain', _('Domain should not be empty'))
Exemple #7
0
    def test_success(self):
        # Mocks
        site = Site(domain='pswdless.appspot.com', token='t')
        email = '*****@*****.**'
        user = mommy.make_one(MainUser, email=email)
        login = Login(status=LOGIN_CALL,
                      hook='https://pswdless.appspot.com/foo')
        ndb.put_multi([site, user, login])

        # Arcs
        ndb.put_multi([
            LoginUser(origin=login.key, destination=user.key),
            LoginSite(origin=login.key, destination=site.key)
        ])

        callback_flag = Mock()

        def callback(*args):
            callback_flag()
            zipped = zip([login, site, user], args)
            for expected, current in zipped:
                self.assertEqual(type(expected), type(current))
                self.assertEqual(expected.key, current.key)

        send_email = facade.send_login_email(str(login.key.id()), callback)
        send_email.execute()

        # Login changes
        login_db = login.key.get()
        self.assertEqual(LOGIN_EMAIL, login_db.status)
        search = SingleLoginStatusArcSearch(login)
        login_status = search()
        self.assertIsInstance(login_status, LoginStatus)
        self.assertEqual(LOGIN_EMAIL, login_status.label)

        # Site User creation
        user_search = SingleSiteUserSearch(site)
        db_user = user_search()
        self.assertEqual(user.key, db_user.key)

        # Callback call
        callback_flag.assert_called_once_with()
Exemple #8
0
    def test_success(self):
        mail_stub = self.testbed.get_stub(testbed.MAIL_SERVICE_NAME)
        # Mocks
        email = '*****@*****.**'
        site = Site(domain='pswdless.appspot.com', token='t')
        user = mommy.save_one(MainUser, email=email)
        login = Login(status=LOGIN_CALL,
                      hook='https://pswdless.appspot.com/foo')
        ndb.put_multi([site, user, login])
        task._ = lambda s: s

        # Arcs
        ndb.put_multi([
            LoginUser(origin=login.key, destination=user.key),
            LoginSite(origin=login.key, destination=site.key)
        ])

        task.send_login_email(template.render, str(login.key.id()), 'pt_BR')
        messages = mail_stub.get_sent_messages(to='*****@*****.**')
        self.assertEqual(1, len(messages))