test_services.py 1.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
import pytest
import sqlite3
import os

from modules.signup.services import sign_up_user
from modules.signup.exceptions import SignUpError
from settings import (
    DATABASE_FILE,
    USER_INFOMATION_TABLE,
    initializing_database
)


def setup():
    #setting up database schema
    initializing_database()


def testing_setting_constants():
    # testing application constants
    assert DATABASE_FILE
    assert USER_INFOMATION_TABLE


def test_signup_operation():
    # test values
    user_info = {
        'email': 'abc@shanky.xyz',
        'password': 'mynewpass',
        'full_name': 'Shashank Kumar',
        'language':'English',
        'timezone': 'UTC+5:30',
    }

    # testing valid signup
    assert sign_up_user(**user_info)

    # testing invalid signup
    with pytest.raises(SignUpError):
        sign_up_user(**user_info)


def teardown():
    # deleting test values
    connection = sqlite3.connect(DATABASE_FILE)
    db_cursor = connection.cursor()
    db_cursor.execute('''
        DELETE FROM USERS WHERE USERS.email="abc@shanky.xyz"
    ''')
    connection.commit()
    connection.close()