<commit_before>from .imports import *
import json
import unittest
from headers import envi, databases
from app import app, User


class TestAuthentication(unittest.TestCase):

    def setUp(self):
        envi("Testing")
        databases.create_all()
        self.app = app.test_client()

    def tearDown(self):
        databases.session.remove()
        databases.drop_all()

    def test_inputs_required_for_registration(self):
        payload = dict(username="<EMAIL>")
        response = self.app.post("/api/v1/auth/register", data=json.dumps(payload), headers={'Content-Type': 'application/json'})
        res_message = json.loads(response.data.decode('Utf-8'))
        message = res_message['message']
        self.assertEqual(message, "Both username and password are required")

    def test_validates_user_inputs_for_registration(self):
        payload = dict(username="twikedzi", password="<PASSWORD>")
        response = self.app.post("/api/v1/auth/register", data=json.dumps(payload), headers={'Content-Type': 'application/json'})
        res_message = json.loads(response.data.decode('Utf-8'))
        message = res_message['message']
        self.assertEqual(message, "Username must be a valid email address")

    def test_user_can_register(self):
        payload = dict(username="<EMAIL>", password="<PASSWORD>")
        response = self.app.post("/api/v1/auth/register", data=json.dumps(payload), headers={'Content-Type': 'application/json'})
        res_message = json.loads(response.data.decode('Utf-8'))
        message = res_message['message']
        self.assertEqual(response.status_code, 201)
        self.assertEqual(message, "User created")

    def test_no_ducplicated_usernames(self):
        payload = dict(username="<EMAIL>", password="<PASSWORD>")
        User(payload).store()
        response = self.app.post("/api/v1/auth/register", data=json.dumps(payload), headers={'Content-Type': 'application/json'})
        res_message = json.loads(response.data.decode('Utf-8'))
        message = res_message['message']<commit_msg>implement passing test logic for empty username and password<commit_after>from .imports import *
import json
import unittest
from headers import envi, databases
from app import app, User


class TestAuthentication(unittest.TestCase):

    def setUp(self):
        envi("Testing")
        databases.create_all()
        self.app = app.test_client()

    def tearDown(self):
        databases.session.remove()
        databases.drop_all()

    def test_inputs_required_for_registration(self):
        payload = dict(username="<EMAIL>")
        response = self.app.post("/api/v1/auth/register", data=json.dumps(payload), headers={'Content-Type': 'application/json'})
        res_message = json.loads(response.data.decode('Utf-8'))
        message = res_message['message']
        self.assertEqual(message, "Both username and password are required")

    def test_validates_user_inputs_for_registration(self):
        payload = dict(username="twikedzi", password="<PASSWORD>")
        response = self.app.post("/api/v1/auth/register", data=json.dumps(payload), headers={'Content-Type': 'application/json'})
        res_message = json.loads(response.data.decode('Utf-8'))
        message = res_message['message']
        self.assertEqual(message, "Username must be a valid email address")

    def test_checks_for_empty_username_during_registration(self):
        payload = dict(username="", password="<PASSWORD>")
        response = self.app.post("/api/v1/auth/register", data=json.dumps(payload), headers={'Content-Type': 'application/json'})
        self.assertEqual(400, response.status_code)
        res_message = json.loads(response.data.decode('Utf-8'))
        message = res_message['message']
        self.assertEqual(message, "Both username and password are required")

    def test_checks_for_empty_password_during_registration(self):
        payload = dict(username="<EMAIL>", password="")
        response = self.app.post("/api/v1/auth/register", data=json.dumps(payload), headers={'Content-Type': 'application/json'})
        self.assertEqual(400, response.status_code)
        res_message = json.loads(response.data.decode('Utf-8'))
        message = res_message['message']
        self.assertEqual(message, "Both username and password are required")


    def test_user_can_register(self):
        payload = dict(username="<EMAIL>", password="<PASSWORD>")
        response = self.app.post("/api/v1/auth/register", data=json.dumps(payload), headers={'Content-Type': 'application/json'})
        res_message = json.loads(response.data.decode('Utf-8'))
        message = res_message['message']
        self.assertEqual(response.status_code, 201)
        self.assertEqual(message, "User created")

    def test_no_ducplicated_usernames(self):
        payload = dict(username="<EMAIL>", password="<PASSWORD>")
        User(payload).store()
        response = self.app.post("/api/v1/auth/register", data=json.dumps(payload), headers={'Content-Type': 'application/json'})
        res_message = json.loads(response.data.decode('Utf-8'))
        message = res_message['message']
{'fraction_non_alphanumeric': 0.14216163583252192, 'fraction_numerical': 0.0062317429406037, 'mean_word_length': 3.854442344045369, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, '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': '6869215', 'n_tokens_mistral': 1500, 'n_tokens_neox': 1484, 'n_words': 263}