Пример #1
0
 def test_email_fail(self):
     subject = 'test'
     to = 'bad_email_address'
     sender = '*****@*****.**'
     body = 'stuff'
     mymox = mox.Mox()
     mymox.StubOutWithMock(logging, 'error')
     logging.error('EmailSender (to: %s, subject: %s), '
                   'failed with exception %s' % (to, subject, 'exception'))
     mymox.StubOutWithMock(mail, 'send_mail')
     mail.send_mail(sender=sender, subject=subject, to=to,
                    body=body).AndRaise(mail_errors.Error('exception'))
     handler = send_mail.EmailSender()
     repo = 'haiti'
     model.Repo(key_name=repo).put()
     request = webapp.Request(
         webob.Request.blank('/admin/send_mail?to=%s&subject=%s&sender=%s' %
                             (to, subject, sender)).environ)
     request.method = 'POST'
     request.body = 'body=%s' % body
     handler.initialize(request, webapp.Response())
     mymox.ReplayAll()
     handler.post()
     # shouldn't raise an error.
     assert True
     mymox.VerifyAll()
Пример #2
0
 def setUp(self):
     model.Repo(key_name='haiti').put()
     config.set_for_repo('haiti',
                         repo_titles={'en': 'Haiti Earthquake'},
                         language_menu_options=['en', 'ht', 'fr', 'es'],
                         referrer_whitelist=[])
     self.original_get_rendered = resources.get_rendered
Пример #3
0
def initialize_handler(
        handler_class, action, repo='haiti', environ=None, params=None):
    model.Repo(key_name=repo).put()
    params_str = ('?' + urllib.urlencode(params)) if params else ''
    request = webapp.Request(webob.Request.blank(
        '/' + repo + '/' + action + params_str, environ=environ).environ)
    response = webapp.Response()
    return handler_class(request, response, main.setup_env(request))
Пример #4
0
 def repo(self,
          store=True,
          repo_id='haiti',
          activation_status=model.Repo.ActivationStatus.ACTIVE):
     repo = model.Repo(key_name=repo_id,
                       activation_status=activation_status)
     if store:
         repo.put()
     return repo
Пример #5
0
 def setUp(self):
     self.testbed = testbed.Testbed()
     self.testbed.activate()
     self.testbed.init_user_stub()
     self.testbed.init_datastore_v3_stub()
     self.testbed.init_memcache_stub()
     self.testbed.init_mail_stub()
     # root_path must be set the the location of queue.yaml.
     # Otherwise, only the 'default' queue will be available.
     path_to_app = os.path.join(os.path.dirname(__file__), '../app')
     self.testbed.init_taskqueue_stub(root_path=path_to_app)
     model.Repo(key_name='haiti').put()
Пример #6
0
 def setUp(self):
     # Make it look like the dev server so HTTPS isn't required.
     os.environ['APPLICATION_ID'] = 'dev~abc'
     self.testbed = testbed.Testbed()
     self.testbed.activate()
     self.testbed.init_user_stub()
     model.Repo(key_name='haiti').put()
     config.set_for_repo('haiti',
                         repo_titles={'en': 'Haiti Earthquake'},
                         language_menu_options=['en', 'ht', 'fr', 'es'],
                         referrer_whitelist=[])
     self.original_get_rendered = resources.get_rendered
Пример #7
0
 def setUp(self):
     self.testbed = testbed.Testbed()
     self.testbed.activate()
     self.testbed.init_user_stub()
     self.testbed.init_datastore_v3_stub()
     self.testbed.init_memcache_stub()
     self.testbed.init_mail_stub()
     # root_path must be set the the location of queue.yaml.
     # Otherwise, only the 'default' queue will be available.
     path_to_app = os.path.join(os.path.dirname(__file__), '../app')
     self.testbed.init_taskqueue_stub(root_path=path_to_app)
     model.Repo(key_name='haiti').put()
     self.handler = test_handler.initialize_handler(
         handler_class=tasks.NotifyManyUnreviewedNotes,
         action=tasks.NotifyManyUnreviewedNotes.ACTION,
         repo='haiti',
         environ=None,
         params=None)
Пример #8
0
 def create_repo(self, repo):
     logging.info('Create repo: %s', repo)
     db.put([model.Repo(key_name=repo)])
     # Provides some defaults.
     config.set_for_repo(
         repo,
         language_menu_options=['en'],
         repo_titles={'en': repo},
         keywords='',
         use_family_name=True,
         use_alternate_names=True,
         use_postal_code=True,
         allow_believed_dead_via_ui=False,
         min_query_word_length=1,
         show_profile_entry=False,
         profile_websites=[],
         map_default_zoom=6,
         map_default_center=[0, 0],
         map_size_pixels=[400, 280],
         read_auth_key_required=True,
         search_auth_key_required=True,
         deactivated=False,
         launched=False,
         deactivation_message_html='',
         start_page_custom_htmls={},
         results_page_custom_htmls={},
         view_page_custom_htmls={},
         seek_query_form_custom_htmls={},
         footer_custom_htmls={},
         bad_words='',
         published_date=0.0,
         updated_date=0.0,
         test_mode=False,
         force_https=False,
         zero_rating_mode=False,
     )
Пример #9
0
    def post(self, request, *args, **kwargs):
        """Serves POST requests, creating a new repo.

        Creates a new repository and sets some default values (assuming the user
        has permission and a valid XSRF token).

        Args:
            request: Unused.
            *args: Unused.
            **kwargs: Unused.

        Returns:
            HttpResponse: A redirect to the new repo's admin page.
        """
        del request, args, kwargs  # unused
        self.enforce_xsrf(self.ACTION_ID)
        new_repo = self.params.new_repo
        model.Repo(
            key_name=new_repo,
            activation_status=model.Repo.ActivationStatus.STAGING,
            test_mode=False).put()
        # Provide some defaults.
        config.set_for_repo(
            new_repo,
            language_menu_options=['en', 'fr'],
            repo_titles={
                'en': 'Earthquake',
                'fr': u'S\xe9isme'
            },
            keywords='person finder, people finder, person, people, ' +
            'crisis, survivor, family',
            use_family_name=True,
            use_alternate_names=True,
            use_postal_code=True,
            allow_believed_dead_via_ui=False,
            min_query_word_length=2,
            show_profile_entry=False,
            profile_websites=const.DEFAULT_PROFILE_WEBSITES,
            map_default_zoom=6,
            map_default_center=[0, 0],
            map_size_pixels=[400, 280],
            read_auth_key_required=True,
            search_auth_key_required=True,
            deactivated=False,
            launched=False,
            deactivation_message_html='',
            start_page_custom_htmls={
                'en': '',
                'fr': ''
            },
            results_page_custom_htmls={
                'en': '',
                'fr': ''
            },
            view_page_custom_htmls={
                'en': '',
                'fr': ''
            },
            seek_query_form_custom_htmls={
                'en': '',
                'fr': ''
            },
            footer_custom_htmls={
                'en': '',
                'fr': ''
            },
            bad_words='',
            published_date=utils.get_utcnow_timestamp(),
            updated_date=utils.get_utcnow_timestamp(),
            test_mode=False,
            force_https=True,
            zero_rating_mode=False,
            time_zone_offset=0,
            time_zone_abbreviation='UTC',
        )
        return django.shortcuts.redirect(
            self.build_absolute_path('/%s/admin' % new_repo))
Пример #10
0
    def setUp(self):
        self.testbed = testbed.Testbed()
        self.testbed.activate()
        self.testbed.init_user_stub()
        self.testbed.init_datastore_v3_stub()
        self.testbed.init_memcache_stub()
        self.testbed.init_taskqueue_stub()
        model.Repo(key_name='haiti').put()

        logging.basicConfig(level=logging.INFO, stream=sys.stderr)
        self.mox = None

        # Setup cheerfully stolen from test_model.
        set_utcnow_for_test(datetime.datetime(2010, 1, 1))
        self.photo = model.Photo.create('haiti', image_data='xyz')
        self.photo.put()
        self.photo_key = self.photo.key()
        self.p1 = model.Person.create_original(
            'haiti',
            given_name='John',
            family_name='Smith',
            home_street='Washington St.',
            home_city='Los Angeles',
            home_state='California',
            home_postal_code='11111',
            home_neighborhood='Good Neighborhood',
            author_name='Alice Smith',
            author_phone='111-111-1111',
            author_email='*****@*****.**',
            photo_url='',
            photo=self.photo,
            source_url='https://www.source.com',
            source_date=datetime.datetime(2010, 1, 1),
            source_name='Source Name',
            entry_date=datetime.datetime(2010, 1, 1),
            expiry_date=datetime.datetime(2010, 2, 1),
            other='')
        self.p2 = model.Person.create_original(
            'haiti',
            given_name='Tzvika',
            family_name='Hartman',
            home_street='Herzl St.',
            home_city='Tel Aviv',
            home_state='Israel',
            source_date=datetime.datetime(2010, 1, 1),
            entry_date=datetime.datetime(2010, 1, 1),
            expiry_date=datetime.datetime(2010, 3, 1),
            other='')
        self.key_p1 = db.put(self.p1)
        self.key_p2 = db.put(self.p2)
        self.n1_1 = model.Note.create_original(
            'haiti',
            person_record_id=self.p1.record_id,
            linked_person_record_id=self.p2.record_id,
            status=u'believed_missing',
            author_made_contact=False,
            entry_date=get_utcnow(),
            source_date=datetime.datetime(2010, 1, 2))
        self.note_id = self.n1_1.note_record_id
        db.put(self.n1_1)
        self.to_delete = [self.p1, self.p2, self.n1_1, self.photo]
Пример #11
0
 def repo(self, store=True, repo_id='haiti'):
     repo = model.Repo(key_name=repo_id)
     if store:
         repo.put()
     return repo