Skip to content

Instantly share code, notes, and snippets.

@Newky
Created May 11, 2013 17:35
Show Gist options
  • Save Newky/5560737 to your computer and use it in GitHub Desktop.
Save Newky/5560737 to your computer and use it in GitHub Desktop.
Python dict weirdness.
# in settings.py
USERS: {
"alice": {
"alice_specific_information" : True
},
"bob": {
"bob_specific_information": True
}
}
# in test file
# In our circumstances, we were not guaranteed that alice's information
# would be available to us. Bobs information will always be available
# This is obviously not how unittests should be
# wrote, but its an imperfect world, so lets persevere.
def test_with_alice():
# get the username, highly annoying code.
username = settings.USERS.keys()[0]
# we are going to hit a certain django view and get a response.
# lets say this view gives us back the specific information for all users.
# can you see anything strange about this?
expected = {
str(username): {
"alice_specific_information" : True
},
"bob": {
"bob_specific_information": True
}
}
# do request
response = request.generic_request()
self.assertEquals(response, expected)
# what does expected look like when username is bob?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment