# Path: performanceplatform/collector/ga/contrib/content/table.py
# def get_department(filters):
#     for f in filters:
#         try:
#             filter_key, filter_value = re.split('=~\^', f)
#             return try_get_department(filter_value)
#         except:
#             raise ValueError("department not found in filters, expected "
#                              "filter expression expression containing "
#                              "'=~^' e.g. 'Organisation=~^<A1>'.")
#     else:
#         # If no matches, raise a RuntimeError
#         raise RuntimeError("department not found in filters, expected "
#                            "filter expression beginning "
#                            "'customVarValue9=~^'.")


import unittest
from nose.tools import assert_raises
from hamcrest import assert_that, equal_to
from performanceplatform.collector.ga.contrib.content.table import \
    get_department


class ContribContentTableTestCase(unittest.TestCase):
    def test_can_pass_custom_value_to_get_department(self):
        filters = ["customVarValue9=~^<D1>"]

        department = get_department(filters)

        assert_that(department, equal_to("attorney-generals-office"))

    def test_can_pass_organisation_to_get_department(self):
        filters = ["Organisation=~^<D1>"]


# Path: performanceplatform/collector/ga/contrib/content/table.py
# def get_department(filters):
#     for f in filters:
#         try:
#             filter_key, filter_value = re.split('=~\^', f)
#             return try_get_department(filter_value)
#         except:
#             raise ValueError("department not found in filters, expected "
#                              "filter expression expression containing "
#                              "'=~^' e.g. 'Organisation=~^<A1>'.")
#     else:
#         # If no matches, raise a RuntimeError
#         raise RuntimeError("department not found in filters, expected "
#                            "filter expression beginning "
#                            "'customVarValue9=~^'.")


# Path: tests/performanceplatform/collector/ga/contrib/content/test_table.py
import unittest
from nose.tools import assert_raises
from hamcrest import assert_that, equal_to
from performanceplatform.collector.ga.contrib.content.table import \
    get_department



class ContribContentTableTestCase(unittest.TestCase):
    def test_can_pass_custom_value_to_get_department(self):
        filters = ["customVarValue9=~^<D1>"]

        department = get_department(filters)

        assert_that(department, equal_to("attorney-generals-office"))

    def test_can_pass_organisation_to_get_department(self):
        filters = ["Organisation=~^<D1>"]


        department = get_department(filters)