# Path: dashboard/apps/hub/models.py
# class ProxyUser(User):
#     class Meta:
# class Office(models.Model):
#     class Meta:
# class Organization(models.Model):
#     class Meta:
# class DataFormat(models.Model):
#     class Meta:
# class State(models.Model):
#     class Meta:
# class Election(models.Model):
#     class Meta:
# class BaseContact(models.Model):
#     class Meta:
# class VolunteerRole(models.Model):
# class Volunteer(BaseContact):
# class BaseLog(models.Model):
#     class Meta:
# class Log(BaseLog):
#     class Meta:
# class VolunteerLog(BaseLog):
#     def __str__(self):
#     def __str__(self):
#     def __repr__(self):
#     def save(self, *args, **kwargs):
#     def __str__(self):
#     def save(self, *args, **kwargs):
#     def __str__(self):
#     def __str__(self):
#     def status_entry(self):
#     def results_status(self):
#     def save(self, *args, **kwargs):
#     def clean(self):
#     def __str__(self):
#     def __repr__(self):
#     def _perform_unique_checks(self, unique_checks):
#     def offices(self):
#     def offices_for_api(self):
#     def reporting_levels(self):
#     def elec_key(self, as_string=False):
#     def slug(self):
#     def division(self):
#     def __str__(self):
#     def __str__(self):
#     def full_name(self):
#     def status_entry(self):
#     def __str__(self):
#     def __repr__(self):
#     def log_key(self, as_string=False):
#     def __str__(self):
#     def __repr__(self):
#     def log_key(self, as_string=False):
#     GOV_LEVELS = (
#         ('county', 'County'),
#         ('state','State'),
#         ('federal','Federal'),
#         ('local', 'Local')
#     )
#     STATUS_OPTIONS = (
#         ('not-started', 'Not Started'),
#         ('partial', 'Partial'),
#         ('up-to-date', 'Up-to-date'),
#     )
#     PAIN_CHOICES = (
#         ('easy', 'Easy'),
#         ('medium', 'Medium'),
#         ('hard', 'Hard'),
#         ('excruciating', 'Excruciating'),
#     )
#     RACE_CHOICES = (
#         ('primary', 'Primary'),
#         ('primary-recall', 'Primary Recall'),
#         ('general', 'General'),
#         ('general-recall', 'General Recall'),
#         ('primary-runoff', 'Primary Runoff'),
#         ('general-runoff', 'General Runoff'),
#     )
#     RESULT_CHOICES = (
#         ('certified', 'Certified'),
#         ('unofficial', 'Unofficial'),
#     )
#     PRIMARY_TYPE_CHOICES = (
#         ('blanket', 'Blanket'),
#         ('closed', 'Closed'),
#         ('open', 'Open'),
#         ('semi-closed', 'Semi-closed'),
#         ('semi-open', 'Semi-open'),
#         ('other', 'Other'),
#     )
#     LEVEL_STATUS_CHOICES = (
#         ('yes', 'Yes - Will be included'),
#         ('no', 'No - Will not be included'),
#         ('unknown', 'Unsure if exists'),
#         ('Unavailable', 'Not available'),
#         ('baked-raw', 'Baked Raw'),
#         ('baked', 'Baked'),
#     )


import unittest
import mock
from django.core.exceptions import ValidationError
from django.db.models import Q
from django.db.models.query import QuerySet
from django.test import TestCase
from ..models import Contact, Election, Log, State, Volunteer
        def filter_method(*args, **kwargs):
            count_val = 0

            try:
                q_obj = args[0]
                if isinstance(q_obj, Q):
                    filter_kwargs = {k:v for k, v in q_obj.children}
            except IndexError:
                filter_kwargs = kwargs

            for kwarg, val in filter_kwargs.items():
                try:
                    count_val = counts[kwarg][val]
                    break
                except KeyError:
                    pass
                
            mqs = mock.MagicMock(spec=QuerySet)
            mqs.count.return_value = count_val
            return mqs

        return filter_method

    # It would be great to use mock-django
    # (https://github.com/dcramer/mock-django/) for more full-featured mocks
    # of Django QuerySets and Managers. However, the version on pypi doesn't
    # support Django 1.5.
    @mock.patch('apps.hub.models.State.election_set', autospec=True) 
    def test_results_status(self, election_set):
        election_set.filter = self.make_mock_filter_method()

# Path: dashboard/apps/hub/models.py
# class ProxyUser(User):
#     class Meta:
# class Office(models.Model):
#     class Meta:
# class Organization(models.Model):
#     class Meta:
# class DataFormat(models.Model):
#     class Meta:
# class State(models.Model):
#     class Meta:
# class Election(models.Model):
#     class Meta:
# class BaseContact(models.Model):
#     class Meta:
# class VolunteerRole(models.Model):
# class Volunteer(BaseContact):
# class BaseLog(models.Model):
#     class Meta:
# class Log(BaseLog):
#     class Meta:
# class VolunteerLog(BaseLog):
#     def __str__(self):
#     def __str__(self):
#     def __repr__(self):
#     def save(self, *args, **kwargs):
#     def __str__(self):
#     def save(self, *args, **kwargs):
#     def __str__(self):
#     def __str__(self):
#     def status_entry(self):
#     def results_status(self):
#     def save(self, *args, **kwargs):
#     def clean(self):
#     def __str__(self):
#     def __repr__(self):
#     def _perform_unique_checks(self, unique_checks):
#     def offices(self):
#     def offices_for_api(self):
#     def reporting_levels(self):
#     def elec_key(self, as_string=False):
#     def slug(self):
#     def division(self):
#     def __str__(self):
#     def __str__(self):
#     def full_name(self):
#     def status_entry(self):
#     def __str__(self):
#     def __repr__(self):
#     def log_key(self, as_string=False):
#     def __str__(self):
#     def __repr__(self):
#     def log_key(self, as_string=False):
#     GOV_LEVELS = (
#         ('county', 'County'),
#         ('state','State'),
#         ('federal','Federal'),
#         ('local', 'Local')
#     )
#     STATUS_OPTIONS = (
#         ('not-started', 'Not Started'),
#         ('partial', 'Partial'),
#         ('up-to-date', 'Up-to-date'),
#     )
#     PAIN_CHOICES = (
#         ('easy', 'Easy'),
#         ('medium', 'Medium'),
#         ('hard', 'Hard'),
#         ('excruciating', 'Excruciating'),
#     )
#     RACE_CHOICES = (
#         ('primary', 'Primary'),
#         ('primary-recall', 'Primary Recall'),
#         ('general', 'General'),
#         ('general-recall', 'General Recall'),
#         ('primary-runoff', 'Primary Runoff'),
#         ('general-runoff', 'General Runoff'),
#     )
#     RESULT_CHOICES = (
#         ('certified', 'Certified'),
#         ('unofficial', 'Unofficial'),
#     )
#     PRIMARY_TYPE_CHOICES = (
#         ('blanket', 'Blanket'),
#         ('closed', 'Closed'),
#         ('open', 'Open'),
#         ('semi-closed', 'Semi-closed'),
#         ('semi-open', 'Semi-open'),
#         ('other', 'Other'),
#     )
#     LEVEL_STATUS_CHOICES = (
#         ('yes', 'Yes - Will be included'),
#         ('no', 'No - Will not be included'),
#         ('unknown', 'Unsure if exists'),
#         ('Unavailable', 'Not available'),
#         ('baked-raw', 'Baked Raw'),
#         ('baked', 'Baked'),
#     )


# Path: dashboard/apps/hub/tests/test_models.py
import unittest
import mock
from django.core.exceptions import ValidationError
from django.db.models import Q
from django.db.models.query import QuerySet
from django.test import TestCase
from ..models import Contact, Election, Log, State, Volunteer

        def filter_method(*args, **kwargs):
            count_val = 0

            try:
                q_obj = args[0]
                if isinstance(q_obj, Q):
                    filter_kwargs = {k:v for k, v in q_obj.children}
            except IndexError:
                filter_kwargs = kwargs

            for kwarg, val in filter_kwargs.items():
                try:
                    count_val = counts[kwarg][val]
                    break
                except KeyError:
                    pass
                
            mqs = mock.MagicMock(spec=QuerySet)
            mqs.count.return_value = count_val
            return mqs

        return filter_method

    # It would be great to use mock-django
    # (https://github.com/dcramer/mock-django/) for more full-featured mocks
    # of Django QuerySets and Managers. However, the version on pypi doesn't
    # support Django 1.5.
    @mock.patch('apps.hub.models.State.election_set', autospec=True) 
    def test_results_status(self, election_set):
        election_set.filter = self.make_mock_filter_method()

        s = State(postal="MD")