test_integration.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:django-rest-messaging-centrifugo 作者: raphaelgyory 项目源码 文件源码
def setUpClass(cls):
        super(IntegrationTests, cls).setUpClass()
        # we do not display
        cls.display = Display(visible=0, size=(1024, 768))
        cls.display.start()
        cls.selenium = WebDriver()
        # we create a user
        password = "password"
        cls.user = User(username="UserForLiveTests")
        cls.user.set_password(password)
        cls.user.save()
        # we log him in
        # source http://stackoverflow.com/questions/22494583/login-with-code-when-using-liveservertestcase-with-django
        # we need a session
        session = SessionStore()
        session[SESSION_KEY] = cls.user.id
        session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
        session[HASH_SESSION_KEY] = cls.user.get_session_auth_hash()
        session.save()
        # the cookie dict
        cls.cookie = {
            'name': settings.SESSION_COOKIE_NAME,
            'value': session.session_key,
            'secure': False,
            'path': '/',
        }
        # we launch centrifugo
        cls.centrifugo = subprocess.Popen(["centrifugo --config=tests/config.json --port={0}".format(getattr(settings, "CENTRIFUGO_PORT", 8802))], stdout=subprocess.PIPE,
                                          shell=True, preexec_fn=os.setsid)
        # we create participants
        cls.participant1 = Participant.objects.create(id=cls.user.id)
        cls.participant2 = Participant.objects.create(id=2)
        cls.participant3 = Participant.objects.create(id=3)
        cls.participant4 = Participant.objects.create(id=4)
        # we create a fake request
        cls.request = RequestFactory()
        cls.request.rest_messaging_participant = cls.participant1
        # and wait for it to run
        time.sleep(4)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号