Exemple #1
0
    def test_auth_social_login(self):
        """Ensure registered social user can login"""
        email = self.data_generator.email()
        name = self.data_generator.full_name()
        username = self.data_generator.username()
        social_id = self.data_generator.identifier()
        response = add_user_into_db(email=email,
                                    name=name,
                                    username=username,
                                    social_id=social_id,
                                    social_type=SocialAuth.FACEBOOK,
                                    access_token=Cryptographic.token_urlsafe())

        data = json.loads(response.data.decode())
        self.assertEqual(
            data['message'],
            f'registered with {SocialAuth.FACEBOOK.value} and logged in')
        self.assertTrue(data['auth_token'])
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 201)

        response = add_user_into_db(email=email,
                                    name=name,
                                    username=username,
                                    social_id=social_id,
                                    social_type=SocialAuth.FACEBOOK,
                                    access_token=Cryptographic.token_urlsafe())

        data = json.loads(response.data.decode())
        self.assertEqual(data['message'],
                         f'logged in with {SocialAuth.FACEBOOK.value}')
        self.assertTrue(data['auth_token'])
        self.assertEqual(response.content_type, 'application/json')
        self.assertEqual(response.status_code, 200)
Exemple #2
0
def add_social_user(role: UserRole = UserRole.USER,
                    email: str = None,
                    username: str = None,
                    password: str = None) -> User:
    """
    Generates a fake social user to add in DB
    """
    if email is None:
        email = data_generator.email()
    if username is None:
        username = data_generator.email()
    if password is None:
        password = data_generator.email()

    user = User(email=email,
                username=username,
                password=password,
                name=data_generator.full_name(),
                created_at=datetime.now(),
                role=role,
                social_type=SocialAuth.FACEBOOK.value,
                social_id=data_generator.identifier(),
                social_access_token=Cryptographic.token_urlsafe())
    db.session.add(user)
    db.session.commit()
    return user
Exemple #3
0
 def _cryptographics(self, seed):
     return Cryptographic(seed=seed), Cryptographic(seed=seed)
Exemple #4
0
 def crypto(self):
     return Cryptographic()
Exemple #5
0
 def c2(self, seed):
     return Cryptographic(seed=seed)
def crypto():
    return Cryptographic()