# Path: tests/fixtures/load_fixture_json.py
# def load_fixture_json(fname):
#     with open(os.path.join(CUR_DIR, '%s.json' % fname)) as ff:
#         content_ = ff.read()
#         return json.loads(content_)


import unittest
from formpack.b64_attachment import B64Attachment
from .fixtures.load_fixture_json import load_fixture_json
# coding: utf-8



class TestB64Attachment(unittest.TestCase):
    def test_string_matches(self):
        expectations = [
            ['data:image/png;base64,wxyz', True],
            ['data:image/jpeg;base64,xyz', True],
            ['abcdefghijklmnopqrstuvwxyz', False],
        ]
        for item_str, tf in expectations:
            self.assertEqual(B64Attachment._is_attachment(item_str), tf)

    def test_extensions(self):
        expectations = [
            ['data:image/png;base64,wxyz', 'image', 'png'],
            ['data:image/jpeg;base64,xyz', 'image', 'jpeg'],
        ]
        for item_str, exp_mtype, exp_ext in expectations:
            (mtype, ext, contents) = B64Attachment._attachment_split(item_str)
            self.assertEqual(exp_ext, ext)
            self.assertEqual(exp_mtype, mtype)

    def test_write_to_file(self):
        img_example = load_fixture_json('restaurant_photo/images')[0]
        attachment = B64Attachment(img_example)

# Path: tests/fixtures/load_fixture_json.py
# def load_fixture_json(fname):
#     with open(os.path.join(CUR_DIR, '%s.json' % fname)) as ff:
#         content_ = ff.read()
#         return json.loads(content_)


# Path: tests/test_formpack_attachments.py
import unittest
from formpack.b64_attachment import B64Attachment
from .fixtures.load_fixture_json import load_fixture_json

# coding: utf-8



class TestB64Attachment(unittest.TestCase):
    def test_string_matches(self):
        expectations = [
            ['data:image/png;base64,wxyz', True],
            ['data:image/jpeg;base64,xyz', True],
            ['abcdefghijklmnopqrstuvwxyz', False],
        ]
        for item_str, tf in expectations:
            self.assertEqual(B64Attachment._is_attachment(item_str), tf)

    def test_extensions(self):
        expectations = [
            ['data:image/png;base64,wxyz', 'image', 'png'],
            ['data:image/jpeg;base64,xyz', 'image', 'jpeg'],
        ]
        for item_str, exp_mtype, exp_ext in expectations:
            (mtype, ext, contents) = B64Attachment._attachment_split(item_str)
            self.assertEqual(exp_ext, ext)
            self.assertEqual(exp_mtype, mtype)

    def test_write_to_file(self):
        img_example = load_fixture_json('restaurant_photo/images')[0]
        attachment = B64Attachment(img_example)

        (