aboutsummaryrefslogtreecommitdiffstats
path: root/keystone-moon/keystone/tests/moon/func/test_func_moon_auth.py
blob: 56132609f5d795591003259769ec1f742e0302c4 (plain)
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
# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
# This software is distributed under the terms and conditions of the 'Apache-2.0'
# license which can be found in the file 'LICENSE' in this package distribution
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.

import unittest
import json
import requests


class AuthTest(unittest.TestCase):

    def setUp(self):
        self.data_auth = {
            "username": "",
            "password": ""
        }

    def tearDown(self):
        pass

    def test_authz(self):
        self.data_auth['username'] = 'admin'
        self.data_auth['password'] = ''
        req = requests.post("http://localhost:5000/moon/auth/tokens",
                            json=self.data_auth,
                            headers={"Content-Type": "application/json"}
                            )
        self.assertIn(req.status_code, (200, 201))
        result = req.json()
        self.assertIn("token", result.keys())
        self.assertEqual(result["token"], None)

        self.data_auth['username'] = 'admin'
        self.data_auth['password'] = 'nomoresecrete'
        req = requests.post("http://localhost:5000/moon/auth/tokens",
                            json=self.data_auth,
                            headers={"Content-Type": "application/json"}
                            )
        self.assertIn(req.status_code, (200, 201))
        result = req.json()
        self.assertIn("token", result.keys())
        self.assertNotEqual(result["token"], None)

if __name__ == "__main__":
    unittest.main()