def setUpData(self): self.past_match = PastMatchFactory.create(home_team='Bordo', away_team='Chelsea') self.past_match2 = PastMatchFactory.create(home_team='Bordo', away_team='Ajax') self.past_match3 = PastMatchFactory.create(home_team='Chelsea', away_team='Ajax', home_score=None, away_score=None) self.future_match = FutureMatchFactory.create(home_team='Ajax', away_team='Barcelona', datetime="2047-01-09 05:04+00:00") self.user1 = UserFactory.create(username='******') self.user2 = UserFactory.create(username='******') self.bets = [ [ BetFactory.create(match=self.future_match, user=self.user1, home_score=2, away_score=1), BetFactory.create(match=self.future_match, user=self.user2, home_score=4, away_score=0), ], # future match [ None, BetFactory.create(match=self.past_match, user=self.user2, home_score=2, away_score=0), ], # past match [ BetFactory.create(match=self.past_match2, user=self.user1, home_score=1, away_score=3), BetFactory.create(match=self.past_match2, user=self.user2, home_score=0, away_score=0), ], [ None, BetFactory.create(match=self.past_match3, user=self.user2, home_score=0, away_score=0), ] ] self.past_match.set_score(home_score=2, away_score=0) self.past_match2.set_score(home_score=0, away_score=0)
def test_check_user_permissions(self): account = AccountFactory.create() user_1 = UserFactory.create(account=account) user_2 = UserFactory.create(account=account) flight = FlightFactory.create() self.assertFalse(flight.check_user_permissions(user_1), 'no fly permissions') self.assertFalse(flight.check_user_permissions(user_2), 'no fly permissions') user_1.user_permissions.add(Permission.objects.get(codename='can_fly')) delattr(user_1, '_perm_cache') self.assertTrue(flight.check_user_permissions(user_1), 'can fly permissions') self.assertFalse(flight.check_user_permissions(user_2), 'no fly permissions') user_2.user_permissions.add(Permission.objects.get(codename='can_fly')) delattr(user_2, '_perm_cache') user_1.user_permissions.add(Permission.objects.get(codename='can_book_promo_flights')) delattr(user_1, '_perm_cache') promo_flight = FlightFactory.create(flight_type=Flight.TYPE_PROMOTION) self.assertTrue(flight.check_user_permissions(user_1), 'regular flight') self.assertTrue(flight.check_user_permissions(user_2), 'regular flight') self.assertTrue(promo_flight.check_user_permissions(user_1), 'promo flight') self.assertFalse(promo_flight.check_user_permissions(user_2), 'promo flight nope')
def test_match_update_bets_calls_set_result_for_every_bet( self, mock_set_result): user1 = UserFactory.create() user2 = UserFactory.create() match = PastMatchFactory(home_score=1, away_score=2) bet1 = BetFactory(match=match, user=user1) BetFactory(match=match, user=user2) match.update_bets() self.assertEqual(mock_set_result.call_count, 2)
def test_can_get_images_uploaded_by_a_user(self): """ Tests that the manager can get images specifically uploaded by a user. """ user_1 = UserFactory.create() user_2 = UserFactory.create() image_1a = ImageFactory.create(uploaded_by=user_1) image_1b = ImageFactory.create(uploaded_by=user_1) image_2a = ImageFactory.create(uploaded_by=user_2) self.assertEquals([image_1b, image_1a], list(Image.objects.filter_uploaded_by(user_1))) self.assertEquals([image_2a], list(Image.objects.filter_uploaded_by(user_2)))
def test_past_match_set_score_calls_calc_result_func_for_all_match_bets( self, mock_calc_bet_result): match = PastMatchFactory.create(home_score=None, away_score=None) user2 = UserFactory.create() BetFactory.create(home_score=4, away_score=3, match=match, user=self.user) BetFactory.create(home_score=2, away_score=1, match=match, user=user2) mock_calc_bet_result.return_value = 12 self.assertFalse(mock_calc_bet_result.called) match.set_score(home_score=2, away_score=1) self.assertEqual(mock_calc_bet_result.call_count, 2) mock_calc_bet_result.assert_has_calls([ call( home_bet=4, away_bet=3, home_score=2, away_score=1, shootout_winner=None, shootout_bet=None, ), call( home_bet=2, away_bet=1, home_score=2, away_score=1, shootout_winner=None, shootout_bet=None, ) ])
def test_should_return_event_owner(self): user = UserFactory.create(email='*****@*****.**') EventFactory.create(user=user, date=TOMORROW) event = Event.objects.incoming().first() self.assertEqual(event.user.get_name(), 'owner')
def setUp(self): super(YoutubeVideoBrowsingTestCase, self).setUp() self.user = UserFactory.create() self.client.login(**{ 'username': self.user.username, 'password': '******' })
def setUp(self): super(LatestImagesTestCase, self).setUp() self.user = UserFactory.create() self.client.login(**{ 'username': self.user.username, 'password': '******' })
def test_plan_restrictions(self): corp_account = CorporateAccountFactory.create() corp_user = UserFactory.create(account=corp_account) plan_1 = PlanFactory() plan_2 = PlanFactory() plan_3 = PlanFactory() account_1 = AccountFactory(plan=plan_1) account_2 = AccountFactory(plan=plan_2) account_3 = AccountFactory(plan=plan_3) user_1 = UserFactory(account=account_1) user_2 = UserFactory(account=account_2) user_3 = UserFactory(account=account_3) flight = FlightFactory(departure=arrow.now().replace(days=+12).datetime) self.assertTrue(flight.check_plan_restrictions(corp_user), 'always allow corp users') self.assertTrue(flight.check_plan_restrictions(user_1), 'no plan restrictions') self.assertTrue(flight.check_plan_restrictions(user_2), 'no plan restrictions') self.assertTrue(flight.check_plan_restrictions(user_3), 'no plan restrictions') FlightPlanRestrictionFactory(flight=flight, plan=plan_1, days=2) FlightPlanRestrictionFactory(flight=flight, plan=plan_2, days=12) FlightPlanRestrictionFactory(flight=flight, plan=plan_3, days=16) self.assertTrue(flight.check_plan_restrictions(corp_user), 'always allow corp users') self.assertFalse(flight.check_plan_restrictions(user_1), 'only 2 days out') self.assertTrue(flight.check_plan_restrictions(user_2), 'just now') self.assertTrue(flight.check_plan_restrictions(user_3), 'been good') flight.departure = arrow.now().replace(days=+13).datetime flight.save() self.assertTrue(flight.check_plan_restrictions(corp_user), 'always allow corp users') self.assertFalse(flight.check_plan_restrictions(user_1), 'only 2 days out') self.assertFalse(flight.check_plan_restrictions(user_2), 'just now') self.assertTrue(flight.check_plan_restrictions(user_3), 'been good') flight.departure = arrow.now().replace(days=+16).datetime flight.save() self.assertTrue(flight.check_plan_restrictions(corp_user), 'always allow corp users') self.assertFalse(flight.check_plan_restrictions(user_1), 'only 2 days out') self.assertFalse(flight.check_plan_restrictions(user_2), 'just now') self.assertTrue(flight.check_plan_restrictions(user_3), 'been good') flight.departure = arrow.now().replace(days=+17).datetime flight.save() self.assertTrue(flight.check_plan_restrictions(corp_user), 'always allow corp users') self.assertFalse(flight.check_plan_restrictions(user_1), 'only 2 days out') self.assertFalse(flight.check_plan_restrictions(user_2), 'just now') self.assertFalse(flight.check_plan_restrictions(user_3), 'been good')
def test_unauthenticated_can_login(self): self.user = UserFactory.create(username='******') self.password = self.user.password self.user.set_password(self.user.password) self.user.save() # Ugo goes to main page self.browser.get(self.live_server_url) # and see login button. login_link = self.browser.find_element_by_link_text('Login') # He clicks on it login_link.click() # and now he sees login form. self.wait_for(lambda: self.browser.find_element_by_id('id_username')) # He fills his credentials self.browser.find_element_by_id('id_username').send_keys( self.user.username) self.browser.find_element_by_id('id_password').send_keys(self.password) # and presses the only button self.browser.find_element_by_css_selector( 'input[type="submit"]').click() # and now he is redirected back to main page. # Now he sees logout button. self.wait_to_be_logged_in() # and logged in as text self.assertEqual( self.browser.find_element_by_css_selector('nav .navbar-text').text, f'Logged in as ugo')
def setUp(self): super(DeleteImageTestCase, self).setUp() user = UserFactory.create() self.client.login(**{ 'username': user.username, 'password': '******' }) self.image = ImageFactory()
def setUpTestData(cls): cls.future_match1 = FutureMatchFactory.create( datetime=timezone.now() + timezone.timedelta(days=2)) cls.future_match2 = FutureMatchFactory.create( datetime=timezone.now() + timezone.timedelta(days=1)) cls.future_match3 = FutureMatchFactory.create( datetime=timezone.now() + timezone.timedelta(days=3)) cls.user = UserFactory.create()
def test_can_logout(self): """ Tests the logout view. """ user = UserFactory.create() self.client.login(**{'username': user.username, 'password': '******'}) response = self.client.get(reverse('accounts:logout'), follow=True) self.assertRedirects(response, '{0}?next={1}'.format(reverse('accounts:login'), reverse('images:upload'))) self.assertFalse(response.context['user'].is_authenticated())
def try_auth(self, correct_login=True, correct_password=True): self.user = UserFactory.create() login = self.user.username if correct_login else 'user_not_exist' password = self.user.raw_password if correct_password else 'wrong_password' self.response = self.client.post('/accounts/login', data={ 'username': login, 'password': password })
def test_account_restrictions(self): corp_account = CorporateAccountFactory.create() corp_user = UserFactory.create(account=corp_account) account = AccountFactory.create() user = UserFactory.create(account=account) flight = FlightFactory() self.assertTrue(flight.check_account_restriction(corp_user), 'no account restrictriction') self.assertTrue(flight.check_account_restriction(user), 'no account restrictriction') flight.account_restriction.add(corp_account) self.assertTrue(flight.check_account_restriction(corp_user), 'corporate only flight') self.assertFalse(flight.check_account_restriction(user), 'corporate only flight') flight.account_restriction.add(account) self.assertTrue(flight.check_account_restriction(corp_user), 'corp and individual account good') self.assertTrue(flight.check_account_restriction(user), 'corp and individual account good')
def setUp(self): """ Initial settings """ self.user = UserFactory.create() self.token = Token.objects.get(user=self.user).key self.client.credentials(HTTP_AUTHORIZATION='Token ' + self.token) self.test_data = { 'first_name': 'Test', 'last_name': 'Test', 'phone': '380661204500', 'user': self.user, }
def test_can_login_and_redirect(self): """ Tests a user can login and be redirected back to the homepage. """ user = UserFactory.create() response = self.client.post( reverse('accounts:login'), data={'username': user.username, 'password': '******'}, follow=True, ) self.assertRedirects(response, reverse('images:upload')) self.assertTrue(response.context['user'].is_authenticated())
def test_past_match_set_score_set_all_match_bets_results(self): match = PastMatchFactory.create(home_score=None, away_score=None) user2 = UserFactory.create() BetFactory.create(home_score=4, away_score=3, match=match, user=self.user) BetFactory.create(home_score=2, away_score=1, match=match, user=user2) match.set_score(home_score=2, away_score=1) self.assertEqual(Bet.objects.all()[0].result, 6) self.assertEqual(Bet.objects.all()[1].result, 12)
def setUp(self): super(DownloadTestCase, self).setUp() self.user = UserFactory.create() self.client.login(**{'username': self.user.username, 'password': '******'})
def setUp(self): account = AccountFactory.create() self.user_1 = UserFactory.create(account=account) self.staff_1 = StaffUserFactory.create()
def setUpClass(cls): cls.user = UserFactory.create()
def setUp(self): self.user = UserFactory.create() self.client.force_login(self.user)
def test_user_factory_default_construction(self): UserFactory.create()
def setUp(self): self.user = UserFactory.create() self.event = EventFactory.create()
def setUp(self): self.user = UserFactory.create() self.event = EventFactory.create() self.ticket = TicketFactory.create(event=self.event)
def setUp(self): super(DeleteImageTestCase, self).setUp() user = UserFactory.create() self.client.login(**{'username': user.username, 'password': '******'}) self.image = ImageFactory()
def test_should_not_allow_to_create_duplicate_object(self): user = UserFactory.create() event = EventFactory.create() with self.assertRaises(IntegrityError): EventParticipantFactory.create_batch(2, event=event, user=user)
def setUpTestData(cls): cls.past_match = PastMatchFactory.create() cls.future_match = FutureMatchFactory.create() cls.user = UserFactory.create()
def setUp(self): super(YoutubeVideoBrowsingTestCase, self).setUp() self.user = UserFactory.create() self.client.login(**{'username': self.user.username, 'password': '******'})
def step_impl(context, username, password): context.user = UserFactory.create(username=username, password=password) context.path_vars.setdefault('users', []) context.path_vars['users'].append(context.user.id)
def setUpTestData(cls): cls.user = UserFactory.create()