Пример #1
0
 def test_no_user_message(self):
     """
     testing of function parse_message with incorrect argument
     :return:
     """
     self.assertEqual(parse_message(NO_USER_MESSAGE),
                      INCORRECT_RESPONSE_400)
Пример #2
0
 def test_no_timestamp_message(self):
     """
     testing of function parse_message with incorrect argument
     :return:
     """
     self.assertNotEqual(parse_message(NO_TIMESTAMP_MESSAGE),
                         CORRECT_RESPONSE_200)
Пример #3
0
 def test_wrong_command_message(self):
     """
     testing of function parse_message with incorrect argument
     :return:
     """
     self.assertEqual(parse_message(WRONG_COMMAND_MESSAGE),
                      INCORRECT_RESPONSE_400)
Пример #4
0
 def test_wrong_user_account_message(self):
     """
     testing of function parse_message with incorrect argument
     :return:
     """
     self.assertNotEqual(parse_message(WRONG_USER_ACCOUNT_MESSAGE),
                         CORRECT_RESPONSE_200)
Пример #5
0
"""
module containes test server socket to test Easy Chat routine functions

"""

import json
import os
import sys
from socket import socket, AF_INET, SOCK_STREAM

sys.path.append(os.path.join(os.getcwd(), '..'))
from each_server import parse_message
from lib.routines import get_message, send_message
from lib.settings import MAX_CONNECTIONS, DEFAULT_PORT

print('Running test server')
each_server_socket = socket(AF_INET, SOCK_STREAM)
each_server_socket.bind(('', DEFAULT_PORT))
each_server_socket.listen(MAX_CONNECTIONS)

while True:
    each_client_socket, each_client_address = each_server_socket.accept()
    try:
        client_message = get_message(each_client_socket)
        server_response = parse_message(client_message)
        send_message(each_client_socket, server_response)
        each_client_socket.close()
    except (ValueError, json.JSONDecodeError):
        print('Incorrect client message received.')
        each_client_socket.close()
Пример #6
0
 def test_correct_message(self):
     """
     testing of function parse_message with correct argument
     :return:
     """
     self.assertEqual(parse_message(CORRECT_MESSAGE), CORRECT_RESPONSE_200)