<reponame>mrdulin/python-codelab
from unittest.mock import patch
import unittest
import json
from member import member


class TestMember(unittest.TestCase):
    @patch('member.requests.post')
    def test_member_success(self, mock_post):
        mock_post.return_value.status_code = 201
        mock_post.return_value.json.return_value = 'mock response'

        actual = member(1)
        self.assertEqual(actual, 'mock response')
        mock_post.assert_called_once_with(
            'http://localhost:3000/api/some/url/part',
            data=json.dumps({
                "Login": 'python',
                "Password": '<PASSWORD>',
            }),
            headers={"Accept": "application/json"}
        )

    @patch('member.requests.post')
    def test_member_success(self, mock_post):
        mock_post.return_value.status_code = 400
        self.assertRaises(ValueError, member, 1)


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

from unittest.mock import patch
import unittest
import json
from member import member


class TestMember(unittest.TestCase):
    @patch('member.requests.post')
    def test_member_success(self, mock_post):
        mock_post.return_value.status_code = 201
        mock_post.return_value.json.return_value = 'mock response'

        actual = member(1)
        self.assertEqual(actual, 'mock response')
        mock_post.assert_called_once_with(
            'http://localhost:3000/api/some/url/part',
            data=json.dumps({
                "Login": 'python',
                "Password": '<PASSWORD>',
            }),
            headers={"Accept": "application/json"}
        )

    @patch('member.requests.post')
    def test_member_success(self, mock_post):
        mock_post.return_value.status_code = 400
        self.assertRaises(ValueError, member, 1)


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