~jcsackett/charmworld/bac-tag-constraints

« back to all changes in this revision

Viewing changes to charmworld/views/tests/test_api.py

  • Committer: Tarmac
  • Author(s): Abel Deuring
  • Date: 2013-08-07 13:31:20 UTC
  • mfrom: (334.1.5 etags)
  • Revision ID: tarmac-20130807133120-euu4igaar08e89iy
[r=abentley][bug=][author=adeuring] Add an Etag header to the API response for charm details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
918
918
        self.assertEqual('foo/bar', charm_id)
919
919
        self.assertEqual('file/baz', trailing)
920
920
 
 
921
    def test_charm_response_includes_etag(self):
 
922
        charm_id, charm = self.make_charm(hash_='fake-hash')
 
923
        response = self.get_response(
 
924
            'charm', remainder='/' + charm_id)
 
925
        self.assertIn(('Etag', 'fake-hash'), response.headerlist)
 
926
 
 
927
        # If no hash value for a charm exists, an Etag header is not included.
 
928
        charm_id, charm = self.make_charm(hash_=None)
 
929
        response = self.get_response(
 
930
            'charm', remainder='/' + charm_id)
 
931
        header_names = [header[0] for header in response.headerlist]
 
932
        self.assertNotIn('Etag', header_names)
 
933
 
 
934
    def test_charm_304_response(self):
 
935
        charm_id, charm = self.make_charm(hash_='fake-hash')
 
936
        request = self.make_request('charm', remainder='/' + charm_id)
 
937
        request.if_none_match = ETagMatcher(['wrong-value'])
 
938
        response = self.api_class(request)()
 
939
        self.assertEqual(200, response.status_code)
 
940
        request.if_none_match = ETagMatcher(['fake-hash'])
 
941
        response = self.api_class(request)()
 
942
        self.assertEqual(304, response.status_code)
 
943
 
921
944
    def test_file(self):
922
945
        charm = factory.makeCharm(self.db)[1]
923
946
        charm_file = factory.make_charm_file(self.db, charm, 'README')