[chronojump-server] Unitary tests for person model
- From: Marcos Venteo Garcia <mventeo src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [chronojump-server] Unitary tests for person model
- Date: Tue, 20 Jun 2017 16:51:51 +0000 (UTC)
commit fe500c5f1dc8b98e66b246d8c7acb86694fc8369
Author: Marcos Venteo GarcĂa <mventeo gmail com>
Date: Tue Jun 20 18:51:21 2017 +0200
Unitary tests for person model
chronojumpserver/tests/test_person.py | 66 +++++++++++++++++++++++++++++++++
1 files changed, 66 insertions(+), 0 deletions(-)
---
diff --git a/chronojumpserver/tests/test_person.py b/chronojumpserver/tests/test_person.py
new file mode 100755
index 0000000..20d979c
--- /dev/null
+++ b/chronojumpserver/tests/test_person.py
@@ -0,0 +1,66 @@
+"""Unit tests for models."""
+import unittest
+from chronojumpserver.tests.fixtures import players
+from chronojumpserver.database import engine
+from chronojumpserver.models import Person
+from sqlalchemy.exc import IntegrityError, InvalidRequestError, OperationalError
+
+
+class TestPerson(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(cls):
+ """Create test data."""
+ engine.execute('delete from person')
+
+ @classmethod
+ def tearDownClass(cls):
+ """Nothing for the moment."""
+ pass
+
+ def test_create_a_new_person(self):
+ """Create a new person."""
+ p = Person(name='Player 1', height=170, weight=70,
+ rfid='111.111.111.111', imageName='player1.jpg')
+ p.add()
+
+ def test_get_byName(self):
+ """Get the person by name."""
+ p = Person.getByName('Player 1')
+ self.assertEqual(p.name, 'Player 1')
+
+ def test_player_name_cannot_be_duplicated(self):
+ """Person name cannot be duplicated."""
+ p = Person(name='Player 1', height=152, weight=67,
+ rfid='111.111.111.112', imageName='player1_1.jpg')
+
+ with self.assertRaises(InvalidRequestError):
+ p.add()
+
+ def test_height_is_required(self):
+ """Person cannot be saved without height."""
+ p = Person(name='Player 2', weight=70,
+ rfid='111.111.111.111', imageName='player2.jpg')
+
+ with self.assertRaises(OperationalError):
+ p.add()
+
+ def test_weight_is_required(self):
+ """Person cannot be saved without weight."""
+ p = Person(name='Player 3', height=170,
+ rfid='111.111.111.111', imageName='player3.jpg')
+
+ with self.assertRaises(InvalidRequestError):
+ p.add()
+
+ def test_rfid_is_required(self):
+ """Person cannot be saved without rfid."""
+ p = Person(name='Player 4', height=170, weight=70,
+ imageName='player4.jpg')
+
+ with self.assertRaises(InvalidRequestError):
+ p.add()
+
+
+if __name__ == "__main__":
+ unittest.main(verbosity=2)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]