Esempio n. 1
0
 def test_phone_query_performance(self):
     user = User.objects(uid=dldyddn0624_uid).first()
     start = pendulum.now().int_timestamp
     contact = Contact.objects(owner=user).first()
     phone_users = User.objects(phone__in=contact.phones).only("id").all()
     user_ids = set([str(user.id) for user in phone_users])
     end = pendulum.now().int_timestamp
     elapsed = end - start
     print(elapsed)
     self.assertEqual(elapsed < 1, True)
     self.assertEqual(len(user_ids), 505)
    def test_list_real_time_users(self, mock_verify_id_token):
        """There must not be recommended users because anotehr users contacts contain my number."""
        mock_time = pendulum.datetime(2020, 5, 21, 12)
        pendulum.set_test_now(mock_time)

        # insert user_1
        mock_verify_id_token.return_value = dict(uid=mock_user_1["uid"])
        response_1 = create_user_1(self.app)
        self.assertEqual(response_1.status_code, 200)
        # insert user_2
        mock_verify_id_token.return_value = dict(uid=mock_user_2["uid"])
        response_2 = create_user_2(self.app)
        self.assertEqual(response_2.status_code, 200)

        User.objects(uid=mock_user_1["uid"]).update(available=True)
        User.objects(uid=mock_user_2["uid"]).update(available=True)

        user_1 = User.objects(uid=mock_user_1["uid"]).first()
        user_2 = User.objects(uid=mock_user_2["uid"]).first()

        response = self.app.get("/users/{user_id}/real_time".format(
            user_id=response_1.get_json().get("_id")),
                                headers=dict(uid=mock_user_1["uid"]),
                                content_type="application/json")
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.get_json()), 1)

        Contact.objects(owner=user_2).update(
            phones=[user_1.phone],
            last_updated_at=pendulum.now().int_timestamp)
        response = self.app.get("/users/{user_id}/real_time".format(
            user_id=response_1.get_json().get("_id")),
                                headers=dict(uid=mock_user_1["uid"]),
                                content_type="application/json")
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.get_json()), 0)