<commit_before># -*- coding: utf-8 -*-
# http://google-styleguide.googlecode.com/svn/trunk/pyguide.html

from smsgw.tests import SmsgwIntegrationTestCase
from smsgw.resources.auth import datasets
from smsgw.models import User
from smsgw.extensions import db


class AuthResourceTest(SmsgwIntegrationTestCase):
    
    LOGIN_URN = '/api/1.0/auth/login/'

    def test_login_endpoint(self):
        """ Testing auth login POST endpoint """

        # invalid empty payload
        res = self.post(self.LOGIN_URN, data={})
        self.assert400(res)

        # invalid email format
        res = self.post(self.LOGIN_URN, 
                        data=datasets.login.INVALID_EMAIL_FORMAT)
        self.assert400(res)

        #  no password
        res = self.post(self.LOGIN_URN, data=datasets.login.NO_PASSWORD)
        self.assert400(res)

        # create users
        db.session.add_all([User(**item) for item in datasets.login.USERS])
        db.session.commit()

        # success login
        res = self.post(self.LOGIN_URN, data=datasets.login.VALID)
        self.assert200(res)
        self.assertIsNotNone(res.json['data']['token'])
        self.assertEqual(res.json['data']['email'], datasets.login.VALID['email'])

        # wrong password
        res = self.post(self.LOGIN_URN, data=datasets.login.INVALID)
        self.assert403(res)

        # not active
        res = self.post(self.LOGIN_URN, data=datasets.login.NOT_ACTIVE)<commit_msg>AuthResources: fixing tests<commit_after># -*- coding: utf-8 -*-
# http://google-styleguide.googlecode.com/svn/trunk/pyguide.html

from smsgw.tests import SmsgwIntegrationTestCase
from smsgw.resources.auth import datasets
from smsgw.models import User
from smsgw.extensions import db


class AuthResourceTest(SmsgwIntegrationTestCase):

    LOGIN_URN = '/api/1.0/auth/login/'

    def test_login_endpoint(self):
        """ Testing auth login POST endpoint """

        # invalid empty payload
        res = self.post(self.LOGIN_URN, data={})
        self.assert400(res)

        # invalid email format
        res = self.post(self.LOGIN_URN,
                        data=datasets.login.INVALID_EMAIL_FORMAT)
        self.assert400(res)

        #  no password
        res = self.post(self.LOGIN_URN, data=datasets.login.NO_PASSWORD)
        self.assert400(res)

        # create users
        db.session.add_all([User(**item) for item in datasets.login.USERS])
        db.session.commit()

        # success login
        res = self.post(self.LOGIN_URN, data=datasets.login.VALID)
        self.assert200(res)
        self.assertIsNotNone(res.json['data']['token'])

        # wrong password
        res = self.post(self.LOGIN_URN, data=datasets.login.INVALID)
        self.assert403(res)

        # not active
        res = self.post(self.LOGIN_URN, data=datasets.login.NOT_ACTIVE)
{'fraction_non_alphanumeric': 0.11486962649753348, 'fraction_numerical': 0.012684989429175475, 'mean_word_length': 2.6679586563307494, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4801698', 'n_tokens_mistral': 917, 'n_tokens_neox': 869, 'n_words': 157}