Пример #1
0
 def test_full_text_search_finds_matches(self):
     admin = create_first_time_sysadmin(User(email="*****@*****.**"))
     admin2 = create_first_time_sysadmin(User(email="*****@*****.**"))
     command = add_command(admin, "python")
     add_command(admin, "cd /Users/admin/stuff")
     search_results = full_text_search(admin, "python", 1)
     self.assertEquals(command.key(), search_results[0].key())
Пример #2
0
 def _test_post_no_user(self):
     moxer = Mox()
     
     request, response = new_mock_request_response(moxer)
     moxer.StubOutWithMock(users, "get_current_user", use_mock_anything=True)
     moxer.StubOutWithMock(User, "__init__", use_mock_anything=True)
     moxer.StubOutWithMock(Feed, "get_by_source_name", use_mock_anything=True)
     moxer.StubOutWithMock(model, "ingest_feed_entries")
     
     source_name = "hi"
     username = Services.API_USER
     user = MockEntity(key_name=username, email=lambda: username)
     
     # passes auth (via cron)
     users.get_current_user().AndReturn(user)
     handler = IngestHandler()
     # no logged in user
     users.get_current_user()
     User.__init__(username)
     handler.initialize(request, response)
     feed = MockEntity(key_name=source_name, url="no")
     Feed.get_by_source_name(source_name, return_none=True).AndReturn(feed)
     model.ingest_feed_entries(feed, None, error_call=IgnoreArg()).AndReturn(())
     
     moxer.ReplayAll()
     handler.post(source_name)
     moxer.VerifyAll()
Пример #3
0
 def test_commands_are_only_fetched_for_the_user_they_are_associated_with(
         self):
     admin = create_first_time_sysadmin(User(email="*****@*****.**"))
     admin2 = create_first_time_sysadmin(User(email="*****@*****.**"))
     add_command(admin, "foo")
     new_command = add_command(admin, "bar")
     self.assertEqual(0, len(fetch_commands(admin2, 1)))
Пример #4
0
 def test_full_text_search_doesnt_find_matches_if_user_has_no_commands(
         self):
     admin = create_first_time_sysadmin(User(email="*****@*****.**"))
     admin2 = create_first_time_sysadmin(User(email="*****@*****.**"))
     add_command(admin, "cd /Users/admin/stuff")
     search_results = full_text_search(admin2, "cd", 1)
     self.assertEquals(0, len(search_results))
Пример #5
0
  def setUp(self):
    super(TestProcessIssue, self).setUp()
    now = datetime.datetime.utcnow()
    self.now = datetime.datetime(
        year=now.year, month=now.month, day=now.day, hour=10)
    self.today = self.now.date()
    self.messages = []

    self.owner = '*****@*****.**'
    self.owner_user = User(self.owner)
    self.owner_account = models.Account.get_account_for_user(self.owner_user)

    self.issue = models.Issue(owner=self.owner_user, subject='World domination')
    self.issue.put()

    self.reviewer = '*****@*****.**'
    self.reviewer_user = User(self.reviewer)
    self.reviewer_account = models.Account.get_account_for_user(
        self.reviewer_user)
    # Real users have created at least one issue.
    models.Issue(owner=self.reviewer_user, subject='Damned').put()

    self.slacker = '*****@*****.**'
    self.slacker_user = User(self.slacker)
    self.slacker_account = models.Account.get_account_for_user(
        self.slacker_user)
    # Real users have created at least one issue.
    models.Issue(owner=self.slacker_user, subject='I\'m slacking').put()

    # Sadly mailing lists have accounts too. BUT, these accounts have never
    # created an issue.
    self.ml = '*****@*****.**'
    self.ml_user = User(self.ml)
    self.ml_account = models.Account.get_account_for_user(self.ml_user)
Пример #6
0
    def post(self):
        from google.appengine.api.users import User

        error = None
        success = None
        dnzo_user = None
        dnzo_user_already = None
        google_user_to = None

        try:
            from_email = self.request.get('user_from', None)
            dnzo_user = get_dnzo_user_by_email(from_email)

            google_user_to = User(self.request.get('user_to', None))
            dnzo_user_already = get_dnzo_user(invalidate_cache=True,
                                              google_user=google_user_to)

        except:
            pass

        if dnzo_user is None:
            error = "Could not find existing DNZO user. Whoops!"
        elif dnzo_user_already is not None:
            error = "User exists already with that e-mail address! Delete him first."
        elif google_user_to is None:
            error = "Couldn't find the new Google user. Whoops!"
        else:
            clear_user_memcache(dnzo_user)
            dnzo_user.user = google_user_to
            save_user(dnzo_user)
            success = "Success! %s is now %s." % (from_email,
                                                  google_user_to.email())

        self.render("admin/modify_user.html", error=error, success=success)
Пример #7
0
  def post(self):
    from google.appengine.api.users import User
  
    error = None
    success = None
    dnzo_user = None
    dnzo_user_already = None
    google_user_to = None
  
    try:
      from_email = self.request.get('user_from', None)
      dnzo_user = get_dnzo_user_by_email(from_email)
  
      google_user_to = User(self.request.get('user_to', None))
      dnzo_user_already = get_dnzo_user(invalidate_cache=True, google_user=google_user_to)
    
    except:
      pass
  
    if dnzo_user is None:
      error = "Could not find existing DNZO user. Whoops!"
    elif dnzo_user_already is not None:
      error = "User exists already with that e-mail address! Delete him first."
    elif google_user_to is None:
      error = "Couldn't find the new Google user. Whoops!"
    else:
      clear_user_memcache(dnzo_user)
      dnzo_user.user = google_user_to
      save_user(dnzo_user)
      success = "Success! %s is now %s." % (from_email, google_user_to.email())

    self.render("admin/modify_user.html", error=error, success=success)
Пример #8
0
 def test_full_text_search_ignores_keywords_after_first_two(self):
     admin = create_first_time_sysadmin(User(email="*****@*****.**"))
     admin2 = create_first_time_sysadmin(User(email="*****@*****.**"))
     command = add_command(admin, "python is great")
     command = add_command(admin, "python")
     add_command(admin, "will find wont find")
     search_results = full_text_search(admin, "wont find python is great",
                                       1)
     self.assertEquals(1, len(search_results))
Пример #9
0
    def setUp(self):
        # First, create an instance of the Testbed class.
        self.testbed = testbed.Testbed()
        # Then activate the testbed, which prepares the service stubs for use.
        self.testbed.activate()

        self.testbed.init_memcache_stub()

        self.user1 = User('*****@*****.**')
        self.user2 = User('*****@*****.**')
Пример #10
0
 def test_full_text_search_gives_correct_results_down_to_a_one_character_search(
         self):
     admin = create_first_time_sysadmin(User(email="*****@*****.**"))
     admin2 = create_first_time_sysadmin(User(email="*****@*****.**"))
     command = add_command(admin, "v")
     add_command(admin, "ls")
     command2 = add_command(admin2, "v command.py")
     commands = Command.all().filter('user =', admin).search("v")
     self.assertEquals(1, len(commands.fetch(10)))
     self.assertEquals(command.key(), commands[0].key())
Пример #11
0
    def post(self):
        super(AdminAction_UserAdd, self).get()
        u = User(email=self.request.get('user_email'))
        existUser = VUser.all().filter('user='******'user_email'))
            newUser.put()

        self.redirect('/admin/users')
Пример #12
0
 def setUp(self):
   super(TestDailyStats, self).setUp()
   self.author = models.Account.get_account_for_user(
       User('*****@*****.**'))
   self.reviewer1 = models.Account.get_account_for_user(
       User('*****@*****.**'))
   self.reviewer2 = models.Account.get_account_for_user(
       User('*****@*****.**'))
   # Real users have created at least one issue.
   models.Issue(owner=self.author.user, subject='Damned').put()
   models.Issue(owner=self.reviewer1.user, subject='Damned').put()
   models.Issue(owner=self.reviewer2.user, subject='Damned').put()
Пример #13
0
def get_youtify_user_by_email(email):
    try:
        youtify_user = YoutifyUser.all().filter('google_user2 =', User(email)).get()
        if youtify_user:
            return youtify_user
    except:
        pass
Пример #14
0
 def setUp(self):
   super(TestMultiStats, self).setUp()
   self.assertEqual([], models.AccountStatsDay.query().fetch())
   self.assertEqual([], models.AccountStatsMulti.query().fetch())
   self.assertEqual(None, models.Issue.query().get())
   self.userA = models.Account.get_account_for_user(
       User('*****@*****.**'))
   self.userA_key = self.userA.key
   self.userB = models.Account.get_account_for_user(
       User('*****@*****.**'))
   self.userB_key = self.userB.key
   # Real users have created at least one issue.
   models.Issue(owner=self.userA.user, subject='Damned').put()
   models.Issue(owner=self.userB.user, subject='Damned').put()
   self.today = datetime.datetime(2012, 04, 30, 1, 0)
   self.yesterday = self.today - datetime.timedelta(days=1)
Пример #15
0
class UserField(wtforms.Field):
    """
    A field that alls WTForms to produce a field that can be used
    to edit a db.UserProperty or ndb.UserProperty. Displays as a text field with an
    Email.
    """
    widget = wtforms.widgets.TextInput()
    __temporary_data = None

    def _value(self):
        if self.data:
            return self.data.email()
        else:
            return u''

    def process_formdata(self, valuelist):
        if valuelist and valuelist[0]:
            self.data = User(valuelist[0])
        else:
            self.data = None

    def pre_validate(self, form):
        if self.data:
            self.__temporary_data = self.data
            self.data = self.data.email()

    def post_validate(self, form, validation_stopped):
        if self.__temporary_data:
            self.data = self.__temporary_data
Пример #16
0
	def get_by_user(cls, user, create=False):
		"""Fetch or if necessary create an instance of RoadMateUser with the
		corrosponding user propertery.

		Args:
			user: An instance of google.appengine.api.users.User.
			create: Whether an instance of RoadMateUser should be created
				in the datastore if it does not exist.

		Returns:
			An instance of RoadMateUser which is in the datastore.

		Raises:
			KindError if user is not of kind google.appengine.api.users.User.
		"""
		# sanity checks
		if user is None:
			raise ValueError('user value must not be None')
		if not isinstance(user, User):
			raise KindError('Expected kind: %r, got kind: %r' %
				(User.kind(), user.kind()))

		# try to get the a RoadMateUser with a corrosponding user property
		roadmate_user = RoadMateUser.all().filter('user =', user).get()

		# if a corrosponding entity was not found in the datastore then create
		# one, if permitted.
		if not roadmate_user and create:
			roadmate_user = RoadMateUser(user=user)
			roadmate_user.put()

		return roadmate_user
Пример #17
0
class UserField(wtforms.Field):
    """
    A field that alls WTForms to produce a field that can be used
    to edit a db.UserProperty or ndb.UserProperty. Displays as a text field with an
    Email.
    """
    widget = wtforms.widgets.TextInput()
    __temporary_data = None

    def _value(self):
        if self.data:
            return self.data.email()
        else:
            return u''

    def process_formdata(self, valuelist):
        if valuelist and valuelist[0]:
            self.data = User(valuelist[0])
        else:
            self.data = None

    def pre_validate(self, form):
        if self.data:
            self.__temporary_data = self.data
            self.data = self.data.email()

    def post_validate(self, form, validation_stopped):
        if self.__temporary_data:
            self.data = self.__temporary_data
Пример #18
0
 def test_create_first_time_sysadmin_doesnt_create_new_entry_for_existing(
         self):
     user = User(email="*****@*****.**")
     admin = create_first_time_sysadmin(user)
     again_admin = create_first_time_sysadmin(user)
     self.assertEquals(1, len(Sysadmin.all().fetch(10)))
     self.assertEquals(again_admin, None)
Пример #19
0
    def login(self, email="*****@*****.**", admin=False):
        from os import environ
        from google.appengine.api.users import User

        #environ["USER_IS_ADMIN"] = str(int(bool(admin)))
        environ["USER_IS_ADMIN"] = ("1" if admin else "0")
        environ["USER_EMAIL"] = email
        return User(email=email)
Пример #20
0
 def setUp(self):
     """Create two test issues and users."""
     super(TestSearch, self).setUp()
     user = User('*****@*****.**')
     models.Account.get_account_for_user(user)
     user = User('*****@*****.**')
     models.Account.get_account_for_user(user)
     self.user = User('*****@*****.**')
     self.login('*****@*****.**')
     issue1 = models.Issue(subject='test')
     issue1.reviewers = ['*****@*****.**', '*****@*****.**']
     issue1.local_base = False
     issue1.put()
     issue2 = models.Issue(subject='test')
     issue2.reviewers = ['*****@*****.**', '*****@*****.**']
     issue2.local_base = False
     issue2.put()
Пример #21
0
 def test_create_command_tags(self):
     user = User(email="*****@*****.**")
     sysadmin = Sysadmin(goo_user=user)
     sysadmin.put()
     command = Command(command="pwd", user=sysadmin)
     command.put()
     create_command_tags(sysadmin, command, ["foo", "bar"])
     self.assertEquals(2, len(CommandTag.all().fetch(10)))
Пример #22
0
 def test_find_by_tag_orders_by_command_creation_date(self):
     admin = create_first_time_sysadmin(User(email="*****@*****.**"))
     oldest_command = add_command(admin, "ls")
     newest_command = add_command(admin, "vi")
     create_command_tags(admin, newest_command, ["foo"])
     create_command_tags(admin, oldest_command, ["foo"])
     self.assertEqual(
         newest_command.key(),
         find_command_tags_by_tag(admin, "foo", 1)[0].command.key())
Пример #23
0
 def test_adding_duplicate_tags_doesnt_create_duplicates(self):
     admin = create_first_time_sysadmin(User(email="*****@*****.**"))
     admin.add_tags(["foo"])
     admin.add_tags(["foo", "foo"])
     admin.put()
     self.assertEquals(["foo"], find_sysadmin_by_id(admin.hash).tags)
     admin.add_tags(["bar"])
     admin.put()
     self.assertEquals(["foo", "bar"], find_sysadmin_by_id(admin.hash).tags)
Пример #24
0
 def test_add_user(self):
     user = AppUser(user=User(email="*****@*****.**"),
                    username="******",
                    email="*****@*****.**",
                    is_staff=True).save()
     assert not Profile.all().count()
     profile = get_profile(user)
     assert profile.notification == 5
     assert Profile.all().count()
Пример #25
0
 def test_user_ignored(self):
     # The save routine should ignore a submitted user parameter.
     user = self.login()
     email = "*****@*****.**"
     other = User(email=email)
     app = TestApp(application)
     response = app.post("/create", params={"slug": "abcd", "user": email})
     fetched = Election.all().fetch(1)[0]
     self.assertEquals(fetched.creator, user)
Пример #26
0
 def test_full_text_search_paging_works(self):
     Command.COMMANDS_PER_PAGE = 2
     admin = create_first_time_sysadmin(User(email="*****@*****.**"))
     command = add_command(admin, "cd /Users/admin/stuff")
     add_command(admin, "cd /Users/admin/stuff")
     add_command(admin, "cd /Users/admin")
     search_results = full_text_search(admin, "cd", 2)
     self.assertEquals(1, len(search_results))
     self.assertEquals(command.key(), search_results[0].key())
Пример #27
0
Файл: mail.py Проект: qs/vypolni
 def receive(self, message):
     user = User(email=re.findall(
         "([a-zA-Z\.]+@[a-zA-Z0-9]+\.[a-zA-Z0-9]+)", message.sender)[0])
     subject, tags = self.parse_subject(message.subject)
     content = u""
     for content_type, body in message.bodies('text/html'):
         content += body.decode()
     quest = Quest(title=subject, tags=tags, user=user)
     quest.put()
     logging.info("Received a message from: " + message.sender)
Пример #28
0
    def ingest(cls, handler, source_name):
        helper = RequestHelper(handler)
        source_name = urllib.unquote(source_name)

        keep = handler.request.get("keep")
        if keep:
            keep = int(keep)
        else:
            keep = 50

        # TODO: get from cache
        f = Feed.get_by_source_name(source_name, return_none=True)
        if not f:
            helper.error(404)
            return

        results = {}
        entries = []
        results['created'] = entries

        # TODO: use etag from previous ingest
        error_call = lambda entry, ex: logging.error(Exceptions.format_last())

        user = users.get_current_user()
        if not user:
            # there is no logged in user for cron requests
            user = User(Services.API_USER)

        try:
            for artifact_guid, entry, created in model.ingest_feed_entries(
                    f, user, error_call=error_call):
                entries.append({
                    "artifact-guid": artifact_guid,
                    "url": entry.link,
                    "title": entry.title,
                    "created": created
                })
        finally:
            # delete oldest feed entries
            # TODO: shouldn't I be deleting ArtifactContent instances also?
            def delete_info(c):
                try:
                    i = c.info
                    if i:
                        i.delete()
                except Exception, e:
                    pass

            deleted_key_names = ArtifactContent.delete_oldest_by_source(
                f.artifact_source, keep, pre_call=delete_info)

            results['deleted'] = deleted_key_names
            Counters.source_counter(f.artifact_source.name).decrement(
                len(deleted_key_names))
Пример #29
0
 def setUp(self):
     super(TestPublish, self).setUp()
     self.user = User('*****@*****.**')
     self.login('*****@*****.**')
     self.issue = models.Issue(subject='test')
     self.issue.local_base = False
     self.issue.put()
     self.ps = models.PatchSet(parent=self.issue, issue=self.issue)
     self.ps.data = load_file('ps1.diff')
     self.ps.save()
     self.patches = engine.ParsePatchSet(self.ps)
     db.put(self.patches)
Пример #30
0
class RFID():

	@staticmethod
	def fetch_member(id):
		# Really need to implement a better data sharing strategy between apps.
		url = config['rfid_url'] + id
		try:
			result = urllib2.urlopen(url).read()
		except urllib2.URLError, e:
			raise Exception("Couldn't connect to the member database.")
		data = json.loads(result)
		user = User( "*****@*****.**" % data['username'] )
		return user
Пример #31
0
 def test_draft_details_no_base_file(self):
     request = MockRequest(User('*****@*****.**'), issue=self.issue)
     # add a comment and render
     cmt = models.Comment(patch=self.patches[0], parent=self.patches[0])
     cmt.text = 'test comment'
     cmt.lineno = 1
     cmt.left = False
     cmt.draft = True
     cmt.author = self.user
     cmt.save()
     tbd, comments = views._get_draft_comments(request, self.issue)
     self.assertEqual(len(comments), 1)
     # Try to render draft details:
     views._get_draft_details(request, comments)
Пример #32
0
    def dateSpanReport(self):
        email = self.request.get('email')

        dateFormat = '%Y-%m-%d %H:%M:%S'

        fromDate = datetime.datetime.strptime(self.request.get('fromDate'),
                                              dateFormat)
        toDate = datetime.datetime.strptime(self.request.get('toDate'),
                                            dateFormat)

        user = User(email=email)

        event_reports.SendEmailDailyReport(user, email, fromDate, toDate)
        pass
Пример #33
0
 def test_find_commands_by_tag(self):
     user = User(email="*****@*****.**")
     sysadmin = Sysadmin(goo_user=user)
     sysadmin.put()
     command = Command(command="pwd", user=sysadmin)
     command.put()
     command2 = Command(command="ls", user=sysadmin)
     command2.put()
     tag = Tag(name="lame")
     tag.put()
     command_tag = CommandTag(command=command, tag=tag, user=sysadmin)
     command_tag.put()
     command_tag2 = CommandTag(command=command2, tag=tag, user=sysadmin)
     command_tag2.put()
     self.assertEqual(2, len(find_command_tags_by_tag(sysadmin, "lame", 1)))
Пример #34
0
 def process_formdata(self, valuelist):
     if valuelist and valuelist[0]:
         self.data = User(valuelist[0])
     else:
         self.data = None