예제 #1
0
    def test_adding_user_twice_doesnt_cause_dupes(self):
        user = User("Joe Bloggs",
                    "*****@*****.**",
                    location_func=lambda: ((0, 0), 0))
        users = Users()

        users.add_user(user)
        users.add_user(
            User("Joe Bloggs",
                 "*****@*****.**",
                 location_func=lambda: ((90, 90), 0)))
        self.assertEqual(len(users.users), 1)
예제 #2
0
    def test_supplying_better_location_function_overrides(self):
        user = User("Joe Bloggs",
                    "*****@*****.**",
                    location_func=lambda: ((0, 0), 0))
        users = Users()

        users.add_user(user)
        users.add_user(
            User("Joe Bloggs",
                 "*****@*****.**",
                 location_func=lambda: ((90, 90), 1)))
        self.assertEqual(
            users.get_user_by_name(u"Joe Bloggs").location, (90, 90))
예제 #3
0
    def add_sender(self, message):
        def email_location():
            recieved = message.get_all('Original-Received')
            ips = [IP.findall(h) for h in recieved]
            ips = [
                ip[0] for ip in ips if ip and not ip[0].startswith("10.")
                and not ip[0].startswith("192.168")
            ]
            likely = ips[-1]
            try:
                logger.info("geocoder: Getting location for %s" % (likely))
                url = "http://freegeoip.net/json/%s" % likely
                logger.debug("geocoder: Fetching %s" % (url))
                loc = json.loads(urllib2.urlopen(url).read())
                ll = float(loc['latitude']), float(loc['longitude'])
                if any(ll):
                    return ll, 0
            except:
                pass

        users = getUtility(IUserDatabase)
        from_ = list(email.utils.parseaddr(message.get("From")))

        # Remove quoted printable
        from_[0] = decode_header(from_[0])[0]
        encoding = from_[0][1]
        if encoding is None:
            encoding = "utf-8"
        from_[0] = from_[0][0].decode(encoding)

        users.add_user(User(from_[0], from_[1], location_func=email_location))
예제 #4
0
    def test_get_location(self):
        user = User("Joe Bloggs",
                    "*****@*****.**",
                    location_func=lambda: ((0, 0), 0))
        users = Users()

        users.add_user(user)
        self.assertEqual(
            users.get_user_by_name(u"Joe Bloggs").location, (0, 0))
예제 #5
0
 def _get_github_accounts(self, accounts, token):
     users = getUtility(IUserDatabase)
     i = 0.0
     for account in accounts:
         i+=1
         if account in ALREADY_FOUND:
             continue
         url = "https://api.github.com/users/%s?access_token=%s" % (account,token)
         logger.debug("github: getting %s" % url)
         gh_api = urllib2.urlopen(url)
         user = json.loads(gh_api.read())
         ALREADY_FOUND.add(account)
         users.add_user(User(user.get('name', user['login']), user.get('email', None), username=user['login'], location_func=lazy_location(user)))
예제 #6
0
def get_github_accounts(accounts, token):
    geocoder = ggeocoder.Geocoder()
    users = getUtility(IUserDatabase)
    i = 0.0
    for account in accounts:
        i += 1
        print "%2d%% complete" % ((i / len(accounts)) * 100.0)
        gh_api = urllib2.urlopen(
            "https://api.github.com/users/%s?access_token=%s" %
            (account, token))
        user = json.loads(gh_api.read())
        try:
            location = geocoder.geocode(user['location'])[0].coordinates
        except:
            location = None
        users.add_user(
            User(user.get('name', user['login']), user.get('email', None),
                 location))
예제 #7
0
    def test_search_by_name(self):
        user = User("Joe Bloggs", "*****@*****.**")
        users = Users()

        users.add_user(user)
        self.assertEqual(users.get_user_by_name("Joe Bloggs"), user)
예제 #8
0
    def test_search_by_name_matches_with_missing_accents(self):
        user = User("Joe Bloggs", "*****@*****.**")
        users = Users()

        users.add_user(user)
        self.assertEqual(users.get_user_by_name(u"Joé Bloggs"), user)