Exemplo n.º 1
0
    def test_bad_parameters_room_endpoint(self):
        with app.test_client(self) as tester:
            response = tester.get('/room?room_type=Deluxe&ordering_type=T')
            self.assertEqual(response.status_code, 400)

            response = tester.get('/room?room_type=D&ordering_type=ASC')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.data, b'[]')
Exemplo n.º 2
0
    def test_bad_parameters_city_endpoint(self):
        with app.test_client(self) as tester:
            response = tester.get('/city?city_name=Bangkok&ordering_type=T')
            self.assertEqual(response.status_code, 400)

            response = tester.get('/city?city_name=A&ordering_type=ASC')
            self.assertEqual(response.status_code, 200)
            self.assertEqual(response.data, b'[]')
Exemplo n.º 3
0
 def test_output_from_room_endpoint(self):
     with app.test_client(self) as tester:
         response = tester.get('/room?room_type=Deluxe&ordering_type=DESC')
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.data, b'[["Ashburn", "21", "Deluxe", 7000], ["Amsterdam", "23", "Deluxe", 5000], ["Ashburn", "17", "Deluxe", 2800], ["Amsterdam", "26", "Deluxe", 2300], ["Amsterdam", "4", "Deluxe", 2200], ["Ashburn", "25", "Deluxe", 1900], ["Ashburn", "12", "Deluxe", 1800], ["Ashburn", "7", "Deluxe", 1600], ["Bangkok", "1", "Deluxe", 1000], ["Bangkok", "15", "Deluxe", 900], ["Bangkok", "11", "Deluxe", 60]]')
         
         response = tester.get('/room?room_type=Deluxe&ordering_type=ASC')
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.data, b'[["Bangkok", "11", "Deluxe", 60], ["Bangkok", "15", "Deluxe", 900], ["Bangkok", "1", "Deluxe", 1000], ["Ashburn", "7", "Deluxe", 1600], ["Ashburn", "12", "Deluxe", 1800], ["Ashburn", "25", "Deluxe", 1900], ["Amsterdam", "4", "Deluxe", 2200], ["Amsterdam", "26", "Deluxe", 2300], ["Ashburn", "17", "Deluxe", 2800], ["Amsterdam", "23", "Deluxe", 5000], ["Ashburn", "21", "Deluxe", 7000]]')
Exemplo n.º 4
0
 def test_output_from_city_endpoint(self):
     with app.test_client(self) as tester:
         response = tester.get('/city?city_name=Bangkok&ordering_type=DESC')
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.data, b'[["Bangkok", "14", "Sweet Suite", 25000], ["Bangkok", "18", "Sweet Suite", 5300], ["Bangkok", "8", "Superior", 2400], ["Bangkok", "6", "Superior", 2000], ["Bangkok", "1", "Deluxe", 1000], ["Bangkok", "15", "Deluxe", 900], ["Bangkok", "11", "Deluxe", 60]]')
         
         response = tester.get('/city?city_name=Bangkok&ordering_type=ASC')
         self.assertEqual(response.status_code, 200)
         self.assertEqual(response.data, b'[["Bangkok", "11", "Deluxe", 60], ["Bangkok", "15", "Deluxe", 900], ["Bangkok", "1", "Deluxe", 1000], ["Bangkok", "6", "Superior", 2000], ["Bangkok", "8", "Superior", 2400], ["Bangkok", "18", "Sweet Suite", 5300], ["Bangkok", "14", "Sweet Suite", 25000]]')
Exemplo n.º 5
0
    def test_rate_limiter(self):
        with app.test_client(self) as tester:
            for i in range(0, 10):
                response = tester.get('/city?city_name=Bangkok&ordering_type=ASC')
                self.assertEqual(response.status_code, 200)

            response = tester.get('/city?city_name=Bangkok&ordering_type=ASC')
            self.assertEqual(response.status_code, 429)

            time.sleep(5)

            response = tester.get('/city?city_name=Bangkok&ordering_type=ASC')
            self.assertEqual(response.status_code, 200)
Exemplo n.º 6
0
    def test_configure_room_default(self):
        with app.test_client(self) as tester:
            tester.post('/room/configure')
            for i in range(50):
                response = tester.get('/room?room_type=Deluxe&ordering_type=ASC')
                self.assertEqual(response.status_code, 200)

            response = tester.get('/room?room_type=Deluxe&ordering_type=ASC')
            self.assertEqual(response.status_code, 429)

            time.sleep(5)

            response = tester.get('/room?room_type=Deluxe&ordering_type=ASC')
            self.assertEqual(response.status_code, 200)
Exemplo n.º 7
0
    def test_configure_city_default(self):
        with app.test_client(self) as tester:
            tester.post('/city/configure')
            for i in range(50):
                response = tester.get('/city?city_name=Bangkok&ordering_type=ASC')
                self.assertEqual(response.status_code, 200)

            response = tester.get('/city?city_name=Bangkok&ordering_type=ASC')
            self.assertEqual(response.status_code, 429)

            time.sleep(5)

            response = tester.get('/city?city_name=Bangkok&ordering_type=ASC')
            self.assertEqual(response.status_code, 200)
Exemplo n.º 8
0
    def test_configure_room_with_params(self):
        with app.test_client(self) as tester:
            tester.post('/room/configure?interval_time=10&number_requests=2')
            for i in range(2):
                response = tester.get('/room?room_type=Deluxe&ordering_type=ASC')
                self.assertEqual(response.status_code, 200)

            response = tester.get('/room?room_type=Deluxe&ordering_type=ASC')
            self.assertEqual(response.status_code, 429)

            time.sleep(5)

            response = tester.get('/room?room_type=Deluxe&ordering_type=ASC')
            self.assertEqual(response.status_code, 200)

            time.sleep(10)

            for i in range(2):
                response = tester.get('/room?room_type=Deluxe&ordering_type=ASC')
                self.assertEqual(response.status_code, 200)
Exemplo n.º 9
0
 def test_index(self):
     with app.test_client(self) as tester:
         response = tester.get('/')
         self.assertEqual(response.status_code, 200)
from flask import request, jsonify
from Server import app

import pytest

#CRIAR ALUNO
with app.test_client() as c:
    aluno = {'ra': '1700072', 'nome': 'alex'}
    rv = c.post('/alunos', json=aluno)
    json_data = rv.get_json()
    assert aluno == json_data['Dados']

with app.test_client() as c:
    aluno = {'ra': '1700073', 'nome': 'dani'}
    rv = c.post('/alunos', json=aluno)
    json_data = rv.get_json()
    assert aluno == json_data['Dados']

#LISTAR ALUNO
with app.test_client() as c:
    aluno1 = {'ra': '1700072', 'nome': 'alex'}
    aluno2 = {'ra': '1700073', 'nome': 'dani'}
    alunos = [aluno1, aluno2]
    rv = c.get('/alunos')
    json_data = rv.get_json()
    assert alunos == json_data['Dados']
#criar forum
with app.test_client() as c:
    forum = {
        "ForumId": "1",
        "OwnerId": "1700072",
Exemplo n.º 11
0
 def setUp(self):
     # creates a test client
     server = Server()
     self.app = app.test_client()
     # propagate the exceptions to the test client
     self.app.testing = True