コード例 #1
0
ファイル: tests.py プロジェクト: flawedmatrix/warmup
 def test_duplicate_add(self):
     """
     Tests the add method of the User class for adding duplicate users
     """
     User.add("xxxxxx", "xxxxxx")
     result = User.add("xxxxxx", "password")
     self.assertEqual(result, ERR_USER_EXISTS)
コード例 #2
0
    def search_profile_by_term(self, term):
        """perform a request to facebook public profile searcher by term, parse html and store
           users information
        """
        kwargs = {'params': {'q': term}, 'path': 'search.php?'}
        resp, content = self.get(**kwargs)
        page = BeautifulSoup(content)
        search_results = page.find(id='pagelet_search_results')
        json_data_regular = re.compile(
            r'{ search_logged_ajax\((?P<json_content>.*)\);.*tabindex')
        name_regular = re.compile(r'<h2 itemprop="name">(?P<name>.*)</h2>')

        for div in search_results.find_all('div',
                                           class_='detailedsearch_result'):
            try:
                jdata = json.loads(
                    json_data_regular.search(str(div)).group('json_content'))
                html_profile = self.get_profile_by_url(jdata['cururl'])
                name = name_regular.search(html_profile).group('name')
                user = User(name=name,
                            username=jdata['id'],
                            json_context=jdata,
                            source=User.SOURCE_ENUM.FACEBOOK)
                user.add()
            except Exception as error:
                print error
                pass
コード例 #3
0
ファイル: tests.py プロジェクト: flawedmatrix/warmup
 def test_successful_login(self):
     """
     Tests the login method of the User class
     """
     User.add("xxxxxx", "xxxxxx")
     result = User.login("xxxxxx", "xxxxxx")
     self.assertEqual(result, 2)
コード例 #4
0
ファイル: tests.py プロジェクト: flawedmatrix/warmup
 def test_wrong_login(self):
     """
     Tests the login method of the User class for
     testing bad credentials
     """
     User.add("xxxxxx", "xxxxxx")
     result = User.login("xxxxxx", "password")
     self.assertEqual(result, ERR_BAD_CREDENTIALS)
コード例 #5
0
ファイル: tests.py プロジェクト: JulianJaffe/Warmup
 def test_resetFixture(self):
     """Reseting the database should clear it."""
     u = User()
     u.add("test1", "")
     u.add("test2", "password")
     self.assertEquals(2, u.login("test1", ""))
     self.assertEquals(User.SUCCESS, u.resetFixture())
     self.assertEquals(User.ERR_BAD_CREDENTIALS, u.login("test1", ""))
     self.assertEquals(User.SUCCESS, u.add("test1", ""))
コード例 #6
0
ファイル: tests.py プロジェクト: flawedmatrix/warmup
 def test_successful_increment(self):
     """
     Tests the login method of the User class for incrementing count
     """
     User.add("xxxxxx", "xxxxxx")
     result = User.login("xxxxxx", "xxxxxx")
     result = User.login("xxxxxx", "xxxxxx")
     result = User.login("xxxxxx", "xxxxxx")
     result = User.login("xxxxxx", "xxxxxx")
     self.assertEqual(result, 5)
コード例 #7
0
ファイル: tests.py プロジェクト: flawedmatrix/warmup
 def test_count_with_wrong_logins(self):
     """
     Tests the login method of the User class for
     preventing wrong credentials from modifying the count
     """
     User.add("xxxxxx", "xxxxxx")
     User.login("xxxxxx", "password")
     User.login("xxxxxx", "xxxxxx")
     User.login("xxxxxx", "password")
     result = User.login("xxxxxx", "xxxxxx")
     self.assertEqual(result, 3)
コード例 #8
0
ファイル: tests.py プロジェクト: flawedmatrix/warmup
 def test_emptypass_add(self):
     """
     Tests the add method of the User class for adding
     a user with an empty password
     """
     result = User.add("xxxxxx", "")
     self.assertNotEqual(result, ERR_BAD_PASSWORD)   
コード例 #9
0
ファイル: tests.py プロジェクト: flawedmatrix/warmup
 def test_emptyuser_add(self):
     """
     Tests the add method of the User class for adding
     a user with an empty username
     """
     result = User.add("", "xxxxxx")
     self.assertEqual(result, ERR_BAD_USERNAME)
コード例 #10
0
ファイル: views.py プロジェクト: JulianJaffe/Warmup
def count(request):
    msg = 'debug'
    user = User()
    if request.method == 'POST':
        username = request.POST.get('username', '')
        password = request.POST.get('password', None)
        if 'login' in request.POST:
            res = user.login(username, password)
            if res > 0:
                msg = 'Welcome %s<br>You have logged in %s times.' % (username, res)
            elif res == user.ERR_BAD_CREDENTIALS:
                msg = 'Invalid username and password combination. Please try again.'
            else:
                msg = 'An error occurred. Please try again.'
        elif 'add' in request.POST:
            res = user.add(username, password)
            if res > 0:
                msg = 'Welcome %s<br>You have logged in 1 time.' % (username)
            elif res == user.ERR_BAD_USERNAME:
                msg = 'The user name should not be empty or longer than 128 characters. Please try again.'
            elif res == user.ERR_BAD_PASSWORD:
                msg = 'The password should not be longer than 128 characters. Please try again.'
            elif res == user.ERR_USER_EXISTS:
                msg = 'This user name already exists. Please choose another one.'
            else:
                msg = 'A error occurred. Please try again.'
        return render(request, 'users/count.html', {'msg': msg})
    return HttpResponseRedirect('/client')
コード例 #11
0
ファイル: base.py プロジェクト: znanl/flask-user-api
    def get_user(cls, **kwargs):
        if "email" not in kwargs:
            kwargs["email"] = ModelTestFactory.create_unique_email()

        if "username" not in kwargs:
            kwargs["username"] = ModelTestFactory.create_unique_string()

        if "first_name" not in kwargs:
            kwargs["first_name"] = ModelTestFactory.create_unique_string()

        if "last_name" not in kwargs:
            kwargs["last_name"] = ModelTestFactory.create_unique_string()

        obj = User(**kwargs)
        obj.add()
        return obj
コード例 #12
0
    def get_user(cls, **kwargs):
        if 'email' not in kwargs:
            kwargs['email'] = ModelTestFactory.create_unique_email()

        if 'username' not in kwargs:
            kwargs['username'] = ModelTestFactory.create_unique_string()

        if 'first_name' not in kwargs:
            kwargs['first_name'] = ModelTestFactory.create_unique_string()

        if 'last_name' not in kwargs:
            kwargs['last_name'] = ModelTestFactory.create_unique_string()

        obj = User(**kwargs)
        obj.add()
        return obj
コード例 #13
0
ファイル: tests.py プロジェクト: flawedmatrix/warmup
 def test_longuser_add(self):
     """
     Tests the add method of the User class for adding
     a user with a long username
     """
     z = "x" * (MAX_USERNAME_LENGTH + 1)
     result = User.add(z, "xxxxxx")
     self.assertEqual(result, ERR_BAD_USERNAME)
コード例 #14
0
ファイル: tests.py プロジェクト: flawedmatrix/warmup
 def test_longpass_add(self):
     """
     Tests the add method of the User class for adding
     a user with a long password
     """
     z = "x" * (MAX_PASSWORD_LENGTH + 1)
     result = User.add("xxxxxx", z)
     self.assertEqual(result, ERR_BAD_PASSWORD)
コード例 #15
0
ファイル: tests.py プロジェクト: JulianJaffe/Warmup
 def test_userTooLong(self):
     """Adding a username with too many characters should fail."""
     u = User()
     name = (
         "12345678901234567890123456789012345678901234567890"
         + "12345678901234567890123456789012345678901234567890"
         + "12345678901234567890123456789012345678901234567890"
     )
     self.assertEquals(User.ERR_BAD_USERNAME, u.add(name, ""))
コード例 #16
0
ファイル: tests.py プロジェクト: JulianJaffe/Warmup
 def test_passTooLong(self):
     """Adding a password with too many characters should fail."""
     u = User()
     pswd = (
         "12345678901234567890123456789012345678901234567890"
         + "12345678901234567890123456789012345678901234567890"
         + "12345678901234567890123456789012345678901234567890"
     )
     self.assertEquals(User.ERR_BAD_PASSWORD, u.add("user", pswd))
コード例 #17
0
    def search_profile_by_term(self, term):
        """perform a request to facebook public profile searcher by term, parse html and store
           users information
        """
        kwargs = {'params': {'q': term},
                 'path': 'search.php?'}
        resp, content = self.get(**kwargs)
        page =  BeautifulSoup(content)
        search_results = page.find(id='pagelet_search_results')
        json_data_regular = re.compile(r'{ search_logged_ajax\((?P<json_content>.*)\);.*tabindex')
        name_regular = re.compile(r'<h2 itemprop="name">(?P<name>.*)</h2>')

        for div in search_results.find_all('div', class_='detailedsearch_result'):
            try:
                jdata = json.loads(json_data_regular.search(str(div)).group('json_content'))
                html_profile = self.get_profile_by_url(jdata['cururl'])
                name = name_regular.search(html_profile).group('name')
                user = User(name=name, username=jdata['id'],
                            json_context=jdata, source=User.SOURCE_ENUM.FACEBOOK)
                user.add()
            except Exception as error:
                print error
                pass
コード例 #18
0
ファイル: views.py プロジェクト: JulianJaffe/Warmup
def addUser(request):
    """Attempts to add a user with the provided credentials to the database and returns a json
    object with either a successful error code and count = 1 or a failing error code."""
    user = User()
    b = request.body
    jsonrequest = json.loads(b.replace("\'",''))
    result = {}
    username = jsonrequest['user']
    password = jsonrequest['password']
    errCode = user.add(username, password)
    result['errCode'] = errCode
    if errCode > 0:
        result['count'] = 1
    return HttpResponse(json.dumps(result), content_type="application/json")
コード例 #19
0
    def search_profile_by_term(self, term):
        """perform a request to twitter public profile searcher by term, parse html and store
           users information
        """
        kwargs = {'params': {'q': term},
                 'path': 'search?'}
        resp, content = self.get(**kwargs)
        page =  BeautifulSoup(content)
        search_results = page.find(id='stream-items-id')
        regular_username = re.compile(r'data-user-id=".*" href="/(?P<username>.*)"')

        def check_username(username):
            """Twitter search return users and twits with the term so we need to make sure that
               the username match with the search term before perform the insertion, if the seacrh
               term is compounded by most than one word we split the string a try to find a partial match
               by every word
            """
            for t in term.split(' '):
                if t.lower() in username.lower():
                    return True
            return False

        json_regular = re.compile(r"value='(?P<json_content>.*)'>")
        for div in search_results.find_all('div', class_='stream-item-header'):
            username = regular_username.search(str(div)).group('username')
            if check_username(username):
                try:
                    profile_page = BeautifulSoup(self.get_profile(username))
                    input_hidden_data =  profile_page.find(id='init-data')
                    jdata = json.loads(json_regular.search(str(input_hidden_data)).group('json_content'))
                    name = jdata['profile_user']['name']
                    popularity_index = jdata['profile_user']['followers_count']
                    user = User(username=username, name=name, json_context=jdata,
                                source=User.SOURCE_ENUM.TWITTER, popularity_index=popularity_index)
                    user.add()
                except Exception as error:
                    pass
コード例 #20
0
ファイル: views.py プロジェクト: flawedmatrix/warmup
def add(request):
    user, password = getUserAndPass(request)
    result = User.add(user, password)
    return respondWithCount(result)
コード例 #21
0
ファイル: tests.py プロジェクト: JulianJaffe/Warmup
 def test_badLoginPass(self):
     """Logging in with the wrong password should fail."""
     u = User()
     u.add("test", "swordfish")
     self.assertEquals(User.ERR_BAD_CREDENTIALS, u.login("test", ""))
コード例 #22
0
ファイル: tests.py プロジェクト: JulianJaffe/Warmup
 def test_addUser(self):
     """Make sure that users can be added to the database!"""
     u = User()
     res = u.add("test3", "pass1")
     self.assertEquals(User.SUCCESS, res)
コード例 #23
0
ファイル: tests.py プロジェクト: JulianJaffe/Warmup
 def test_loginIncrement(self):
     """Logging in should increment the login count."""
     u = User()
     u.add("test", "")
     res = u.login("test", "")
     self.assertEquals(2, res)
コード例 #24
0
ファイル: tests.py プロジェクト: flawedmatrix/warmup
 def test_successful_add(self):
     """
     Tests the add method of the User class
     """
     result = User.add("xxxxxx", "xxxxxx")
     self.assertEqual(result, 1)
コード例 #25
0
ファイル: tests.py プロジェクト: JulianJaffe/Warmup
 def test_addEmptyUsername(self):
     """Adding a user with no username should fail."""
     u = User()
     self.assertEquals(User.ERR_BAD_USERNAME, u.add("", "pass"))
コード例 #26
0
ファイル: tests.py プロジェクト: JulianJaffe/Warmup
 def test_addTwo(self):
     """Adding two users should work."""
     u = User()
     self.assertEquals(User.SUCCESS, u.add("test1", ""))
     self.assertEquals(User.SUCCESS, u.add("test2", "password"))
コード例 #27
0
ファイル: tests.py プロジェクト: JulianJaffe/Warmup
 def test_addExisting(self):
     """Adding an existing user should fail."""
     u = User()
     u.add("test1", "")
     res = u.add("test1", "")
     self.assertEquals(User.ERR_USER_EXISTS, res)
コード例 #28
0
 def test_fail_create_required_fields(self):
     user = User()
     user.add()