Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

API Changes and CO Timestamp support #4

Merged
merged 5 commits into from
Jan 29, 2018
Merged

API Changes and CO Timestamp support #4

merged 5 commits into from
Jan 29, 2018

Conversation

pradeepsixer
Copy link
Contributor

  1. Updated the API to support customizations by the API consumer
  2. Added support for Created and Closed Timestamps for Change Requests.

1. Updated the API to support customizations by the API consumer
2. Added support for Created and Closed Timestamps for Change Requests.
@codecov
Copy link

codecov bot commented Dec 27, 2017

Codecov Report

Merging #4 into master will increase coverage by 2.21%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master       #4      +/-   ##
==========================================
+ Coverage   92.04%   94.26%   +2.21%     
==========================================
  Files           6        7       +1     
  Lines          88      122      +34     
  Branches        5        6       +1     
==========================================
+ Hits           81      115      +34     
  Misses          7        7
Impacted Files Coverage Δ
django_snow/helpers/snow_request_handler.py 100% <100%> (ø) ⬆️
django_snow/models.py 95.23% <100%> (+0.5%) ⬆️
...ations/0002_changemgmt_add_createtime_closetime.py 100% <100%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b7b805...4c69e29. Read the comment docs.

Copy link
Contributor

@tarkatronic tarkatronic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm only reviewing the tests for a first pass, so that I can be sure they all make sense. To that end, I've made several comments about potential improvements.

One other thought I had is, does it perhaps make sense to split these tests out into multiple TestCase classes? That way there could be slightly better logical grouping of them, and more focused setUp() methods for each. Just a thought.

fake_resource = mock.MagicMock()
fake_resource.create.return_value = fake_insert_retval

self.mock_pysnow_client.resource.return_value = fake_resource
mock_pysnow.Client.return_value = self.mock_pysnow_client
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you get rid of the self.mock_pysnow_client? Since it's just an empty mock, it's not extremely useful, and it's making this logic a bit hard to follow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The self.mock_pysnow_client is being used in almost all the test cases. So instead of instantiating it every time within the test cases themselves, I think its better to have it at the setUp() method.

last_co = ChangeRequest.objects.last()

mock_get_snow_group_guid.assert_called_with('assignment_group')
self.assertEqual(co.pk, last_co.pk)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that two separate behaviors are being tested here; one to make sure that the return value of the create is as expected, and one to ensure that the object is added to the db. If that is the case, these should probably be split into separate tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the line 71 gone, it focuses only on checking the values of the persistence object created.

testapp/tests.py Outdated
expected_payload['type'] = 'normal'
expected_payload['assignment_group'] = 'bar'
expected_payload['short_description'] = 'Title'
expected_payload['description'] = 'Description'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is an OrderedDict actually necessary here? I'm guessing that assert_called_with cares about the order?

If so, this could be cleaned up a bit:

expected_payload = OrderedDict({
    'type': 'normal',
    'assignment_group': 'bar',
    'short_description': 'Title',
    'description': 'Description'
})

The same applies below for payload.

testapp/tests.py Outdated
expected_payload['short_description'] = 'Title'
expected_payload['description'] = 'Description'
expected_payload['type'] = 'standard'
expected_payload['assignment_group'] = 'bar'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same notes apply here about the OrderedDict.

testapp/tests.py Outdated
expected_payload['type'] = 'standard'
expected_payload['assignment_group'] = 'bar'

self.change_request_handler.group_guid_dict['assignment_group'] = 'bar'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not particularly a fan of this. This seems like a bit of a TDD anti-pattern. With TDD, tests should be written before code, but this line is quite obviously written after the code, because it implies, and requires, an intimate knowledge of the code internals. Is there a different way this can be controlled? Perhaps using django.test.override_settings?

testapp/tests.py Outdated
fake_resource = mock.MagicMock()
fake_resource.create.return_value = fake_insert_retval

self.mock_pysnow_client.resource.return_value = fake_resource
mock_pysnow.Client.return_value = self.mock_pysnow_client

with self.assertRaises(ChangeRequestException):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is checking for the exact same exception as above, generated by the same method call, I think this should also verify that the proper error message is being raised, with six.assertRaisesRegex().

testapp/tests.py Outdated
self.mock_pysnow_client.resource.return_value = fake_resource
mock_pysnow.Client.return_value = self.mock_pysnow_client

with self.assertRaises(ChangeRequestException):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same notes about the assert apply here.

testapp/tests.py Outdated

def test_get_snow_group_guid_cached_result(self, mock_pysnow):
self.change_request_handler.group_guid_dict['foo'] = 'bar'
self.assertEqual(self.change_request_handler.get_snow_group_guid('foo'), 'bar')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test has the same code smell as I mentioned above with needing to have intimate knowledge of the inner workings of the code. I think it would be better to mock the pysnow result, and ensure that pysnow is only called on the first attempt to retrieve the guid. This same technique should probably be used in other tests. In fact, this could even justify the continued use of self.mock_pysnow_client, since that would be functionality which would be necessary for many of the tests.

@tarkatronic
Copy link
Contributor

This PR fixes #2

1. Replaced usage of OrderedDict usage with dictionary.
2. Rewritten test cases that required internal working knowledge.
3. assertRaises replaced with assertRaisesRegex
@tarkatronic
Copy link
Contributor

The updates look great! Aside from one issue: assertRaisesRegex doesn't exist in Python 2.7; you will need to use the six module for this. That also means that you'll need to add it to the deps section in tox.ini.

Added 'six' package for assertRaisesRegex shim for Python 2.7
@tarkatronic tarkatronic merged commit b2e4732 into master Jan 29, 2018
@tarkatronic tarkatronic deleted the issue1 branch January 29, 2018 23:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants