Skip to content

Instantly share code, notes, and snippets.

@thepug
Created March 27, 2012 17:28
Show Gist options
  • Save thepug/2218203 to your computer and use it in GitHub Desktop.
Save thepug/2218203 to your computer and use it in GitHub Desktop.
class ApiTTests(TestCase):
fixtures = ['auth_views_testdata.json']
def setUp(self):
email = "w0"
user = User.objects.create_user(username=email, email=email)
user.set_unusable_password()
user.jid = email
user.save()
user.apikey = get_api_key(user)
print "Created user: %s" % user.username
print "Has API key: %s" % user.apikey
self.api_key = user.apikey
self.username = user.username
def test_new_ticket(self):
# create new ticket
test_data = {
"username":self.username,
"api_key":self.api_key
}
header = {
"HTTP_AUTHORIZATION": "ApiKey %s:%s" % (self.username, self.api_key)
}
response = self.client.put('/api/v1/t/', json.dumps(test_data), content_type="application/json", **header)
self.assertEqual(response.status_code, 201)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment