Beispiel #1
0
 def test_api_ping_endpoint_delegates_to_rpc_proxy(self, mock_rpc_proxy):
     mock_rpc = mock_rpc_proxy.return_value.__enter__.return_value
     mock_rpc.ping.return_value = {"message": "ping"}
     response = app.test_client().get('/ping')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, b'{"message": "ping"}')
     mock_rpc.ping.assert_called_once_with()
def test_post_no_content():
    client = app.test_client()
    url = '/AddMessage'
    data = {
        'application_id': 3,
        'sessionId': "www",
        'participants': ["avi", "moshe"],
    }
    x = client.post(url, data=json.dumps(data))
    response = client.post(url, data=json.dumps(data))
    assert response.get_data() == b'data not correct'
    assert response.status_code == 400
Beispiel #3
0
    def setUp(self):
        self.app = app.test_client()

        user1 = User(name="Name", surname="Surname", password="******", username="******")
        user2 = User(name="Ім'я", surname="Прізвище", password="******", username="******")

        db.session.add(user1)
        db.session.add(user2)

        db.session.commit()

        self.users_data = [(user1.username, user1.password), (user2.username, user2.password)]
def test_post_content_not_number():
    client = app.test_client()
    url = '/AddMessage'
    data = {
        'application_id': 5,
        'session_id': "ddd",
        'message_id': "12",
        'participants': ["avi", "moshe"],
        'content': [12]
    }
    x = client.post(url, data=json.dumps(data))
    response = client.post(url, data=json.dumps(data))
    assert response.get_data() == b'content must be string'
    assert response.status_code == 400
def test_post_participants_not_list():
    client = app.test_client()
    url = '/AddMessage'
    data = {
        'application_id': 5,
        'session_id': "ddd",
        'message_id': "ff",
        'participants': "avi,moshe",
        'content': "hello world"
    }
    x = client.post(url, data=json.dumps(data))
    response = client.post(url, data=json.dumps(data))
    assert response.get_data() == b'participants must be list'
    assert response.status_code == 400
Beispiel #6
0
    def setUp(self):
        """Define test variables and initialize app."""
        self.app = app
        self.client = app.test_client()
        self.database_name = "trivia_test"
        self.database_path = "postgresql:///trivia_test"
        setup_db(self.app, self.database_path)

        # binds the app to the current context
        with self.app.app_context():
            self.db = SQLAlchemy()
            self.db.init_app(self.app)
            # create all tables
            self.db.create_all()
def test_post_applicationId_empty():
    client = app.test_client()
    url = '/AddMessage'
    data = {
        'application_id': "",
        'session_id': "www",
        'message_id': "sss",
        'participants': ["avi", "moshe"],
        'content': "hello world"
    }
    x = client.post(url, data=json.dumps(data))
    response = client.post(url, data=json.dumps(data))
    assert response.get_data() == b'application_id cannot be empty'
    assert response.status_code == 400
def test_post_exist():
    client = app.test_client()
    url = '/AddMessage'
    data = {
        'application_id': 5,
        'session_id': "www",
        'message_id': "ddd",
        'participants': ["avi", "moshe"],
        'content': "hello world"
    }
    x = client.post(url, data=json.dumps(data))
    response = client.post(url, data=json.dumps(data))
    assert response.get_data() == b'message_id is alredy exist'
    assert response.status_code == 400
def test_post_succes():
    client = app.test_client()
    url = '/AddMessage'
    data = {
        'application_id': 3,
        'message_id': "aaa",
        'participants': ["avi", "moshe"],
        'session_id': "www",
        'content': "hello world"
    }
    response = client.post(url, data=json.dumps(data))
    assert response.get_data() == b'the message was added succesfully'
    assert response.status_code == 200

    url = '/AddMessage'
    data = {
        'application_id': 1,
        'message_id': "bbb",
        'participants': ["avi", "moshe"],
        'session_id': "www",
        'content': "hello world"
    }
    response = client.post(url, data=json.dumps(data))
    assert response.get_data() == b'the message was added succesfully'
    assert response.status_code == 200

    url = '/AddMessage'
    data = {
        'application_id': 1,
        'message_id': "ccc",
        'participants': ["avi", "moshe"],
        'session_id': "xxx",
        'content': "hello world"
    }
    response = client.post(url, data=json.dumps(data))
    assert response.get_data() == b'the message was added succesfully'
    assert response.status_code == 200

    url = '/AddMessage'
    data = {
        'application_id': 2,
        'message_id': "ddd",
        'participants': ["avi", "moshe"],
        'session_id': "zzz",
        'content': "hello world"
    }
    response = client.post(url, data=json.dumps(data))
    assert response.get_data() == b'the message was added succesfully'
    assert response.status_code == 200
def test_get_by_message():
    client = app.test_client()
    url = '/GetMessage?messageId=aaa'
    response = client.get(url)
    data = response.get_data()
    data = json.loads(data.decode())
    assert data["message_id"] == "aaa"
    assert response.status_code == 200

    url = '/GetMessage?messageId=5'
    response = client.get(url)
    data = response.get_data()
    data = json.loads(data.decode())
    assert data == {}
    assert response.status_code == 200
def test_get_by_session():
    client = app.test_client()
    url = '/GetMessage?sessionId=www'
    response = client.get(url)
    data = response.get_data()
    data = json.loads(data.decode())
    assert data.__len__() == 2
    assert response.status_code == 200

    url = '/GetMessage?sessionId=3'
    response = client.get(url)
    data = response.get_data()
    data = json.loads(data.decode())
    assert data.__len__() == 0
    assert response.status_code == 200
Beispiel #12
0
    def setUp(self):
        self.app = app.test_client()

        user1 = User(name="Name", surname="Surname", password="******", username="******")
        user2 = User(name="Ім'я", surname="Прізвище", password="******", username="******")
        user3 = User(name="Peter", surname="Peterson", password="******", username="******")
        user4 = User(name="John", surname="Johnson", password="******", username="******")

        db.session.add(user1)
        db.session.add(user2)
        db.session.add(user3)
        db.session.add(user4)

        db.session.commit()

        self.users_json = [user1.json(), user2.json(), user3.json(), user4.json()]
def test_get_by_application():
    client = app.test_client()
    url = '/GetMessage?applicationId=1'
    response = client.get(url)
    data = response.get_data()
    data = json.loads(data.decode())
    assert data.__len__() == 2
    assert response.status_code == 200

    url = '/GetMessage?applicationId="sss"'
    response = client.get(url)
    data = response.get_data()
    assert data == b'arguments not correct'
    assert response.status_code == 400

    url = '/GetMessage?applicationId=17'
    response = client.get(url)
    data = response.get_data()
    data = json.loads(data.decode())
    assert data.__len__() == 0
    assert response.status_code == 200
Beispiel #14
0
    def setUp(self):
        self.app = app.test_client()

        user1 = User(name="name",
                     surname="surname",
                     password="******",
                     username="******")
        user2 = User(name="name2",
                     surname="surname2",
                     password="******",
                     username="******")

        db.session.add(user1)
        db.session.add(user2)

        post1 = Post(author_id=user1.id, text="Directed by R. B. Weirde")
        post2 = Post(
            author_id=user1.id,
            text="My second post: I've just turned 18! Congrats to me!!!")
        post3 = Post(author_id=user2.id,
                     text="I think I`m very good at doing nothing")
        post4 = Post(author_id=user2.id, text="Йой, най буде")

        db.session.add(post1)
        db.session.add(post2)
        db.session.add(post3)
        db.session.add(post4)

        db.session.commit()

        self.posts_json = [
            post1.json(),
            post2.json(),
            post3.json(),
            post4.json()
        ]
        self.users_json = [user1.json(), user2.json()]
Beispiel #15
0
 def setUp(self):
     self.app = app.test_client()
Beispiel #16
0
 def test_api_root_returns_empty_body(self):
     response = app.test_client().get('/')
     assert response.status_code == 200
     assert response.data == b'Hello World!'
Beispiel #17
0
 def setUp(self):
     
     self.app = app.test_client()
     self.app.testing = True
Beispiel #18
0
 def setUp(self):
     self.service = app.test_client()
Beispiel #19
0
 def setUp(self):
     app.config['TESTING'] = True
     self.app = app.test_client()