Exemplo n.º 1
0
    def test_reconnect_make_proposal_success(self):
        client1 = socketio.test_client(
            self.app, flask_test_client=self.app.test_client())
        client1.connect('/game')
        client2 = socketio.test_client(
            self.app, flask_test_client=self.app.test_client())
        client2.connect('/game')
        client3 = socketio.test_client(
            self.app, flask_test_client=self.app.test_client())
        client3.connect('/game')
        client4 = socketio.test_client(
            self.app, flask_test_client=self.app.test_client())
        client4.connect('/game')
        client5 = socketio.test_client(
            self.app, flask_test_client=self.app.test_client())
        client5.connect('/game')

        result1 = client1.emit('create_game', {'username': '******'},
                               namespace='/game',
                               callback=True)
        result2 = client2.emit('join_game', {
            'username': '******',
            'game_id': result1['game']['id']
        },
                               namespace='/game',
                               callback=True)
        result3 = client3.emit('join_game', {
            'username': '******',
            'game_id': result1['game']['id']
        },
                               namespace='/game',
                               callback=True)
        result4 = client4.emit('join_game', {
            'username': '******',
            'game_id': result1['game']['id']
        },
                               namespace='/game',
                               callback=True)
        result5 = client5.emit('join_game', {
            'username': '******',
            'game_id': result1['game']['id']
        },
                               namespace='/game',
                               callback=True)
        print(client1.get_received())
        self.assertTrue(
            client1.emit('start_game', {'game_id': result1['game']['id']},
                         namespace='/game',
                         callback=True) == 'Game started')
        game1 = client1.get_received(namespace='/game')[-1]['args'][0]
        old_leader = game1['details']['leader_id']
        client1.emit('update_session', {
            'sid': result1['sid'],
            'game_id': result1['game']['id']
        },
                     namespace='/game')
        game2 = client1.get_received(namespace='/game')[-1]['args'][0]
        self.assertTrue(game2['details']['leader_id'] == old_leader)
Exemplo n.º 2
0
 def test_disconnect(self):
     with mock.patch("app.emit_all_messages"):
         client1 = socketio.test_client(app)
         client2 = socketio.test_client(app)
         client1.disconnect()
         received = client2.get_received()
         self.assertEqual("user count changed", received[0]["name"])
         self.assertEqual(0, received[0]["args"][0]["users"])
         client2.disconnect()
Exemplo n.º 3
0
 def test_get_repo_tree(self):
     flask_test_client = app.test_client()
     socketio_test_client = socketio.test_client(
         app, flask_test_client=flask_test_client)
     expected_res = {
         'path':
         '.babelrc',
         'mode':
         '100644',
         'type':
         'blob',
         'sha':
         '13a92d0084ce3312cb0150d0229fb9fa823a8f6d',
         'size':
         65,
         'url':
         'https://api.github.com/repos/rudra-desai/Codelint/git/blobs/'
         '13a92d0084ce3312cb0150d0229fb9fa823a8f6d'
     }
     with patch('app.get_user_repo_tree') as mock_method:
         mock_method.return_value = mock_github_responses.tree_return
         socketio_test_client.emit(
             'get repo tree', {
                 'repo_url':
                 'https://api.github.com/repos/AnthonyTudorov/BST-and-AVL-Tree-Comparison',
                 'default_branch': 'master'
             })
         res = socketio_test_client.get_received()[1]["args"][0]["tree"][0]
         self.assertEqual(res, expected_res)
Exemplo n.º 4
0
def socket_client_end():
    app.config["TESTING"] = True
    all_games["TEST_GAME"] = Game("test_game")
    client = app.test_client()
    socket_client_end = socketio.test_client(app, flask_test_client=client)
    socket_client_end.emit("join", {"name": "TEST_GAME"})
    _ = socket_client_end.get_received()
    socket_client_end.emit("player_join", {
        "name": "TEST_GAME",
        "player_id": "p1"
    })
    _ = socket_client_end.get_received()
    socket_client_end.emit("player_join", {
        "name": "TEST_GAME",
        "player_id": "p2"
    })
    _ = socket_client_end.get_received()
    socket_client_end.emit("start_game", {"name": "TEST_GAME"})
    _ = socket_client_end.get_received()
    all_games["TEST_GAME"].tiles = ["A", "B", "C"]
    all_games["TEST_GAME"].tiles_remaining = 3
    time.sleep(1)
    socket_client_end.emit("peel", {"name": "TEST_GAME"})
    _ = socket_client_end.get_received()
    yield socket_client_end
Exemplo n.º 5
0
 def test_on_new_zip(self):
     with mock.patch("app.emit_all_recipes"):
         client = socketio.test_client(app)
         client.emit("new zipcode query", {"zip": "12345"})
         received = client.get_received()
         self.assertEqual("12345", received[-1]["args"][0])
         client.disconnect()
Exemplo n.º 6
0
    def test_lint_code_js(self):
        with patch('lint.eslint') as mock_eslint:
            mock_eslint.return_value = None
            res = lint.lint_code({
                'linter': 'eslint',
                'code': 'function test(){\nconsole.log("Hello")\n}',
                'uuid': 'testfile'
            })
            here = os.path.dirname(os.path.abspath(__file__))
            here = re.sub(r'tests\/.*', "", here).replace("tests", "")
            subdir = "userfiles"
            filepath = os.path.join(here, subdir, "testfile.js")
            file = open(filepath, "r")
            self.assertEqual(file.read(),
                             'function test(){\nconsole.log("Hello")\n}')

            flask_test_client = app.test_client()
            socketio_test_client = socketio.test_client(
                app, flask_test_client=flask_test_client)
            with patch('app.lint_code') as mock_method:
                mock_method.return_value = {'filename': 'testfile.js'}
                socketio_test_client.emit('lint', {})
                res = socketio_test_client.get_received(
                )[1]['args'][0]['filename']
                self.assertEqual(res, 'testfile.js')
Exemplo n.º 7
0
 def test_on_old_google_user(self):
     with mock.patch("app.emit_all_recipes"):
         client = socketio.test_client(app)
         client.emit('old google user', {})
         received = client.get_received()
         self.assertEqual('logout', received[-1]["args"][0]["logout"])
         client.disconnect()
Exemplo n.º 8
0
 def test_on_connect(self):
     with mock.patch("app.emit_all_recipes"):
         socketio_test_client = socketio.test_client(app)
         assert socketio_test_client.is_connected()
         received = socketio_test_client.get_received()
         self.assertEqual('Connected', received[-1]["args"][0]["test"])
         socketio_test_client.disconnect()
Exemplo n.º 9
0
def socket_client():
    app.config["TESTING"] = True
    all_games["TEST_GAME"] = Game("TEST_GAME", [ClueSetType.BASE])
    client = app.test_client()
    socket_client = socketio.test_client(app, flask_test_client=client)
    socket_client.emit("join", {"name": "TEST_GAME"})
    yield socket_client
Exemplo n.º 10
0
    def test_lint_code_py(self):
        with patch('lint.pylint') as mock_pylint:
            mock_pylint.return_value = None
            res = lint.lint_code({
                'linter': 'pylint',
                'code': 'def func():\n  print("Hello")',
                'uuid': 'testfile',
                'filename': 'testfile'
            }, {'styleguide': 'airbnb'})
            here = os.path.dirname(os.path.abspath(__file__))
            here = re.sub(r'tests\/.*', "", here).replace("tests", "")
            subdir = "userfiles"
            filepath = os.path.join(here, subdir, "testfile.py")
            file = open(filepath, "r")
            self.assertEqual(file.read(), 'def func():\n  print("Hello")')

            flask_test_client = app.test_client()
            socketio_test_client = socketio.test_client(app, flask_test_client=flask_test_client)
            with patch('app.lint_code') as mock_method:
                mock_method.return_value = {
                    'filename': 'testfile.py'
                }
                socketio_test_client.emit('lint', {'linter': 'pylint',
                'code': 'def func():\n  print("Hello")',
                'uuid': 'testfile','index': '0'})
                res = socketio_test_client.get_received()[1]['args'][0]['filename']
                self.assertEqual(res, 'testfile.py')
Exemplo n.º 11
0
 def test_store_state(self):
     flask_test_client = app.test_client()
     socketio_test_client = socketio.test_client(
         app, flask_test_client=flask_test_client)
     socketio_test_client.emit('store state', {'state': '123456789'})
     self.assertEqual(len(wholeApp.states), 1)
     self.assertEqual('123456789' in wholeApp.states, True)
     wholeApp.states = set()
Exemplo n.º 12
0
 def test_on_new_recipe(self):
     with mock.patch("app.emit_all_recipes"):
         client = socketio.test_client(app)
         assert client.is_connected()
         with mock.patch("db_queries.get_user_id", mocked_get_user_id):
             with mock.patch("db_queries.add_recipe", mocked_add_recipe):
                 client.emit("new recipe", TEST_NEW_RECIPE)
                 client.disconnect()
Exemplo n.º 13
0
    def setUp(self):
        """ Sets up test fixture. """
        app.config['TESTING'] = True
        self.setUpPyfakefs()
        self.http_client = app.test_client()
        self.ws_client = socketio.test_client(app)

        os.mkdir(app.config['UPLOAD_FOLDER'])
Exemplo n.º 14
0
 def test_connection(self):
     with mock.patch("app.emit_all_messages"):
         socketio_test_client = socketio.test_client(app)
         assert socketio_test_client.is_connected()
         received = socketio_test_client.get_received()
         self.assertEqual("user count changed", received[0]["name"])
         self.assertEqual(0, received[0]["args"][0]["users"])
         socketio_test_client.disconnect()
Exemplo n.º 15
0
 def test_logged_in(self):
     flask_test_client = app.test_client()
     socketio_test_client = socketio.test_client(app, flask_test_client=flask_test_client)
     with patch('app.session', mock_methods.mock_session), \
             patch('models.Users') as mock_models_data:
         socketio_test_client.emit('is logged in')
         res = socketio_test_client.get_received()[1]
         self.assertEqual(res["name"], "logged in status")
Exemplo n.º 16
0
 def test_on_new_user_page(self):
     with mock.patch("app.emit_all_recipes"):
         with mock.patch("db_queries.get_user", mocked_get_user):
             client = socketio.test_client(app)
             client.emit('user page', {'user_id': TEST_ID})
             received = client.get_received()
             self.assertEqual(TEST_ADD_USER["name"],
                              received[-1]["args"][0]["user"]['name'])
             client.disconnect()
Exemplo n.º 17
0
 def test_authorize(self):
     with mock.patch("app.emit_all_messages"):
         with mock.patch("app.update_user"):
             client1 = socketio.test_client(app)
             client1.emit("new google user", {"email": "test"})
             received = client1.get_received()
             self.assertEqual("user count changed", received[-1]["name"])
             self.assertEqual(1, received[-1]["args"][0]["users"])
             client1.disconnect()
Exemplo n.º 18
0
    def setUp(self):
        app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///:memory:"
        app.config["TESTING"] = True

        self.app = app
        self.client = socketio.test_client(self.app)
        self.db = db

        db.create_all()
def startBots(game):
    client = socketio.test_client(app)
    nachricht = {'gamename': game.name, 'Name': '', 'Haus': '', 'message': ''}
    for haus in game.spielbareHauser:
        if game.spiel['Spieler'][haus]['User'].name == '':
            nachricht['Name'] = 'bot'
            nachricht['Haus'] = haus
            print(haus)
            client.emit('join', nachricht)
Exemplo n.º 20
0
 def test_disconnect(self):
     flask_test_client = app.test_client()
     socketio_test_client = socketio.test_client(app, flask_test_client=flask_test_client)
     with patch('models.Users') as mock_models_data, \
             patch('app.db.session') as mock_add_db:
         mock_models_data.return_value = None
         mock_add_db.return_value = None
         wholeApp.states = set()
         socketio_test_client.disconnect()
         self.assertEqual(len(wholeApp.states), 0)
Exemplo n.º 21
0
 def test_on_new_message(self):
     with mock.patch("app.emit_all_messages", mocked_emit_all_messages):
         with mock.patch("app.add_message_to_db"):
             client = socketio.test_client(app)
             client.emit("new message input", {})
             received = client.get_received()
             self.assertEqual(MESSAGES_RECEIVED_CHANNEL, received[-1]["name"])
             allMessages = received[-1]["args"][0]["allMessages"]
             self.assertEqual("test-message", allMessages[0].message)
             client.disconnect()
Exemplo n.º 22
0
 def test_on_get_repos(self):
     flask_test_client = app.test_client()
     socketio_test_client = socketio.test_client(
         app, flask_test_client=flask_test_client)
     with patch('app.get_user_repos') as mock_method:
         mock_method.return_value = None
         socketio_test_client.emit('get repos')
         res = socketio_test_client.get_received()[1]
         self.assertEqual(res["name"], 'repos')
         self.assertEqual(res["args"], [])
Exemplo n.º 23
0
 def test_on_recipe_page(self):
     with mock.patch("app.emit_all_recipes"):
         with mock.patch("db_queries.get_user", mocked_get_user):
             with mock.patch("db_queries.get_recipe", mocked_get_recipe):
                 client = socketio.test_client(app)
                 client.emit('recipe page', {'id': 1})
                 received = client.get_received()
                 self.assertEqual(
                     TEST_RECIPE["title"],
                     received[-1]["args"][0]["recipe"]["title"])
                 client.disconnect
Exemplo n.º 24
0
 def test_auth_user(self):
     flask_test_client = app.test_client()
     socketio_test_client = socketio.test_client(
         app, flask_test_client=flask_test_client)
     socketio_test_client.emit('auth user', {
         'state': '123456789',
         'code': '987654321'
     })
     res = socketio_test_client.get_received()[1]["args"][0]["message"]
     self.assertEqual(res,
                      'state: 123456789 does not match any waiting states')
Exemplo n.º 25
0
 def test_emit_all_messages(self):
     with mock.patch("app.get_messages", mocked_get_messages):
         with mock.patch("app.get_user", mocked_get_user):
             client = socketio.test_client(app)
             emit_all_messages(MESSAGES_RECEIVED_CHANNEL)
             received = client.get_received()
             self.assertEqual(MESSAGES_RECEIVED_CHANNEL, received[-1]["name"])
             allMessages = received[-1]["args"][0]["allMessages"]
             self.assertEqual("test-message", allMessages[0][3])
             self.assertEqual("bot-test-message", allMessages[1][3])
             client.disconnect()
Exemplo n.º 26
0
 def test_on_new_search_with_tag(self):
     with mock.patch("app.emit_all_recipes"):
         client = socketio.test_client(app)
         assert client.is_connected()
         with mock.patch("db_queries.get_user", mocked_get_user):
             with mock.patch("db_queries.search_by_tag", mocked_search):
                 client.emit("new search input", TEST_SEARCH_BY_TAG)
                 received = client.get_received()
                 recipe_list = received[-1]["args"][0]["search_output"]
                 self.assertEqual(recipe_list[0]["servings"], 3)
                 client.disconnect()
Exemplo n.º 27
0
 def test_on_content_page(self):
     with mock.patch("db_queries.get_n_recipes",
                     mocked_db_queries_get_n_recipes):
         with mock.patch("db_queries.get_user", mocked_get_user):
             client = socketio.test_client(app)
             assert client.is_connected()
             client.emit("content page", {"content": "content"})
             received = client.get_received()
             recipe_list = received[-1]["args"][0]["all_display"]
             self.assertEqual(recipe_list[0]["servings"], 3)
             client.disconnect()
Exemplo n.º 28
0
 def setup_class(self):
     self.app = app.test_client()
     app.config['TESTING'] = True
     app.config['SQLALCHEMY_DATABASE_URI'] = config.SQLALCHEMY_TEST_DATABASE_URI
     db = SQLAlchemy(app)
     db.session.close()
     db.drop_all()
     db.create_all()
     db.event.remove(Committees, "after_insert", new_committee)
     self.socketio = socketio.test_client(app);
     self.socketio.connect()
Exemplo n.º 29
0
 def test_logged_out(self):
     flask_test_client = app.test_client()
     socketio_test_client = socketio.test_client(app, flask_test_client=flask_test_client)
     with patch('app.session', mock_methods.mock_session), \
             patch('models.Users') as mock_models_data, \
             patch('app.escape') as mock_escape, \
             patch('app.logout_user') as mock_logout:
         mock_escape.return_value = None
         mock_logout.return_value = None
         socketio_test_client.emit('logout')
         res = socketio_test_client.get_received()[1]
         self.assertEqual(res["name"], "logout")
Exemplo n.º 30
0
 def test_on_get_repos(self):
     flask_test_client = app.test_client()
     socketio_test_client = socketio.test_client(app, flask_test_client=flask_test_client)
     with patch('app.session', mock_methods.mock_session), \
             patch('app.escape') as mock_escape, \
             patch('app.get_user_repos') as mock_method:
         mock_escape.return_value = None
         mock_method.return_value = {}
         socketio_test_client.emit('get repos', {'index': '0'})
         res = socketio_test_client.get_received()[1]
         self.assertEqual(res["name"], 'repos')
         self.assertEqual(res["args"], [{'tab': '0'}])
Exemplo n.º 31
0
    def setUp(self):
        super().setUp()

        self.socketio_client = socketio.test_client(app)
        ProcessRepository.set_encoding_active(False)
        self.socketio_client.queue.clear()