def test_insert_update_likely_users_get_likely_users(self):
     target_id_vk = test_target_user.get("id_vk")
     likely_id_vk = test_likely_user1.get('id_vk')
     likely_user_params = dict(test_likely_user1)
     likely_user_params.pop("id")
     likely_user_params.pop("id_vk")
     users_in_db = [insert_update_likely_users(self.connection_db, target_id_vk, likely_id_vk, **likely_user_params),
                    get_likely_users(self.connection_db, test_target_user.get("id_vk"),
                                     test_likely_user1.get("id_vk"))]
     for user_in_db in users_in_db:
         self.assertEqual(user_in_db[1], target_id_vk)
         self.assertEqual(user_in_db[2], likely_id_vk)
         self.assertEqual(user_in_db[3], likely_user_params.get('first_name'))
         self.assertEqual(user_in_db[4], likely_user_params.get('last_name'))
         self.assertEqual(user_in_db[5], likely_user_params.get('sex'))
         self.assertEqual(user_in_db[6], likely_user_params.get('city'))
         self.assertEqual(user_in_db[7], likely_user_params.get('age'))
         self.assertEqual(user_in_db[8], likely_user_params.get('activities'))
         self.assertEqual(user_in_db[9], likely_user_params.get('interests'))
         self.assertEqual(user_in_db[10], likely_user_params.get('movies'))
         self.assertEqual(user_in_db[11], likely_user_params.get('music'))
         self.assertEqual(user_in_db[12], likely_user_params.get('books'))
         self.assertEqual(user_in_db[13], likely_user_params.get('quotes'))
         self.assertEqual(user_in_db[14], likely_user_params.get('about'))
         self.assertEqual(user_in_db[15], likely_user_params.get('home_town'))
         self.assertEqual(user_in_db[16], likely_user_params.get('urls_photo'))
         self.assertEqual(user_in_db[17], likely_user_params.get('relation'))
         self.assertEqual(user_in_db[18], likely_user_params.get('common_friends'))
         self.assertEqual(user_in_db[19], likely_user_params.get('common_groups'))
         self.assertEqual(user_in_db[20], likely_user_params.get('points_auto'))
Ejemplo n.º 2
0
    def test_get_token_vk_on_login(self):
        id_vk = test_target_user.get("id_vk")
        login = test_target_user.get("login")
        token = test_target_user.get("token")

        sql_string = (
            f"INSERT INTO target_users_vk (id_vk, login, token) VALUES ({id_vk}, %s, %s) "
            f"ON CONFLICT (id_vk) DO UPDATE SET "
            f"login = EXCLUDED.login , token = EXCLUDED.token "
            f"RETURNING *")
        with self.connection_db:
            with self.connection_db.cursor() as cursor:
                cursor.execute(sql_string, [login, token])
        result = db_engine.get_token_vk_on_login(self.connection_db, login)
        self.assertEqual(result, token)
 def test_user_to_db_from_db(self):
     target_id_vk = test_target_user.get("id_vk")
     likely_id_vk = test_likely_user1.get('id_vk')
     likely_user_in = LikelyUser(likely_id_vk,**test_likely_user1)
     likely_user_in.user_to_db(self.connection_db, target_id_vk)
     likely_user_out = LikelyUser(0)
     likely_user_out.user_from_db(self.connection_db, target_id_vk, likely_id_vk)
     self.assertEqual(likely_user_in.user_vk_id, likely_user_out.user_vk_id)
     self.assertEqual(likely_user_in.first_name, likely_user_out.first_name)
     self.assertEqual(likely_user_in.last_name, likely_user_out.last_name)
     self.assertEqual(likely_user_in.sex, likely_user_out.sex)
     self.assertEqual(likely_user_in.city, likely_user_out.city)
     self.assertEqual(likely_user_in.age, likely_user_out.age)
     self.assertEqual(likely_user_in.activities, likely_user_out.activities)
     self.assertEqual(likely_user_in.interests, likely_user_out.interests)
     self.assertEqual(likely_user_in.movies, likely_user_out.movies)
     self.assertEqual(likely_user_in.music, likely_user_out.music)
     self.assertEqual(likely_user_in.books, likely_user_out.books)
     self.assertEqual(likely_user_in.quotes, likely_user_out.quotes)
     self.assertEqual(likely_user_in.about, likely_user_out.about)
     self.assertEqual(likely_user_in.urls_photo, likely_user_out.urls_photo)
     self.assertEqual(likely_user_in.relation, likely_user_out.relation)
     self.assertEqual(likely_user_in.common_friends, likely_user_out.common_friends)
     self.assertEqual(likely_user_in.common_groups, likely_user_out.common_groups)
     self.assertEqual(likely_user_in.points_auto, likely_user_out.points_auto)
 def test_update_param_target_users(self):
     target_user = TargetUser(test_target_user.get('id_vk'), test_target_user.get('login'),
                              test_target_user.get('token'))
     with patch("vkinder.input", side_effect=["м", "Москва", "activities1, activities2",
                                              "interests1, interests2", "movies1, movies2",
                                              "music1, music2", "books1, books2", "quotes1, quotes2",
                                              "about1, about2", "home1, home2"]):
         with patch("vkinder.posintput", side_effect=[1, 55]):
             update_param_target_users(target_user, self.vk_api)
     self.assertEqual(target_user.sex, 2)
     self.assertEqual(target_user.city, 1)
     self.assertEqual(target_user.age, 55)
     self.assertEqual(target_user.activities, ["activities1", "activities2"])
     self.assertEqual(target_user.interests, ["interests1", "interests2"])
     self.assertEqual(target_user.movies, ["movies1", "movies2"])
     self.assertEqual(target_user.music, ["music1", "music2"])
     self.assertEqual(target_user.books, ["books1", "books2"])
     self.assertEqual(target_user.quotes, ["quotes1", "quotes2"])
     self.assertEqual(target_user.about, ["about1", "about2"])
     self.assertEqual(target_user.home_town, ["home1", "home2"])
 def test_spec_list(self):
     type_list = -1
     target_id_vk = test_target_user.get("id_vk")
     likely_id_vk = test_likely_user1.get("id_vk")
     for user_id in range(0, 10):
         test_likely_user1.update({"first_name": f"first name {user_id+1}", "last_name": f"last name {user_id+1}"})
         likely_user_in = LikelyUser(likely_id_vk+user_id, **test_likely_user1)
         likely_user_in.user_to_db(self.connection_db, target_id_vk, type_list)
     with patch("db_engine.input", return_value='n'):
         users_in_black = spec_list(self.connection_db, target_id_vk, [], type_list)
     self.assertEqual(len(users_in_black), 10)
Ejemplo n.º 6
0
    def test_get_id_vk_token_on_login(self):
        sql_string = (
            f"INSERT INTO target_users_vk (id_vk, login, token) VALUES ({test_target_user.get('id_vk')}, %s, %s) "
            f"ON CONFLICT (id_vk) DO UPDATE SET "
            f"login = EXCLUDED.login , token = EXCLUDED.token "
            f"RETURNING *")
        with self.connection_db:
            with self.connection_db.cursor() as cursor:
                cursor.execute(
                    sql_string,
                    [
                        test_target_user.get("login"),
                        test_target_user.get("token")
                    ],
                )

        result = db_engine.get_id_vk_token_on_login(
            self.connection_db, test_target_user.get("login"))
        self.assertEqual(result[0], test_target_user.get("id_vk"))
        self.assertEqual(result[1], test_target_user.get("token"))
 def test_search_users_of_parametr(self):
     current_target_user = TargetUser(test_target_user.get('id_vk'), 'login', 'token', **test_target_user)
     q_string = ''
     city = 1
     start_age = 25
     stop_age = 26
     count_search_max = 100
     sex = 1
     has_photo = 1
     status = [6, ]
     search_p = SearchParametr(
         q_string,
         city,
         start_age,
         stop_age,
         count_search_max,
         sex,
         has_photo,
         status
     )
     find_users = search_users_of_parametr(self.vk_api, search_p, current_target_user)
     for user in find_users:
         self.assertIsInstance(user, LikelyUser)
 def test_calculate_points_auto(self):
     target_user = TargetUser(test_target_user.get('id_vk'), test_target_user.get('login'),
                              test_target_user.get('token'), **test_target_user)
     likely_user = LikelyUser(test_likely_user1.get('id_vk'), **test_likely_user1)
     likely_user.calculate_points_auto(target_user)
     self.assertGreater(likely_user.points_auto, 100)
 def test_target_user(self):
     user_vk_id = test_target_user.get("id_vk")
     user_vk_login = test_target_user.get("login")
     user_vk_token = test_target_user.get("token")
     user_for_test = TargetUser(user_vk_id, user_vk_login, user_vk_token, **test_target_user)
     self.assertEqual(user_for_test.user_vk_id, user_vk_id)
     self.assertEqual(user_for_test.first_name, test_target_user.get("first_name"))
     self.assertEqual(user_for_test.last_name, test_target_user.get("last_name"))
     self.assertEqual(user_for_test.sex, test_target_user.get("sex"))
     self.assertEqual(user_for_test.city, test_target_user.get("city"))
     self.assertEqual(user_for_test.age, test_target_user.get("age"))
     self.assertEqual(user_for_test.activities, test_target_user.get("activities"))
     self.assertEqual(user_for_test.interests, test_target_user.get("interests"))
     self.assertEqual(user_for_test.movies, test_target_user.get("movies"))
     self.assertEqual(user_for_test.music, test_target_user.get("music"))
     self.assertEqual(user_for_test.quotes, test_target_user.get("quotes"))
     self.assertEqual(user_for_test.about, test_target_user.get("about"))
     self.assertEqual(user_for_test.home_town, test_target_user.get("home_town"))
Ejemplo n.º 10
0
 def test_insert_update_user_vk(self):
     user_param = dict(test_target_user)
     user_id_vk = user_param.pop("id_vk")
     user_param.pop("id")
     user_param.pop("login")
     user_param.pop("token")
     result = db_engine.insert_update_user_vk(self.connection_db,
                                              "users_vk", user_id_vk,
                                              **user_param)
     self.assertEqual(
         [
             result[1],
             result[2],
             result[3],
             result[4],
             result[5],
             result[6],
             result[7],
             result[8],
             result[9],
             result[10],
             result[11],
             result[12],
             result[13],
             result[14],
         ],
         [
             test_target_user.get("id_vk"),
             test_target_user.get("first_name"),
             test_target_user.get("last_name"),
             test_target_user.get("sex"),
             test_target_user.get("city"),
             test_target_user.get("age"),
             test_target_user.get("activities"),
             test_target_user.get("interests"),
             test_target_user.get("movies"),
             test_target_user.get("music"),
             test_target_user.get("books"),
             test_target_user.get("quotes"),
             test_target_user.get("about"),
             test_target_user.get("home_town"),
         ],
     )