def test_NAT_value_of_opened_session_is_updated_overtime_if_IN_swipe_is_corrected( self): user1 = UserFactory() swipe1 = SwipeFactory(user=user1, swipe_type="IN") swipe2 = SwipeFactory( # correction of swipe1 user=user1, swipe_type="IN", correction_of_swipe=swipe1, datetime=swipe1.datetime + timedelta(seconds=1), ) nat_1 = swipe2.session.get_not_assigned_duration() sleep(1) # sleep creates needed time difference (better method?) nat_2 = swipe2.session.get_not_assigned_duration() self.assertNotEqual(nat_1, nat_2)
def test_admin_can_swipe_user_out(self): user1 = UserFactory.create(is_staff=True) user2 = UserFactory.create() self.browser.get(self.server_url) swipe = SwipeFactory(user=user2, swipe_type="IN") self.login_by_form(user1.username, "password", self.browser) self.wait_for_element_with_name("OUTUSER") self.browser.find_element_by_name('OUTUSER').click() WebDriverWait(self.browser, 3).until( EC.alert_is_present(), 'Timed out waiting for PA creation ' + 'confirmation popup to appear.') self.browser.switch_to_alert().accept() self.browser.get(self.server_url + "/logout/") self.login_by_form(user2.username, "password", self.browser) self.wait_for_element_with_name("IN")
def test_swipe_edit_form(self): form_data = {"datetime": timezone.now()} form = SwipeEditForm(data=form_data, instance=self.swipe2) self.assertTrue(form.is_valid()) form_data["datetime"] -= timedelta(seconds=1) form = SwipeEditForm(data=form_data, instance=self.swipe2) self.assertFalse(form.is_valid()) swipe = SwipeFactory(user=self.user, swipe_type="IN") form_data["datetime"] += timedelta(hours=1) form = SwipeEditForm(data=form_data, instance=self.swipe2) self.assertFalse(form.is_valid())
def test_user_can_look_up_his_sessions_months(self): user = UserFactory.create() swipe = SwipeFactory(user=user, swipe_type="IN", datetime=timezone.now() - timedelta(hours=24 * 32)) swipe = SwipeFactory(user=user, swipe_type="OUT", datetime=timezone.now() - timedelta(hours=24 * 31)) swipe = SwipeFactory(user=user, swipe_type="IN", datetime=timezone.now() + timedelta(hours=1)) swipe = SwipeFactory(user=user, swipe_type="OUT", datetime=timezone.now() + timedelta(hours=2)) swipe = SwipeFactory(user=user, swipe_type="IN", datetime=timezone.now() + timedelta(hours=24 * 31)) swipe = SwipeFactory(user=user, swipe_type="OUT", datetime=timezone.now() + timedelta(hours=24 * 32)) self.assertEqual(Session.objects.count(), 3) for session in Session.objects.all(): self.browser.get(self.server_url) self.login_by_form(user.username, "password", self.browser) session_url = "{0}/sessions/{1}/{2}/{3:0>2}/".format( self.server_url, user.username, session.get_date().year, session.get_date().month, ) self.browser.get(session_url) try: self.browser.find_element_by_link_text("Detail") except NoSuchElementException: self.fail( "Can't find Detail on page {}, session date: {}".format( session_url, session.get_date(), )) finally: self.browser.get(self.server_url + "/logout/") self.assertIn(self.server_url + "/login/", self.browser.current_url)
def test_there_should_be_no_session_long_time_ago(self): user = UserFactory.create() swipe = SwipeFactory(user=user, swipe_type="IN") self.browser.get(self.server_url) self.login_by_form(user.username, "password", self.browser) self.assertEqual(Session.objects.count(), 1) SESSION_URL = self.server_url + "/sessions/" + user.username + "/2014/06/" self.browser.get(SESSION_URL) self.assertEqual(SESSION_URL, self.browser.current_url) try: element = self.browser.find_element_by_link_text("Detail") except NoSuchElementException: pass else: self.fail("There are sessions!") finally: self.browser.get(self.server_url + "/logout/") self.assertIn(self.server_url + "/login/", self.browser.current_url)
def setUp(self): self.user = UserFactory() self.swipe1 = SwipeFactory(user=self.user, swipe_type="IN") self.swipe2 = SwipeFactory(user=self.user, swipe_type="OUT")
def test_get_swipe_before(self): self.assertFalse(Swipe.objects.get(id=1).get_last_swipe_same_user()) self.assertEqual(1, Swipe.objects.get(id=2).get_last_swipe_same_user().id) user1, user2 = UserFactory(), UserFactory() swipe1 = SwipeFactory(swipe_type="IN", user=user1) swipe2 = SwipeFactory(swipe_type="IN", user=user2) swipe3 = SwipeFactory(swipe_type="OUT", user=user1) swipe4 = SwipeFactory(swipe_type="OBR", user=user2) swipe5 = SwipeFactory(swipe_type="OBR", user=user2, correction_of_swipe=swipe4) swipe7 = SwipeFactory(swipe_type="FBR", user=user2) swipe8 = SwipeFactory(swipe_type="OUT", user=user2) self.assertFalse(swipe1.get_last_swipe_same_user()) self.assertFalse(swipe2.get_last_swipe_same_user()) self.assertEqual(swipe5.id, swipe7.get_last_swipe_same_user().id) self.assertEqual(swipe1.id, swipe3.get_last_swipe_same_user().id) #testing swipe after so we dont have to repeat initialization self.assertEqual(swipe5.id, swipe2.get_next_swipe_same_user().id)
def test_cant_break_swipes_integrity(self): """ Only some sequences of swipes are allowed (IN after IN is not allowed and so on) """ def create_swipe(type, offset, id): return Swipe.objects.create(id=id, user=User.objects.get(id=1), datetime=timezone.now() + timedelta(hours=offset), swipe_type=type) #we are testing swipes if every last swipe in tupple exists SWIPE_SEQUENCE = [ ( "IN", "IN", ), ( "OBR", "OBR", ), ( "FBR", "FBR", ), ( "OTR", "OTR", ), ( "FTR", "FTR", ), ( "OUT", "OUT", ), ("FTR", ), ("FBR", ), ( "IN", "FTR", ), ("FBR", ), ] offset, id = 50, 50 for tuple_assert in SWIPE_SEQUENCE: try: for swipe_type in tuple_assert: create_swipe(swipe_type, offset, id) offset, id = offset + 1, id + 1 self.fail("It should be imposible to write this swipe_type") except ValueError: pass self.assertFalse(Swipe.objects.filter(id=id)) user1 = UserFactory() swipe1 = SwipeFactory(user=user1, swipe_type="IN") swipe2 = SwipeFactory(user=user1, swipe_type="OUT") swipe3 = SwipeFactory( user=user1, swipe_type="IN", correction_of_swipe=swipe1, datetime=swipe1.datetime - timedelta(seconds=1), ) #this should be posiible because last swipe is correction swipe4 = SwipeFactory(user=user1, swipe_type="IN")