Ejemplo n.º 1
0
def test_matcher():
    matcher = ETagMatcher(["ETAGS"])
    matcher = ETagMatcher(["ETAGS"])
    assert matcher.etags == ["ETAGS"]
    assert "ETAGS" in matcher
    assert "WEAK" not in matcher
    assert "BEER" not in matcher
    assert None not in matcher
    assert repr(matcher) == "<ETag ETAGS>"
    assert str(matcher) == '"ETAGS"'

    matcher2 = ETagMatcher(("ETAG1", "ETAG2"))
    assert repr(matcher2) == "<ETag ETAG1 or ETAG2>"
Ejemplo n.º 2
0
def test_matcher():
    matcher = ETagMatcher(['ETAGS'])
    matcher = ETagMatcher(['ETAGS'])
    eq_(matcher.etags, ['ETAGS'])
    assert_raises(DeprecationWarning, matcher.weak_match, "etag")
    assert "ETAGS" in matcher
    assert "WEAK" not in matcher
    assert "BEER" not in matcher
    assert None not in matcher
    eq_(repr(matcher), '<ETag ETAGS>')
    eq_(str(matcher), '"ETAGS"')

    matcher2 = ETagMatcher(("ETAG1", "ETAG2"))
    eq_(repr(matcher2), '<ETag ETAG1 or ETAG2>')
Ejemplo n.º 3
0
def test_matcher():
    matcher = ETagMatcher(['ETAGS'])
    matcher = ETagMatcher(['ETAGS'])
    assert matcher.etags == ['ETAGS']
    with pytest.raises(DeprecationWarning):
        matcher.weak_match("etag")
    assert "ETAGS" in matcher
    assert "WEAK" not in matcher
    assert "BEER" not in matcher
    assert None not in matcher
    assert repr(matcher) == '<ETag ETAGS>'
    assert str(matcher) == '"ETAGS"'

    matcher2 = ETagMatcher(("ETAG1","ETAG2"))
    assert repr(matcher2) == '<ETag ETAG1 or ETAG2>'
Ejemplo n.º 4
0
def _parse_etag(value, default=True):
    if value is None:
        value = ''
    value = value.strip()
    if not value:
        if default:
            return AnyETag
        else:
            return NoETag
    if value == '*':
        return AnyETag
    else:
        return ETagMatcher.parse(value)
Ejemplo n.º 5
0
def _parse_etag(value, default=True):
    if value is None:
        value = ''
    value = value.strip()
    if not value:
        if default:
            return AnyETag
        else:
            return NoETag
    if value == '*':
        return AnyETag
    else:
        return ETagMatcher.parse(value)
Ejemplo n.º 6
0
def check_etag(request, etag):
    """
    returns a response if the request contains an if-none-match 
    header that matches the given etag.  returns None if the 
    request should proceed as normal. 
    """
    
    rtags = request.headers.get('if-none-match', None)
    if rtags is None: 
        return None
    
    # spec requires that only GET and HEAD may be used
    if request.method not in ['GET', 'HEAD']: 
        return HttpResponse(status=412) # precondition failed

    matcher = ETagMatcher.parse(rtags)
    if etag in matcher:
        return HttpResponse(status=304, headers=[('etag', etag)])
    else: 
        return None
Ejemplo n.º 7
0
def test_matcher():
    matcher = ETagMatcher(['ETAGS'])
    matcher = ETagMatcher(['ETAGS'])
    assert matcher.etags == ['ETAGS']
    with pytest.raises(DeprecationWarning):
        matcher.weak_match("etag")
    assert "ETAGS" in matcher
    assert "WEAK" not in matcher
    assert "BEER" not in matcher
    assert None not in matcher
    assert repr(matcher) == '<ETag ETAGS>'
    assert str(matcher) == '"ETAGS"'

    matcher2 = ETagMatcher(("ETAG1", "ETAG2"))
    assert repr(matcher2) == '<ETag ETAG1 or ETAG2>'
Ejemplo n.º 8
0
 def test_parse_commasep(self):
     et = ETagMatcher.parse('"ONE", "TWO"')
     assert et.etags, ["ONE" == "TWO"]
Ejemplo n.º 9
0
 def test_parse_anyetag(self):
     # these tests smell bad, are they useful?
     et = ETagMatcher.parse("*")
     assert et.__dict__ == {}
     assert et.__repr__() == "<ETag *>"
Ejemplo n.º 10
0
 def test_parse_quoted_two_weak(self):
     et = ETagMatcher.parse('"ONE", W/"TWO"')
     self.assertEqual(et.etags, ['ONE'])
     self.assertEqual(et.weak_etags, ['TWO'])
Ejemplo n.º 11
0
 def test_parse_wo_close_quote(self):
     # Unsure if this is testing likely input
     et = ETagMatcher.parse('"ONE')
     self.assertEqual(et.etags, ['ONE'])
     self.assertEqual(et.weak_etags, [])
Ejemplo n.º 12
0
 def test_parse_commasep_w_weak(self):
     et = ETagMatcher.parse('ONE, w/TWO')
     self.assertEqual(et.etags, ['ONE'])
     self.assertEqual(et.weak_etags, ['TWO'])
Ejemplo n.º 13
0
 def test_parse_quoted_two(self):
     et = ETagMatcher.parse('"ONE", "TWO"')
     self.assertEqual(et.etags, ['ONE', 'TWO'])
Ejemplo n.º 14
0
 def test_parse_one(self):
     et = ETagMatcher.parse('ONE')
     self.assertEqual(et.etags, ['ONE'])
     self.assertEqual(et.weak_etags, [])
Ejemplo n.º 15
0
 def test_parse_invalid(self):
     for tag in ['one', 'one, two', '"one two']:
         et = ETagMatcher.parse(tag)
         self.assertEqual(et.etags, [tag])
     et = ETagMatcher.parse('"foo" and w/"weak"', strong=False)
     self.assertEqual(et.etags, ['foo'])
Ejemplo n.º 16
0
 def test_parse_commasep(self):
     et = ETagMatcher.parse('"ONE", "TWO"')
     self.assertEqual(et.etags, ['ONE', 'TWO'])
Ejemplo n.º 17
0
 def test_parse_quoted_two_weak(self):
     et = ETagMatcher.parse('"ONE", W/"TWO"')
     self.assertEqual(et.etags, ['ONE'])
     et = ETagMatcher.parse('"ONE", W/"TWO"', strong=False)
     self.assertEqual(et.etags, ['ONE', 'TWO'])
Ejemplo n.º 18
0
 def test_parse_quoted_two(self):
     et = ETagMatcher.parse('"ONE", "TWO"')
     self.assertEqual(et.etags, ['ONE', 'TWO'])
Ejemplo n.º 19
0
 def test_parse_commasep(self):
     et = ETagMatcher.parse('"ONE", "TWO"')
     self.assertEqual(et.etags, ['ONE', 'TWO'])
Ejemplo n.º 20
0
 def test_parse_quoted_two(self):
     et = ETagMatcher.parse('"ONE", "TWO"')
     assert et.etags, ["ONE" == "TWO"]
Ejemplo n.º 21
0
 def test_parse_quoted_two_weak(self):
     et = ETagMatcher.parse('"ONE", W/"TWO"')
     self.assertEqual(et.etags, ['ONE'])
     et = ETagMatcher.parse('"ONE", W/"TWO"', strong=False)
     self.assertEqual(et.etags, ['ONE', 'TWO'])
Ejemplo n.º 22
0
 def test_parse_None(self):
     et = ETagMatcher.parse(None)
     self.assertEqual(et.etags, [])
     self.assertEqual(et.weak_etags, [])
Ejemplo n.º 23
0
 def test_parse_None(self):
     et = ETagMatcher.parse(None)
     assert et.etags == []
Ejemplo n.º 24
0
 def test_parse_quoted(self):
     et = ETagMatcher.parse('"ONE"')
     self.assertEqual(et.etags, ['ONE'])
     self.assertEqual(et.weak_etags, [])
Ejemplo n.º 25
0
 def test_parse_anyetag(self):
     # these tests smell bad, are they useful?
     et = ETagMatcher.parse('*')
     assert et.__dict__ == {}
     assert et.__repr__() == '<ETag *>'
Ejemplo n.º 26
0
 def test_parse_invalid(self):
     for tag in ['one', 'one, two', '"one two']:
         et = ETagMatcher.parse(tag)
         self.assertEqual(et.etags, [tag])
     et = ETagMatcher.parse('"foo" and w/"weak"', strong=False)
     self.assertEqual(et.etags, ['foo'])
Ejemplo n.º 27
0
 def test_parse_invalid(self):
     for tag in ['one', 'one, two', '"one two']:
         et = ETagMatcher.parse(tag)
         assert et.etags == [tag]
     et = ETagMatcher.parse('"foo" and w/"weak"', strong=False)
     assert et.etags == ['foo']
Ejemplo n.º 28
0
 def test_parse_quoted(self):
     et = ETagMatcher.parse('"ONE"')
     self.assertEqual(et.etags, ['ONE'])
     self.assertEqual(et.weak_etags, [])
Ejemplo n.º 29
0
 def test_parse_commasep(self):
     et = ETagMatcher.parse('"ONE", "TWO"')
     assert et.etags, ['ONE' == 'TWO']
Ejemplo n.º 30
0
 def test_parse_wo_close_quote(self):
     # Unsure if this is testing likely input
     et = ETagMatcher.parse('"ONE')
     self.assertEqual(et.etags, ['ONE'])
     self.assertEqual(et.weak_etags, [])
Ejemplo n.º 31
0
 def test_parse_quoted(self):
     et = ETagMatcher.parse('"ONE"')
     assert et.etags == ['ONE']
Ejemplo n.º 32
0
 def test_parse_None(self):
     et = ETagMatcher.parse(None)
     assert et.etags == []
Ejemplo n.º 33
0
 def test_parse_quoted_two(self):
     et = ETagMatcher.parse('"ONE", "TWO"')
     assert et.etags, ['ONE' == 'TWO']
Ejemplo n.º 34
0
 def test_parse_invalid(self):
     for tag in ["one", "one, two", '"one two']:
         et = ETagMatcher.parse(tag)
         assert et.etags == [tag]
     et = ETagMatcher.parse('"foo" and w/"weak"', strong=False)
     assert et.etags == ["foo"]
Ejemplo n.º 35
0
 def test_parse_quoted_two_weak(self):
     et = ETagMatcher.parse('"ONE", W/"TWO"')
     assert et.etags == ['ONE']
     et = ETagMatcher.parse('"ONE", W/"TWO"', strong=False)
     assert et.etags, ['ONE' == 'TWO']
Ejemplo n.º 36
0
 def test_parse_quoted(self):
     et = ETagMatcher.parse('"ONE"')
     assert et.etags == ["ONE"]
Ejemplo n.º 37
0
 def test_parse_one(self):
     et = ETagMatcher.parse('"ONE"')
     assert et.etags == ['ONE']
Ejemplo n.º 38
0
 def test_parse_quoted_two_weak(self):
     et = ETagMatcher.parse('"ONE", W/"TWO"')
     assert et.etags == ["ONE"]
     et = ETagMatcher.parse('"ONE", W/"TWO"', strong=False)
     assert et.etags, ["ONE" == "TWO"]
Ejemplo n.º 39
0
 def test_parse_one(self):
     et = ETagMatcher.parse('"ONE"')
     assert et.etags == ["ONE"]
Ejemplo n.º 40
0
 def test_parse_anyetag(self):
     # these tests smell bad, are they useful?
     et = ETagMatcher.parse('*')
     self.assertEqual(et.__dict__, {})
     self.assertEqual(et.__repr__(), '<ETag *>')
Ejemplo n.º 41
0
 def test_parse_None(self):
     et = ETagMatcher.parse(None)
     self.assertEqual(et.etags, [])
     self.assertEqual(et.weak_etags, [])
Ejemplo n.º 42
0
 def test_parse_commasep_w_weak(self):
     et = ETagMatcher.parse('ONE, w/TWO')
     self.assertEqual(et.etags, ['ONE'])
     self.assertEqual(et.weak_etags, ['TWO'])
Ejemplo n.º 43
0
 def test_parse_anyetag(self):
     # these tests smell bad, are they useful?
     et = ETagMatcher.parse('*')
     self.assertEqual(et.__dict__, {})
     self.assertEqual(et.__repr__(), '<ETag *>')
Ejemplo n.º 44
0
 def test_parse_quoted_two_weak(self):
     et = ETagMatcher.parse('"ONE", W/"TWO"')
     self.assertEqual(et.etags, ['ONE'])
     self.assertEqual(et.weak_etags, ['TWO'])
Ejemplo n.º 45
0
 def test_parse_one(self):
     et = ETagMatcher.parse('ONE')
     self.assertEqual(et.etags, ['ONE'])
     self.assertEqual(et.weak_etags, [])
Ejemplo n.º 46
0
 def test_parse_commasep_w_weak(self):
     et = ETagMatcher.parse('"ONE", W/"TWO"')
     assert et.etags == ['ONE']
     et = ETagMatcher.parse('"ONE", W/"TWO"', strong=False)
     assert et.etags, ['ONE' == 'TWO']
Ejemplo n.º 47
0
 def test_parse_commasep_w_weak(self):
     et = ETagMatcher.parse('"ONE", W/"TWO"')
     assert et.etags == ["ONE"]
     et = ETagMatcher.parse('"ONE", W/"TWO"', strong=False)
     assert et.etags, ["ONE" == "TWO"]