def test_user_unauthorized(self): # given client = HelperClient() self.assertFalse(client.is_authorised()) # when response = client.get(reverse('membership_expired')) self.assertRedirects(response=response, expected_url=f'/', fetch_redirect_response=False)
def setUp(self): self.client = HelperClient() self.existed_user: User = User.objects.create( email="*****@*****.**", membership_started_at=datetime.now() - timedelta(days=5), membership_expires_at=datetime.now() + timedelta(days=5), slug="ujlbu4")
def test_successful_redirect_with_query_params(self): # given self.client = HelperClient(user=self.new_user) self.client.authorise() # when with self.settings(JWT_PRIVATE_KEY=JWT_STUB_VALUES.JWT_PRIVATE_KEY): response = self.client.get(reverse('external_login'), data={'redirect': 'some-page?param1=value1'}) # then self.assertRegex(text=urljoin(response.request['PATH_INFO'], response.url), expected_regex='\/auth\/external\/some-page\?param1=value1&jwt=.*')
def test_membership_already_expired(self): # given new_user: User = User.objects.create( email="*****@*****.**", membership_started_at=datetime.now() - timedelta(days=10), membership_expires_at=datetime.now() - timedelta(days=5), slug="ujlbu4" ) client = HelperClient(user=new_user) client.authorise() # when response = client.get(reverse('membership_expired')) self.assertContains(response=response, text="Ваша клубная карта истекла", status_code=200)
def test_membership_expires_future(self): # given new_user: User = User.objects.create( email="*****@*****.**", membership_started_at=datetime.now() - timedelta(days=5), membership_expires_at=datetime.now() + timedelta(days=5), slug="ujlbu4" ) client = HelperClient(user=new_user) client.authorise() # when response = client.get(reverse('membership_expired')) self.assertRedirects(response=response, expected_url=f'/user/{new_user.slug}/', fetch_redirect_response=False)
def test_successful_flat_redirect(self): # given self.client = HelperClient(user=self.new_user) self.client.authorise() # when with self.settings(JWT_PRIVATE_KEY=JWT_STUB_VALUES.JWT_PRIVATE_KEY): response = self.client.get(reverse('external_login'), data={'redirect': 'some-page'}) # then self.assertRegex(text=urljoin(response.request['PATH_INFO'], response.url), expected_regex='\/auth\/external\/some-page\?jwt=.*') # check jwt url_params = response.url.split("?")[1] jwt_str = url_params.split("=")[1] payload = jwt.decode(jwt_str, verify=False) self.assertIsNotNone(payload) self.assertEqual(payload['user_slug'], self.new_user.slug) self.assertEqual(payload['user_name'], self.new_user.full_name) self.assertIsNotNone(payload['exp'])
def setUp(self): self.client = HelperClient() self.stub_patreon_response_oauth_token = { "access_token": "xxx-access-token", "refresh_token": "xxx-refresh-token", "expires_in": (datetime.utcnow() + timedelta(minutes=5)).microsecond, "scope": "scope??", "token_type": "Bearer" } self.stub_patreon_response_oauth_identity = None # doesn't need for now self.stub_parse_membership = Membership( platform=Platform.patreon, user_id=str(uuid.uuid4()), full_name="PatreonMember FullName", email="*****@*****.**", image="http://xxx.url", started_at=datetime.utcnow(), charged_at=None, expires_at=datetime.utcnow() + timedelta(days=100 * 365), lifetime_support_cents=400, currently_entitled_amount_cents=0 )
def setUp(self): self.client = HelperClient(user=self.new_user)
def setUp(self): self.client = HelperClient()
def setUp(self): self.client = HelperClient(user=self.new_user) self.broker.purge_queue()
def _authorized_client(user): client = HelperClient(user) if user is not None: client.authorise() return client
def setUp(self): self.client = HelperClient(user=None)
def setUp(self): self.client = HelperClient(user=self.existed_user)