Exemplo n.º 1
0
 def test_delete_invalid_id(self):
     with app.test_request_context():
         url = url_for('noticias_put_delete', noticia_id='abc')
         resp = self.client.delete(url, headers=self.default_headers)
     assert resp.status_code == 400
     resp_data = resp.get_json()
     assert resp_data['code'] == INVALID_NOTICIA_ID
Exemplo n.º 2
0
 def test_post_invalid_struct(self):
     data = {"titulo1": "teste", "autor": {"nome": "teste 123"}}
     with app.test_request_context():
         url = url_for('noticias_get_post')
         resp = self.client.post(url,
                                 data=json.dumps(data),
                                 headers=self.default_headers)
     assert resp.status_code == 400
     assert resp.get_json()['code'] == INVALID_STRUCTURE
 def test_update(self):
     with app.test_request_context():
         url = url_for('noticias_put_delete', noticia_id=self.noticia_id)
         resp = self.client.put(url,
                                data=json.dumps(self.new_data),
                                headers=self.default_headers)
     assert resp.status_code == 200
     resp_data = resp.get_json()
     self.created_data.append(resp_data)
     assert resp_data['titulo'] == self.new_data['titulo']
     assert resp_data['texto'] == self.new_data['texto']
     assert resp_data['autor']['nome'] == self.new_data['autor']['nome']
 def test_get(self):
     val_to_test = 'teste search'
     with app.test_request_context():
         url = url_for('noticias_get_post')
         resp = self.client.get(
             f'{url}?val={val_to_test}', headers=self.default_headers
         )
     assert resp.status_code == 200
     resp_data = resp.get_json()
     assert resp_data[0]['titulo'] == self.data['titulo']
     assert resp_data[0]['texto'] == self.data['texto']
     assert resp_data[0]['autor']['nome'] == self.data['autor']['nome']
Exemplo n.º 5
0
 def test_fail_post_autor_number(self):
     data = {
         "titulo": "teste",
         "texto": "teste teste",
         "autor": {
             "nome": "teste 123"
         }
     }
     with app.test_request_context():
         url = url_for('noticias_get_post')
         resp = self.client.post(url,
                                 data=json.dumps(data),
                                 headers=self.default_headers)
     assert resp.status_code == 400
     assert resp.get_json()['code'] == FIELD_NOT_SHOULD_HAS_INT_VALUE
Exemplo n.º 6
0
 def test_format_money_route(self):
     with app.test_request_context('/format_money?number=10'):
         assert flask.request.path == '/format_money'
         assert flask.request.args['number'] == '10'
Exemplo n.º 7
0
 def test_home_page_route(self):
     with app.test_request_context('/'):
         assert flask.request.path == '/'
Exemplo n.º 8
0
 def test_delete(self):
     with app.test_request_context():
         url = url_for('noticias_put_delete', noticia_id=self.noticia_id)
         resp = self.client.delete(url, headers=self.default_headers)
     assert resp.status_code == 200
     assert len(NoticiaModel.objects(id=self.noticia_id)) == 0