]> git.parisson.com Git - mezzo.git/commitdiff
[Timesheet] : test case utils + util function to get nb of half days in worked week...
authorEmilie Zawadzki <zawadzki@ircam.fr>
Thu, 5 Jan 2017 18:03:05 +0000 (19:03 +0100)
committerEmilie Zawadzki <zawadzki@ircam.fr>
Thu, 5 Jan 2017 18:03:05 +0000 (19:03 +0100)
app/organization/core/no_db_settings.py [new file with mode: 0644]
app/organization/core/tests.py
app/organization/network/tests.py
app/organization/network/utils.py [new file with mode: 0644]

diff --git a/app/organization/core/no_db_settings.py b/app/organization/core/no_db_settings.py
new file mode 100644 (file)
index 0000000..bd41162
--- /dev/null
@@ -0,0 +1,7 @@
+# -*- coding: utf-8 -*-
+try:
+    from local_settings import *
+except ImportError:
+    pass
+# Test runner with no database creation
+TEST_RUNNER = 'organization.core.tests.NoDbTestRunner'
index fa8859d789ee53fe190f5692e5205748af39308a..85b5bf83da1186602ae9ee7cac8ec33fcef7230d 100644 (file)
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 from django.test import TestCase
+from django.test.runner import DiscoverRunner
 
-# Create your tests here.
+class NoDbTestRunner(DiscoverRunner):
+  """ A test runner to test without database creation """
+
+  def setup_databases(self, **kwargs):
+    """ Override the database creation defined in parent class """
+    pass
+
+  def teardown_databases(self, old_config, **kwargs):
+    """ Override the database teardown defined in parent class """
+    pass
index fa8859d789ee53fe190f5692e5205748af39308a..43ddb800c6ef2ec149d47918ad1f2ed7cc8899c5 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
 
-from django.test import TestCase
+from django.test import SimpleTestCase
+import datetime
+from organization.network.utils import get_nb_half_days_by_period
 
-# Create your tests here.
+class NbOfHalfDaysInPeriodTestCase(SimpleTestCase):
+
+    def setUp(self):
+        self.date_from = datetime.date(2016,12,1)
+        self.date_to = datetime.date(2016,12,31)
+
+    def test_nbhalf_half_days(self):
+
+        expected = {
+          "monday_am": 4,
+          "monday_pm": 4,
+          "tuesday_am": 4,
+          "tuesday_pm": 4,
+          "wednesday_am": 4,
+          "wednesday_pm": 4,
+          "thursday_am": 5,
+          "thursday_pm": 5,
+          "friday_am": 5,
+          "friday_pm": 5,
+        }
+
+        result = get_nb_half_days_by_period(self.date_from, self.date_to)
+        self.assertEquals(result, expected)
diff --git a/app/organization/network/utils.py b/app/organization/network/utils.py
new file mode 100644 (file)
index 0000000..ec47083
--- /dev/null
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+import pandas as pd
+
+def get_nb_half_days_by_period(date_from, date_to):
+    day_list = pd.date_range(date_from, date_to).tolist()
+    day_dict = {
+      "monday_am": 0,
+      "monday_pm": 0,
+      "tuesday_am": 0,
+      "tuesday_pm": 0,
+      "wednesday_am": 0,
+      "wednesday_pm": 0,
+      "thursday_am": 0,
+      "thursday_pm": 0,
+      "friday_am": 0,
+      "friday_pm": 0,
+    }
+    for day in day_list :
+        if day.dayofweek == 0:
+            day_dict['monday_am'] += 1
+            day_dict['monday_pm'] += 1
+        if day.dayofweek == 1:
+            day_dict['tuesday_am'] += 1
+            day_dict['tuesday_pm'] += 1
+        if day.dayofweek == 2:
+            day_dict['wednesday_am'] += 1
+            day_dict['wednesday_pm'] += 1
+        if day.dayofweek == 3:
+            day_dict['thursday_am'] += 1
+            day_dict['thursday_pm'] += 1
+        if day.dayofweek == 4:
+            day_dict['friday_am'] += 1
+            day_dict['friday_pm'] += 1
+
+    return day_dict