zaidmehdi commited on
Commit
37aa982
1 Parent(s): ab7587a

replace requests with flask test_client()

Browse files
Files changed (1) hide show
  1. tests/model_tests.py +8 -7
tests/model_tests.py CHANGED
@@ -1,10 +1,11 @@
1
- import requests
2
  import unittest
3
 
 
 
4
 
5
  class TestClassifier(unittest.TestCase):
6
  def setUp(self) -> None:
7
- self.API_URL = "http://localhost:5000/classify"
8
  self.dialects = ['Egypt', 'Iraq', 'Saudi_Arabia', 'Mauritania', 'Algeria', 'Syria',
9
  'Oman', 'Tunisia', 'Lebanon', 'Morocco', 'Djibouti','United_Arab_Emirates','Kuwait',
10
  'Libya', 'Bahrain', 'Qatar', 'Yemen', 'Palestine', 'Jordan', 'Somalia', 'Sudan']
@@ -18,17 +19,17 @@ class TestClassifier(unittest.TestCase):
18
  def test_response(self):
19
  """Test if the response of the /classify API endpoint is correct"""
20
  request_data = {"text": "حاجة حلوة اكيد"}
21
- response = requests.post(self.API_URL, json=request_data)
22
  self.assertEqual(response.status_code, 200)
23
- self.assertIn("class", response.json())
24
- self.assertIn(response.json()["class"], self.dialects)
25
 
26
  def test_model_output(self):
27
  """Test that the model correctly classifies obvious dialects"""
28
  for country, text, in self.test_set.items():
29
  request_data = {"text": text}
30
- response = requests.post(self.API_URL, json=request_data)
31
- self.assertEqual(response.json()["class"], country)
32
 
33
 
34
  if __name__ == "__main__":
 
 
1
  import unittest
2
 
3
+ from src.main import app
4
+
5
 
6
  class TestClassifier(unittest.TestCase):
7
  def setUp(self) -> None:
8
+ self.client = app.test_client()
9
  self.dialects = ['Egypt', 'Iraq', 'Saudi_Arabia', 'Mauritania', 'Algeria', 'Syria',
10
  'Oman', 'Tunisia', 'Lebanon', 'Morocco', 'Djibouti','United_Arab_Emirates','Kuwait',
11
  'Libya', 'Bahrain', 'Qatar', 'Yemen', 'Palestine', 'Jordan', 'Somalia', 'Sudan']
 
19
  def test_response(self):
20
  """Test if the response of the /classify API endpoint is correct"""
21
  request_data = {"text": "حاجة حلوة اكيد"}
22
+ response = self.client.post("/classify", json=request_data)
23
  self.assertEqual(response.status_code, 200)
24
+ self.assertIn("class", response.json)
25
+ self.assertIn(response.json["class"], self.dialects)
26
 
27
  def test_model_output(self):
28
  """Test that the model correctly classifies obvious dialects"""
29
  for country, text, in self.test_set.items():
30
  request_data = {"text": text}
31
+ response = self.client.post("/classify", json=request_data)
32
+ self.assertEqual(response.json["class"], country)
33
 
34
 
35
  if __name__ == "__main__":