--- /dev/null
+# -*- coding: utf-8 -*-
+try:
+ from local_settings import *
+except ImportError:
+ pass
+# Test runner with no database creation
+TEST_RUNNER = 'organization.core.tests.NoDbTestRunner'
# 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
# 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)
--- /dev/null
+# -*- 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