Skip to content

Commit

Permalink
feito validação para probabilidade de chuva
Browse files Browse the repository at this point in the history
  • Loading branch information
alexNeto committed Aug 4, 2019
1 parent 17b83a5 commit bb2f45b
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 8 deletions.
1 change: 0 additions & 1 deletion .env

This file was deleted.

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
[Ss]cripts
pyvenv.cfg
.venv
.env
venv/
.idea/
.vscode/
Expand Down
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: python
python:
- '3.6'
- '3.6'
- '3.7'
sudo: required
install:
- pip install -r requirements.txt
Expand Down
14 changes: 14 additions & 0 deletions api/services/weatherValidator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
def rain_probability(value):
try:
result = __validate_rain_probability(value)
except ValueError:
result = None
return result


def __validate_rain_probability(value):
to_validate = float(value)
if 0 <= to_validate <= 100:
return to_validate
elif str(to_validate).isdigit() and (0 <= float(to_validate) <= 100):
return float(to_validate)
4 changes: 2 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
from api.today_resume.today_resume import today_resume_blueprint

app = Flask(__name__)
# app.config["MONGO_URI"] = "mongodb://localhost:27017/ladaDatabase"
# mongo = PyMongo(app)
cors = CORS(app, resources={r"/*": {"origins": "*"}})

app.register_blueprint(today_resume_blueprint, url_prefix="/today_resume")
Expand All @@ -21,3 +19,5 @@ def hello_world():
if __name__ == '__main__':
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)


3 changes: 0 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
unidecode
lxml
mongo
pymongo
Flask-PyMongo
beautifulsoup4
Flask
flask_cors
Expand Down
Empty file added test/services/__init__.py
Empty file.
39 changes: 39 additions & 0 deletions test/services/weatherValidatorTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import unittest

from api.services.weatherValidator import rain_probability


class MyTestCase(unittest.TestCase):
def test_rain_probability_negative_integer(self):
self.assertEqual(None, rain_probability(-1))

def test_rain_probability_negative_float(self):
self.assertEqual(None, rain_probability(-1.1))

def test_rain_probability_negative_string(self):
self.assertEqual(None, rain_probability('-1'))

def test_rain_probability_over_100_integer(self):
self.assertEqual(None, rain_probability(101))

def test_rain_probability_over_100_float(self):
self.assertEqual(None, rain_probability(101.1))

def test_rain_probability_over_100_string(self):
self.assertEqual(None, rain_probability('101'))

def test_rain_probability_string_not_digit(self):
self.assertEqual(None, rain_probability('aaaaaa1212'))

def test_rain_probability_in_interval_integer(self):
self.assertEqual(12, rain_probability(12))

def test_rain_probability_in_interval_float(self):
self.assertEqual(12.34, rain_probability(12.34))

def test_rain_probability_in_interval_string(self):
self.assertEqual(54.121, rain_probability('54.121'))


if __name__ == '__main__':
unittest.main()
6 changes: 5 additions & 1 deletion test/sources/cptec/getter/cptec_api_getter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,9 @@ class CptecAPIGetterTest(unittest.TestCase):
def setUp(self):
self.__cptec_api_getter = CptecAPIGetter(-22.87216997446473, -48.44871995614285) # Botucatu - SP

def retrieving_data_from_api_test(self):
def test_retrieving_data_from_api(self):
self.assertIsNotNone(self.__cptec_api_getter.make_request())


if __name__ == '__main__':
unittest.main()

0 comments on commit bb2f45b

Please sign in to comment.