# Path: timepiece/tests/factories.py
# class User(factory.DjangoModelFactory):
#     class Meta:
# class Superuser(User):
# class Group(factory.DjangoModelFactory):
#     class Meta:
# class ProjectContract(factory.DjangoModelFactory):
#     class Meta:
# class ContractHour(factory.DjangoModelFactory):
#     class Meta:
# class ContractAssignment(factory.DjangoModelFactory):
#     class Meta:
# class HourGroup(factory.DjangoModelFactory):
#     class Meta:
# class EntryGroup(factory.DjangoModelFactory):
#     class Meta:
# class TypeAttribute(factory.DjangoModelFactory):
#     class Meta:
# class StatusAttribute(factory.DjangoModelFactory):
#     class Meta:
# class Business(factory.DjangoModelFactory):
#     class Meta:
# class Project(factory.DjangoModelFactory):
#     class Meta:
# class BillableProject(Project):
# class NonbillableProject(Project):
# class RelationshipType(factory.DjangoModelFactory):
#     class Meta:
# class ProjectRelationship(factory.DjangoModelFactory):
#     class Meta:
# class UserProfile(factory.DjangoModelFactory):
#     class Meta:
# class Activity(factory.DjangoModelFactory):
#     class Meta:
# class BillableActivityFactory(Activity):
# class NonbillableActivityFactory(Activity):
# class ActivityGroup(factory.DjangoModelFactory):
#     class Meta:
# class Location(factory.DjangoModelFactory):
#     class Meta:
# class Entry(factory.DjangoModelFactory):
#     class Meta:
# class ProjectHours(factory.DjangoModelFactory):
#     class Meta:
#     def password(self, create, extracted, **kwargs):
#     def permissions(self, create, extracted, **kwargs):
#     def contract_hours(self, create, extracted, **kwargs):
#     def projects(self, create, extracted, **kwargs):
# 
# Path: timepiece/entries/lookups.py
# class ActivityLookup(ModelLookup):
#     model = Activity
#     search_fields = ('name__icontains', )
# 
#     def get_query(self, request, term):
#         results = super(ActivityLookup, self).get_query(request, term)
#         project_pk = request.GET.get('project', None)
#         if project_pk not in [None, '']:
#             project = Project.objects.get(pk=project_pk)
#             if project and project.activity_group:
#                 return project.activity_group.activities.all().filter(name__icontains=term)
#         return results
# 
#     def get_item_label(self, item):
#         return u"%s" % (item.name)


from django.test import TestCase
from django.test.client import RequestFactory
from timepiece.tests import factories
from timepiece.entries.lookups import ActivityLookup
        activity_group.activities.add(activity3)
        activity_group.activities.add(activity4)

        project = factories.Project(activity_group=activity_group)

        request = RequestFactory().get('/selectable/entries-activitylookup', {
            'project': project.pk
        })

        data = self.lookup.get_query(request, 'a')

        self.assertNotIn(activity1, data)
        self.assertIn(activity2, data)
        self.assertIn(activity3, data)
        self.assertNotIn(activity4, data)

    def test_get_query_empty(self):
        """
        Tests whether a query with no associated project searches the entire
        set of activities, regardless of project.
        """
        activity1 = factories.Activity(name='foo')
        activity2 = factories.Activity(name='bar')
        activity3 = factories.Activity(name='baz')
        activity4 = factories.Activity(name='qux')

        activity_group1 = factories.ActivityGroup()
        activity_group1.activities.add(activity1)
        activity_group1.activities.add(activity2)


# Path: timepiece/tests/factories.py
# class User(factory.DjangoModelFactory):
#     class Meta:
# class Superuser(User):
# class Group(factory.DjangoModelFactory):
#     class Meta:
# class ProjectContract(factory.DjangoModelFactory):
#     class Meta:
# class ContractHour(factory.DjangoModelFactory):
#     class Meta:
# class ContractAssignment(factory.DjangoModelFactory):
#     class Meta:
# class HourGroup(factory.DjangoModelFactory):
#     class Meta:
# class EntryGroup(factory.DjangoModelFactory):
#     class Meta:
# class TypeAttribute(factory.DjangoModelFactory):
#     class Meta:
# class StatusAttribute(factory.DjangoModelFactory):
#     class Meta:
# class Business(factory.DjangoModelFactory):
#     class Meta:
# class Project(factory.DjangoModelFactory):
#     class Meta:
# class BillableProject(Project):
# class NonbillableProject(Project):
# class RelationshipType(factory.DjangoModelFactory):
#     class Meta:
# class ProjectRelationship(factory.DjangoModelFactory):
#     class Meta:
# class UserProfile(factory.DjangoModelFactory):
#     class Meta:
# class Activity(factory.DjangoModelFactory):
#     class Meta:
# class BillableActivityFactory(Activity):
# class NonbillableActivityFactory(Activity):
# class ActivityGroup(factory.DjangoModelFactory):
#     class Meta:
# class Location(factory.DjangoModelFactory):
#     class Meta:
# class Entry(factory.DjangoModelFactory):
#     class Meta:
# class ProjectHours(factory.DjangoModelFactory):
#     class Meta:
#     def password(self, create, extracted, **kwargs):
#     def permissions(self, create, extracted, **kwargs):
#     def contract_hours(self, create, extracted, **kwargs):
#     def projects(self, create, extracted, **kwargs):
# 
# Path: timepiece/entries/lookups.py
# class ActivityLookup(ModelLookup):
#     model = Activity
#     search_fields = ('name__icontains', )
# 
#     def get_query(self, request, term):
#         results = super(ActivityLookup, self).get_query(request, term)
#         project_pk = request.GET.get('project', None)
#         if project_pk not in [None, '']:
#             project = Project.objects.get(pk=project_pk)
#             if project and project.activity_group:
#                 return project.activity_group.activities.all().filter(name__icontains=term)
#         return results
# 
#     def get_item_label(self, item):
#         return u"%s" % (item.name)


# Path: timepiece/entries/tests/test_lookups.py
from django.test import TestCase
from django.test.client import RequestFactory
from timepiece.tests import factories
from timepiece.entries.lookups import ActivityLookup

        activity_group.activities.add(activity3)
        activity_group.activities.add(activity4)

        project = factories.Project(activity_group=activity_group)

        request = RequestFactory().get('/selectable/entries-activitylookup', {
            'project': project.pk
        })

        data = self.lookup.get_query(request, 'a')

        self.assertNotIn(activity1, data)
        self.assertIn(activity2, data)
        self.assertIn(activity3, data)
        self.assertNotIn(activity4, data)

    def test_get_query_empty(self):
        """
        Tests whether a query with no associated project searches the entire
        set of activities, regardless of project.
        """
        activity1 = factories.Activity(name='foo')
        activity2 = factories.Activity(name='bar')
        activity3 = factories.Activity(name='baz')
        activity4 = factories.Activity(name='qux')

        activity_group1 = factories.ActivityGroup()
        activity_group1.activities.add(activity1)
        activity_group1.activities.add(activity2)


        activity_group2 = factories.ActivityGroup()