# -*- coding: utf-8 -*-
u"""Test sirepo.cookie

:copyright: Copyright (c) 2018 RadiaSoft LLC.  All Rights Reserved.
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""
from __future__ import absolute_import, division, print_function
import pytest
from sirepo import srunit

@srunit.wrap_in_request(want_user=False)
def test_set_get():
    from pykern import pkunit
    from pykern.pkunit import pkeq
    from pykern.pkdebug import pkdp
    from pykern import pkcollections
    from sirepo import cookie

    class _Response(pkcollections.Dict):
        def set_cookie(self, *args, **kwargs):
            self.args = args
            self.kwargs = kwargs

    cookie.process_header('x')
    with pkunit.pkexcept('KeyError'):
        cookie.get_value('hi')
    with pkunit.pkexcept('AssertionError'):
        cookie.set_value('hi', 'hello')
    pkeq(None, cookie.unchecked_get_value('hi'))
    cookie.init_mock()
    cookie.set_value('hi', 'hello')
    r = _Response(status_code=200)
    cookie.save_to_cookie(r)
    pkeq('sirepo_dev', r.args[0])
    pkeq(False, r.kwargs['secure'])
    pkeq('hello', cookie.get_value('hi'))
    cookie.unchecked_remove('hi')
    pkeq(None, cookie.unchecked_get_value('hi'))
    cookie.process_header('sirepo_dev={}'.format(r.args[1]))
    pkeq('hello', cookie.get_value('hi'))

@@ -367,16 +367,26 @@
 t pkunit
+, pkcompat
 %0A    fro
@@ -761,24 +761,25 @@
 et_value('hi
+1
 ')%0A    with 
@@ -833,32 +833,33 @@
 ie.set_value('hi
+2
 ', 'hello')%0A    
@@ -891,32 +891,33 @@
 ed_get_value('hi
+3
 '))%0A    cookie.i
@@ -951,16 +951,17 @@
 alue('hi
+4
 ', 'hell
@@ -1128,32 +1128,33 @@
 ie.get_value('hi
+4
 '))%0A    cookie.u
@@ -1172,16 +1172,17 @@
 move('hi
+4
 ')%0A    p
@@ -1217,24 +1217,25 @@
 et_value('hi
+4
 '))%0A    cook
@@ -1252,16 +1252,25 @@
 _header(
+%0A        
 'sirepo_
@@ -1284,16 +1284,36 @@
 .format(
+pkcompat.from_bytes(
 r.args%5B1
@@ -1315,16 +1315,23 @@
 rgs%5B1%5D))
+,%0A    )
 %0A    pke
@@ -1361,12 +1361,13 @@
 alue('hi
+4
 '))%0A

make test easier to debug