| Total Complexity | 5 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 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 resources.models import find_by_username, return_all, insert_to_db |
||
| 9 | |||
| 10 | |||
| 11 | @pytest.mark.unittest |
||
| 12 | |||
| 13 | class AuthTest(unittest.TestCase): |
||
| 14 | |||
| 15 | def setUp(self): |
||
| 16 | self.app = create_app(config_name="testing") |
||
| 17 | self.client = self.app.test_client |
||
| 18 | self.reg = { "username": "[email protected]", "password": "test", "firstname": "susan", |
||
| 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 |