# Path: featureflow/objectstore.py
# class WriteStream(object):
#     def __init__(self, uri, content_type, token, refresh):
#         self.content_type = content_type
#         self.refresh = refresh
#         self.token = token
#         self.uri = uri
#         self.buf = BytesIO()
# 
#     def __enter__(self):
#         return self
# 
#     def __exit__(self, t, value, traceback):
#         self.close()
# 
#     def _put(self):
#         return requests.put(
#                 self.uri,
#                 data=self.buf,
#                 headers={
#                     'X-Auth-Token': self.token,
#                     'Content-Type': self.content_type
#                 })
# 
#     def close(self):
#         if self.buf.tell() == 0:
#             # no bytes have been written to the stream
#             return
# 
#         self.buf.seek(0)
#         resp = self._put()
#         if resp.status_code == http.client.UNAUTHORIZED:
#             self.token = self.refresh()
#             self._put()
# 
#     def write(self, data):
#         self.buf.write(data)


import unittest2
import http.client
from .objectstore import WriteStream
from collections import namedtuple


class WriteStreamTests(unittest2.TestCase):
    def test_write_stream_does_not_put_zero_bytes(self):
        class TestWriteStream(WriteStream):
            def __init__(self):
                super(TestWriteStream, self).__init__(None, None, None, None)
                self._put_count = 0

            def _put(self):
                self._put_count += 1
                response_cls = namedtuple('Response', 'status_code')

# Path: featureflow/objectstore.py
# class WriteStream(object):
#     def __init__(self, uri, content_type, token, refresh):
#         self.content_type = content_type
#         self.refresh = refresh
#         self.token = token
#         self.uri = uri
#         self.buf = BytesIO()
# 
#     def __enter__(self):
#         return self
# 
#     def __exit__(self, t, value, traceback):
#         self.close()
# 
#     def _put(self):
#         return requests.put(
#                 self.uri,
#                 data=self.buf,
#                 headers={
#                     'X-Auth-Token': self.token,
#                     'Content-Type': self.content_type
#                 })
# 
#     def close(self):
#         if self.buf.tell() == 0:
#             # no bytes have been written to the stream
#             return
# 
#         self.buf.seek(0)
#         resp = self._put()
#         if resp.status_code == http.client.UNAUTHORIZED:
#             self.token = self.refresh()
#             self._put()
# 
#     def write(self, data):
#         self.buf.write(data)


# Path: featureflow/test_objectstorage.py
import unittest2
import http.client
from .objectstore import WriteStream
from collections import namedtuple



class WriteStreamTests(unittest2.TestCase):
    def test_write_stream_does_not_put_zero_bytes(self):
        class TestWriteStream(WriteStream):
            def __init__(self):
                super(TestWriteStream, self).__init__(None, None, None, None)
                self._put_count = 0

            def _put(self):
                self._put_count += 1
                response_cls = namedtuple('Response', 'status_code')

                return response_cls(status_code=http.client.NO_CONTENT)