Пример #1
0
    def test_login_with_invalid_user(self, fetch_mock):
        fetch_mock.side_effect = NoResultFound

        data = {
            'email': '*****@*****.**',
            'password': '******',
        }

        with self.assertRaises(InvalidLogin):
            login_user(data)
Пример #2
0
    def test_login_with_wrong_password(self, fetch_mock):
        db_user = User(
            id=1,
            name='Joao',
            email='*****@*****.**',
            password='******'
        )
        fetch_mock.return_value = db_user

        data = {
            'email': '*****@*****.**',
            'password': '******',
        }

        with self.assertRaises(InvalidLogin):
            login_user(data)
Пример #3
0
def login():

    try:
        data = request.json
        data['email']
        data['password']
    except (KeyError, BadRequest):
        return api_error('Request Inválida: formato dos parâmetros inválido', 400)

    try:
        user_data = login_user(data)
    except ValidationError as exc:
        return api_error(exc.message, 400)

    return user_data, 200
Пример #4
0
    def test_sucessful_login(self, token_mock, fetch_mock):

        token_mock.return_value = 'mocked token'

        db_user = User(
            id=1,
            name='Joao',
            email='*****@*****.**',
            password=hashlib.sha1('1234').hexdigest(),
            created=datetime(2016, 2, 15, 19, 20, 21),
            modified=datetime(2016, 2, 15, 19, 20, 21),
            last_login=datetime(2016, 2, 15, 19, 20, 21),
        )
        fetch_mock.return_value = db_user

        data = {
            'email': '*****@*****.**',
            'password': '******',
        }

        user_data = login_user(data)

        self.assertEqual(hashlib.sha1(user_data['token']).hexdigest(), db_user.token)
        self.assertEqual(datetime(2016, 2, 15, 19, 20, 21), db_user.last_login)