def test_login_backend(self): self.code = LoginCode.create_code_for_user(self.user) self.assertEqual(len(self.code.code), 20) self.assertIsNotNone(authenticate(username=self.user.username, code=self.code.code)) self.assertEqual(LoginCode.objects.filter(user=self.user, code=self.code.code).count(), 0) authenticate(username=self.user.username) self.assertEqual(LoginCode.objects.filter(user=self.user).count(), 1) self.assertIsNone(LoginCode.create_code_for_user(self.inactive_user)) self.assertIsNone(authenticate(username=self.inactive_user.username))
def test_login_backend(self): self.code = LoginCode.create_code_for_user(self.user) self.assertEqual(len(self.code.code), 20) self.assertIsNotNone( authenticate(username=self.user.username, code=self.code.code)) self.assertEqual( LoginCode.objects.filter(user=self.user, code=self.code.code).count(), 0) authenticate(username=self.user.username) self.assertEqual(LoginCode.objects.filter(user=self.user).count(), 1) self.assertIsNone(LoginCode.create_code_for_user(self.inactive_user)) self.assertIsNone(authenticate(username=self.inactive_user.username))
def email_transport_companies(): DEFAULT_EMPTY_VALUE = 'Sin Datos' subject = 'En tucarga.cl te queremos conseguir carga. Actualiza tu perfil ahora' row_names = ( 'FNAME', 'LNAME', 'PNAME', 'HREF', 'ADDRESS', 'RUT', 'PHONE', ) transportcompanies = utils.get_model_from_csv(TransportCompany) site = directory_utils.get_api_site() update_url = reverse('profile-transportcompany') rows = [] for transportcompany in transportcompanies: userdirectories = \ transportcompany.company.userdirectory_set.all() for userdirectory in userdirectories: user = userdirectory.user company = userdirectory.company login_code = LoginCode.create_code_for_user( user=user, next=update_url) url = directory_utils.get_url(site, 'login-with-code', login_code.code) rows.append((user.email, user.full_name or DEFAULT_EMPTY_VALUE, '', company.name, url, company.address or DEFAULT_EMPTY_VALUE, company.business_number, userdirectory.phone or DEFAULT_EMPTY_VALUE, )) local_vars = {} print(rows) raw_input('Continuar?') for row in rows: detail = dict(zip(row_names, row[1:])) user = row[0] local_vars[user] = detail directory_utils.send_mail.delay( [user], template_name='transport-profile', subject=subject, local_vars=local_vars)
def setUp(self): self.client = client self.user = directory_factories.UserFactory(**USER_CREDENTIALS) self.login_code = LoginCode.create_code_for_user(self.user) self.company = directory_factories.CompanyFactory() directory_factories.UserDirectoryFactory( user=self.user, company=self.company) from_regions = Location.objects.filter( level=levels.CHILE['region'])[:1] to_regions = Location.objects.filter(level=levels.CHILE['region'])[14:] self.coverage = directory_factories.CoverageFactory( from_regions=from_regions, to_regions=to_regions) self.transportcompany = directory_factories.TransportCompanyFactory( company=self.company, coverage=[self.coverage])
def authenticate(self, username, code=None): try: user = User.objects.get(username=username) if not user.is_active: return None if code is None: return LoginCode.create_code_for_user(user) else: timestamp = datetime.now() - timedelta(seconds=getattr(settings, 'NOPASSWORD_LOGIN_CODE_TIMEOUT', 900)) login_code = LoginCode.objects.get(user=user, code=code, timestamp__gt=timestamp) user = login_code.user user.code = login_code login_code.delete() return user except (TypeError, User.DoesNotExist, LoginCode.DoesNotExist): return None
def test_post_only_owner(self): self.EXPECTED_STATUS = status.HTTP_404_NOT_FOUND transportcompany = directory_factories.TransportCompanyFactory( company=self.company) user = directory_factories.UserFactory(**INVALID_USER_CREDENTIALS) login_code = LoginCode.create_code_for_user(user) company = directory_factories.CompanyFactory() directory_factories.UserDirectoryFactory( user=user, company=company) directory_factories.TransportCompanyFactory(company=company) route = routes_factories.RouteExportFactory() rate = test_factories.RateExportFactory( route=route, transportcompany=transportcompany) url = reverse('rate-export-update', kwargs={'pk': rate.pk}) data = {'route': route.pk, 'amount': 100000, 'validity': models.RateAbstractBase.VALIDITY_90} self.login(login_code, user.email) self.assertPost(url, data)
def setUp(self): self.user = directory_factories.UserFactory(**USER_CREDENTIALS) self.login_code = LoginCode.create_code_for_user(self.user) self.company = directory_factories.CompanyFactory() directory_factories.UserDirectoryFactory( user=self.user, company=self.company)
def test_code_timeout(self): self.timeout_code = LoginCode.create_code_for_user(self.user) time.sleep(3) self.assertIsNone( authenticate(username=self.user.username, code=self.timeout_code.code))
def test_next_value(self): self.code = LoginCode.create_code_for_user(self.user, next='/secrets/') self.assertEqual(self.code.next, '/secrets/')
def test_code_timeout(self): self.timeout_code = LoginCode.create_code_for_user(self.user) time.sleep(3) self.assertIsNone(authenticate(username=self.user.username, code=self.timeout_code.code))