Ejemplo n.º 1
0
class AppTestCase(unittest.TestCase):
    def setUp(self):
        """Initialisez app and defines variables"""
        app.testing = True
        self.tester = app.test_client()
        self.database = DatabaseConnection()
        self.database.create_user_table()

        self.user = {
            'username': '',
            'email': '*****@*****.**',
            'password': '******',
            'role': 'user'
        }

    def tearDown(self):
        """Crashes down all initialized variables"""

        self.database.cursor.execute("DROP TABLE users")
        self.tester = None

    def test_user_register(self):
        user = {
            'username': '******',
            'email': '*****@*****.**',
            'password': '******',
            'role': 'user'
        }
        response = self.tester.post('api/v1/signup',
                                    content_type='application/json',
                                    data=json.dumps(user))
        message = json.loads(response.data.decode())

        self.assertEqual(201, response.status_code)
        self.assertIn("you have succesfully signed up", str(response.data))