Passed
Push — develop ( 1e8194...5d1e13 )
by Antony
44s
created

build.tests.test_auth.AuthTest.test_user_authentication()   A

Complexity

Conditions 3

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
nop 1
1
import os
2
import unittest
3
import pytest
4
import psycopg2
5
6
from flask import json, request, jsonify
7
from run import create_app
8
from tests.models import find_by_username, return_all, insert_to_db, create_tables
9
10
11
@pytest.mark.unittest
12
13
class AuthTest(unittest.TestCase):
14
    
15
    def setUp(self):
16
        self.app = create_app('testing')
17
        self.client = self.app.test_client
18
        self.reg =  { "username": "[email protected]", "password": "test", "firstname": "Mary",
19
 	                    "lastname": "Wekesa" }
20
        self.login = {"username":"[email protected]","password":"test"}
21
22
        #with self.app.app_context():
23
           
24
25
    def tearDown(self):
26
        pass
27
    
28
29
    def test_encode_auth_token(self):
30
       """ 
31
       user = UserAuth(
32
            email = '[email protected]',
33
            password = 'test'
34
        )
35
        auth_token = user.encode_auth_token(user.id)
36
        """
37
38
    
39
    def test_registration_endpoint(self):
40
        """Test signup/register users endpoint"""
41
        res = self.client().post('/api/v1/auth/signup', data = self.reg)
42
        self.assertEquals(res.status_code, 200)
43
        self.assertIn('mary', str(res.data))
44
    
45
    
46
    def test_login_endpoint(self):
47
        """Test login endpoint"""
48
        res = self.client().post('/api/v1/auth/login', data = self.login)
49
        self.assertEquals(res.status_code,200)
50
        
51