def test_delete_user(self): hypertrack_id = str(uuid.uuid4()) response = MockResponse(204, json.dumps({})) with patch.object(User, '_make_request', return_value=response) as mock_request: user = User(id=hypertrack_id, **DUMMY_USER) user.delete() mock_request.assert_called_once_with( 'delete', 'https://api.hypertrack.com/api/v1/users/{hypertrack_id}/'. format(hypertrack_id=hypertrack_id))
def test_v2_user_mileage(self): hypertrack_id = str(uuid.uuid4()) response = MockResponse(200, json.dumps({})) data = {} with patch.object(User, '_make_request', return_value=response) as mock_request: user = User(id=hypertrack_id, **DUMMY_USER) user.mileage() mock_request.assert_called_once_with( 'get', 'https://api.hypertrack.com/api/v1/users/{hypertrack_id}/mileage/' .format(hypertrack_id=hypertrack_id), data=data)
def test_user_cancel_actions(self): hypertrack_id = str(uuid.uuid4()) response = MockResponse(200, json.dumps(DUMMY_USER)) data = {} with patch.object(User, '_make_request', return_value=response) as mock_request: user = User(id=hypertrack_id, **DUMMY_USER) user.cancel_actions(**data) mock_request.assert_called_once_with( 'post', 'https://api.hypertrack.com/api/v1/users/{hypertrack_id}/cancel_actions/' .format(hypertrack_id=hypertrack_id), data=data)
def test_list_user(self): response = MockResponse(200, json.dumps({'results': [DUMMY_USER]})) with patch.object(User, '_make_request', return_value=response) as mock_request: users = User.list() mock_request.assert_called_once_with( 'get', 'https://api.hypertrack.com/api/v1/users/', params={})
def test_create_user(self): response = MockResponse(201, json.dumps(DUMMY_USER)) with patch.object(User, '_make_request', return_value=response) as mock_request: user = User.create(**DUMMY_USER) mock_request.assert_called_once_with( 'post', 'https://api.hypertrack.com/api/v1/users/', data=DUMMY_USER, files=None) self.assertEqual(user.name, DUMMY_USER.get('name'))
def test_update_user(self): hypertrack_id = str(uuid.uuid4()) response = MockResponse(200, json.dumps(DUMMY_USER)) with patch.object(User, '_make_request', return_value=response) as mock_request: user = User(id=hypertrack_id, **DUMMY_USER) user.city = 'New York' user.photo = 'http://photo-url.com/' user.save() mock_request.assert_called_once_with( 'patch', 'https://api.hypertrack.com/api/v1/users/{hypertrack_id}/'. format(hypertrack_id=hypertrack_id), data={ 'city': user.city, 'photo': user.photo }, files=None)