Esempio n. 1
0
    def test_project_comment_events(self):
        """
            Project comment event responses
        """
        self._sign_in(self.user)

        project = milkman.deliver(Project)
        project.set_owner(self.admin)

        root_comment = ProjectComment.add_root(project=project,
                                               user=self.admin,
                                               text="foo")

        event = milkman.deliver(Event,
                                timestamp=self.now,
                                kind=EventKind.PROJECTROOTCOMMENTCREATED,
                                object_id=root_comment.pk,
                                project_id=project.pk)

        request = EventRequestContainer.combined_message_class(ts=self.ts)

        with self.assertNumQueries(3):
            response = self.api.event_list(request)

        self.assertEqual(len(response.events), 1)
        self.assertEqual(len(response.project_comments), 1)
        self.assertEqual(response.events[0].id, event.pk)
        self.assertEqual(response.project_comments[0].id, root_comment.pk)
Esempio n. 2
0
 def create_test_users(self):
     """
         Creates test users
     """
     User = get_user_model()
     self.admin = milkman.deliver(User,
                                  email="*****@*****.**",
                                  is_superuser=True,
                                  first_name="Polar",
                                  last_name="Bear",
                                  is_whitelisted=True)
     self.admin2 = milkman.deliver(User,
                                   email="*****@*****.**",
                                   is_staff=True,
                                   first_name="Manx",
                                   last_name="Shearwater",
                                   is_whitelisted=True)
     self.user = milkman.deliver(User,
                                 email="*****@*****.**",
                                 first_name="Razor",
                                 last_name="Bill")
     self.user2 = milkman.deliver(User,
                                  email="*****@*****.**",
                                  first_name="Storm",
                                  last_name="Petrel")
Esempio n. 3
0
    def test_filter_users(self):
        """ Test that the correct users are returned when doing partial filters
            on the first_name, last_name and email fields
        """
        User = get_user_model()

        # Users with some overlapping details
        charlie_brown = milkman.deliver(User,
                                        first_name="Charlie",
                                        last_name="Brown",
                                        email="*****@*****.**")
        charlie_brooker = milkman.deliver(User,
                                          first_name="Charlie",
                                          last_name="Brooker",
                                          email="*****@*****.**")
        someone_brooker = milkman.deliver(User,
                                          first_name="Someone",
                                          last_name="Brooker",
                                          email="*****@*****.**")

        def _check_filtered_users(q, *users):
            self._sign_in(self.admin)

            response = self.api.users_filter(
                UserFilterContainer.combined_message_class(q=q))
            self.assertIsInstance(response, UserListResponse)
            items_pks = [item.id for item in response.items]

            self.assertEqual(len(users), len(items_pks))
            for user in users:
                self.assertTrue(user.pk in items_pks)

        # Filter on 'example.com' first, it should return all 5 users
        with self.assertNumQueries(2):
            _check_filtered_users('example', charlie_brown, charlie_brooker,
                                  someone_brooker, self.user, self.user2)

        # Test some more restrictive filters
        with self.assertNumQueries(2):
            _check_filtered_users('charlie', charlie_brown, charlie_brooker)
        # partial matches work as well
        with self.assertNumQueries(2):
            _check_filtered_users('charl', charlie_brown, charlie_brooker)
        with self.assertNumQueries(2):
            _check_filtered_users('brooker', charlie_brooker, someone_brooker)
        with self.assertNumQueries(2):
            _check_filtered_users('someone', someone_brooker)
        with self.assertNumQueries(3):
            _check_filtered_users('Charlie Brooker', charlie_brooker)
        with self.assertNumQueries(3):
            _check_filtered_users('Charlie Brown', charlie_brown)
        # no results
        with self.assertNumQueries(3):
            _check_filtered_users('Someone Brown')

        # no search term and not admin user - should raise forbidden.
        self._sign_out()
        self._sign_in(self.user)
        self.assertRaises(ForbiddenException, self.api.users_filter,
                          UserFilterContainer.combined_message_class(q=None))
Esempio n. 4
0
    def setUp(self):
        """
            Bootstrap data
        """
        super(ProjectChannelAPITests, self).setUp()

        self.pending_user = milkman.deliver(PendingUser,
                                            email="*****@*****.**")

        self.project = milkman.deliver(Project)
        self.project.set_owner(self.admin)

        self.video_1 = self.create_video(channel_id="123",
                                         channel_name="foo",
                                         project=self.project)

        self.video_2 = self.create_video(channel_id="123",
                                         channel_name="fez",
                                         project=self.project)

        self.video_3 = self.create_video(channel_id="456",
                                         channel_name="bar",
                                         project=self.project)

        self.other_video = self.create_video(channel_id="999",
                                             channel_name="buzz")
Esempio n. 5
0
    def setUp(self):
        """
            Bootstrap test data
        """
        super(AutoCompleteTagDocumentTestCase, self).setUp()
        self.user = milkman.deliver(get_user_model(),
                                    email="*****@*****.**",
                                    first_name='Robbo',
                                    last_name='Cop')
        self.project = milkman.deliver(Project)
        self.project_2 = milkman.deliver(Project, privacy_tags=1)
        self.project_3 = milkman.deliver(Project)

        self.tag, _ = self.create_project_tag(
            name="RobboCop",
            description='description 1',
            image_url='http://robbocop.com/foobar.jpg',
            project=self.project,
            user=self.user)

        self.tag_2, _ = self.create_project_tag(
            name="RobboCop Private",
            description='description 1 private',
            image_url='http://private.robbocop.com/foobar.jpg',
            project=self.project_2,
            user=self.user)

        self.create_project_tag(global_tag=self.tag, project=self.project_3)
Esempio n. 6
0
    def setUp(self):
        """
            Bootstrap with project data
        """
        super(ProjectAPITests, self).setUp()

        self.pending_user = milkman.deliver(PendingUser,
                                            email="*****@*****.**")

        self.project = milkman.deliver(Project)
        self.project.set_owner(self.admin)
        self.project.add_admin(self.user, pending=False)
        self.project.add_assigned(self.user2, pending=False)
        self.project.add_assigned(self.pending_user, pending=True)

        self.favourited_video = self.create_video(project=self.project,
                                                  favourited=True)

        self.tagged_video = self.create_video(project=self.project)

        self.archived_video = self.create_video(project=self.project)
        self.archived_video.archive()

        self.deleted_video = self.create_video(project=self.project)
        self.deleted_video.delete()

        self.tag, _, video_tag, _ = self.create_video_instance_tag(
            name='Foo', project=self.project, video=self.tagged_video)

        self.create_video_instance_tag(video_tag=video_tag,
                                       start_seconds=0,
                                       end_seconds=42)

        self.tag2, _, _, _ = self.create_video_instance_tag(
            name='Bar', project=self.project, video=self.tagged_video)
Esempio n. 7
0
    def setUp(self):
        """
            Bootstrap test data
        """
        super(ProjectCommentAPIListTestCase, self).setUp()
        self.project = milkman.deliver(Project)
        self.project.set_owner(self.admin)
        self.project.add_assigned(self.user, pending=False)

        self.project_2 = milkman.deliver(Project)

        # create root comments
        self.root_comments = [
            ProjectComment.add_root(project=self.project,
                                    user=self.user,
                                    text="foo{0}".format(i),
                                    created=datetime.datetime(
                                        2014, 1, 1, i, i, i))
            for i in range(1, 6)
        ]

        self.other_comments = [
            ProjectComment.add_root(project=self.project_2,
                                    user=self.user,
                                    text="bar{0}".format(i))
            for i in range(0, 5)
        ]
    def setUp(self):
        """
            Bootstrap test data
        """
        super(VideoCollectionFilterAPITests, self).setUp()
        self.project = milkman.deliver(Project)
        self.project.set_owner(self.admin)

        self.video_1 = self.create_video(
            project=self.project,
            channel_id=u"UCDASmtEzVZS5PZxjiRjcHKA",
            publish_date=datetime.datetime(2014, 1, 1, tzinfo=timezone.utc),
            name=u"Bazooka")

        self.video_2 = self.create_video(
            channel_id=u"UCmA0uNMDy4wx9NHu1OfAw9g",
            publish_date=datetime.datetime(2014, 2, 1, tzinfo=timezone.utc),
            project=self.project,
            name=u"Bazooka 2")

        self.collection_1 = milkman.deliver(VideoCollection,
                                            project=self.project,
                                            name='Collection 1')
        self.collection_1.add_video(self.video_2)
        self.collection_1.add_video(self.video_1)

        self.other_video = self.create_video(
            youtube_video=self.video_1.youtube_video)
Esempio n. 9
0
    def test_video_events(self):
        """
            Video events responses
        """
        self._sign_in(self.user)

        video = self.create_video()
        created_event = milkman.deliver(Event,
                                        timestamp=self.now,
                                        kind=EventKind.VIDEOCREATED,
                                        object_id=video.pk)

        updated_event = milkman.deliver(Event,
                                        timestamp=self.now,
                                        kind=EventKind.VIDEOUPDATED,
                                        object_id=video.pk)

        video2 = self.create_video()
        created_event2 = milkman.deliver(Event,
                                         timestamp=self.now,
                                         kind=EventKind.VIDEOCREATED,
                                         object_id=video2.pk)

        request = EventRequestContainer.combined_message_class(ts=self.ts)

        with self.assertNumQueries(3):
            response = self.api.event_list(request)

        self.assertEqual(len(response.events), 3)
        self.assertEqual(len(response.videos), 2)
        self.assertEqual(response.events[0].id, created_event2.pk)
        self.assertEqual(response.videos[0].id, video.pk)
Esempio n. 10
0
    def setUp(self):
        """
            Bootstrap test data
        """
        super(ExportVideoTestCase, self).setUp()

        self.admin = milkman.deliver(
            get_user_model(), email="*****@*****.**", is_superuser=True,
            username='******')

        self.project = milkman.deliver(Project)
        self.video = self.create_video(
            project=self.project,
            name='test video',
            notes='foobar\nbuzz',
            latitude='3.14',
            longitude='5.33')
        self.tag1, _, _, _ = self.create_video_instance_tag(
            project=self.project, video=self.video, name='غرفة عمليات انصار')

        self.comment = TimedVideoComment.add_root(
            video=self.video,
            user=self.admin,
            text='Hello world with UTF chars! غرفة عمليات انصار الشريع',
            start_seconds=0,
        )
        self.comment_reply = self.comment.add_reply('Goodbye!', self.admin)
Esempio n. 11
0
    def setUp(self):
        self.page = milkman.deliver(WebPage, slug='test-page', title="page", template='pages/default.html')
        self.page2 = milkman.deliver(WebPage, slug='test-page-2', title="page2", template='pages/default.html')
        self.page_resource = PageResource()
        self.user = User.objects.create_user(username='******', email='*****@*****.**', password='******')
        self.client.login(username='******', password='******')

        self.rf = RequestFactory()
Esempio n. 12
0
 def setUp(self):
     """
         Bootstrap test data
     """
     super(UserModelTestCase, self).setUp()
     self.user = milkman.deliver(User, email="*****@*****.**")
     self.admin = milkman.deliver(
         User, email="*****@*****.**", is_superuser=True, is_googler=True)
Esempio n. 13
0
    def test_my_projects(self):
        """
            Get list of projects assigned to a user or they have been invited to
        """
        project2 = milkman.deliver(Project,
                                   created=timezone.now() -
                                   datetime.timedelta(hours=1))
        project2.set_owner(self.admin)
        project2.add_admin(self.user, pending=False)

        project3 = milkman.deliver(Project,
                                   created=timezone.now() -
                                   datetime.timedelta(hours=2))
        project3.set_owner(self.user)

        project4 = milkman.deliver(Project,
                                   created=timezone.now() -
                                   datetime.timedelta(hours=3))
        project4.set_owner(self.admin)
        project4.add_assigned(self.user)

        self._sign_in(self.user)

        with self.assertNumQueries(4):
            response = self.api.project_list_user(
                ProjectListRequest.combined_message_class())
        self.assertEqual(4, len(response.items))

        assigned_project_resp = response.items[0]
        self.assertEqual(self.project.pk, assigned_project_resp.id)
        self.assertTrue(assigned_project_resp.current_user_info.is_assigned)
        self.assertFalse(assigned_project_resp.current_user_info.is_owner)
        self.assertTrue(assigned_project_resp.current_user_info.is_admin)
        self.assertFalse(assigned_project_resp.current_user_info.is_pending)
        self.assertEqual(2, assigned_project_resp.video_count)

        self.assertEqual(response.items[0].video_tag_instance_count, 3)

        admin_project_resp = response.items[1]
        self.assertEqual(project2.pk, admin_project_resp.id)
        self.assertTrue(admin_project_resp.current_user_info.is_assigned)
        self.assertFalse(admin_project_resp.current_user_info.is_owner)
        self.assertTrue(admin_project_resp.current_user_info.is_admin)
        self.assertFalse(admin_project_resp.current_user_info.is_pending)

        owner_project_resp = response.items[2]
        self.assertEqual(project3.pk, owner_project_resp.id)
        self.assertTrue(owner_project_resp.current_user_info.is_assigned)
        self.assertTrue(owner_project_resp.current_user_info.is_owner)
        self.assertTrue(owner_project_resp.current_user_info.is_admin)
        self.assertFalse(owner_project_resp.current_user_info.is_pending)

        pending_project_resp = response.items[3]
        self.assertEqual(project4.pk, pending_project_resp.id)
        self.assertTrue(pending_project_resp.current_user_info.is_assigned)
        self.assertFalse(pending_project_resp.current_user_info.is_owner)
        self.assertFalse(pending_project_resp.current_user_info.is_admin)
        self.assertTrue(pending_project_resp.current_user_info.is_pending)
Esempio n. 14
0
 def setUp(self):
     """
         Bootstrap test data
     """
     super(VideoModelTestCase, self).setUp()
     self.project_owner = milkman.deliver(User, email="*****@*****.**")
     self.project = milkman.deliver(Project)
     self.project.set_owner(self.project_owner)
     self.video = self.create_video(project=self.project)
Esempio n. 15
0
 def setUp(self):
     """
         Bootstrap test data
     """
     super(VideoCollectionVideoSignalsTestCase, self).setUp()
     self.project = milkman.deliver(Project)
     self.video = self.create_video()
     self.collection = milkman.deliver(
         VideoCollection, project=self.project)
Esempio n. 16
0
    def test_save_project_tag_search_document(
            self, mock_index_global_tag_document):
        """
            Project tag created
        """
        tag = milkman.deliver(GlobalTag)
        mock_index_global_tag_document.reset_mock()

        ProjectTag.add_root(project=milkman.deliver(Project), global_tag=tag)
        mock_index_global_tag_document.assert_called_once_with(tag.pk)
Esempio n. 17
0
    def setUp(self):
        """
            Bootstrap test data
        """
        super(PublishEventHandlerViewTestCase, self).setUp()

        self.project = milkman.deliver(Project)

        User = get_user_model()
        self.user = milkman.deliver(User, email="*****@*****.**")
Esempio n. 18
0
    def setUp(self):
        """
            Bootstrap test data
        """
        super(ProjectCommentTestCase, self).setUp()

        self.project = milkman.deliver(Project)

        self.user1 = milkman.deliver(User, email="*****@*****.**")
        self.user2 = milkman.deliver(User, email="*****@*****.**")
Esempio n. 19
0
    def setUp(self):
        """
            Bootstrap test data
        """
        super(CleanChannelsTestCase, self).setUp()

        User = get_user_model()
        self.user = milkman.deliver(User, email="*****@*****.**")
        self.project = milkman.deliver(Project)
        self.video = self.create_video(project=self.project)
Esempio n. 20
0
    def test_related_explicit_values(self):
        child = milkman.deliver(Child, root__my_char='foo')
        self.assertEqual(child.root.my_char, 'foo')

        grandchild = milkman.deliver(GrandChild, parent__name='foo', parent__root__my_char='bar')
        self.assertEqual(grandchild.parent.name, 'foo')
        self.assertEqual(grandchild.parent.root.my_char, 'bar')

        root = milkman.deliver(Root)
        grandchild = milkman.deliver(GrandChild, parent__root=root)
        self.assertEqual(root.pk, grandchild.parent.root.pk)
Esempio n. 21
0
    def test_related_explicit_values(self):
        child = milkman.deliver(Child, root__my_char='foo')
        self.assertEqual(child.root.my_char, 'foo')

        grandchild = milkman.deliver(GrandChild, parent__name='foo', parent__root__my_char='bar')
        self.assertEqual(grandchild.parent.name, 'foo')
        self.assertEqual(grandchild.parent.root.my_char, 'bar')

        root = milkman.deliver(Root)
        grandchild = milkman.deliver(GrandChild, parent__root=root)
        self.assertEqual(root.pk, grandchild.parent.root.pk)
Esempio n. 22
0
    def test_has_correct_objects(self):
        "has correct objects for user (those which can be modified)"
        yes = milkman.deliver(Trip, where="Yesland", user=self.user)
        no = milkman.deliver(Trip, where="Nopeland", user=self.user)

        yes.fully_authorize(self.user)

        resp = self.client.get(reverse("trips:list"))

        self.assertIn(yes, resp.context["trip_list"])
        self.assertNotIn(no, resp.context["trip_list"])
Esempio n. 23
0
    def create_global_tag(self, project=None, **kwargs):
        """
            Creates a global tag
        """
        if not project:
            # GlobalTags must be created from a project - create one to
            # tie it to
            project = milkman.deliver(Project)

        return milkman.deliver(
            GlobalTag, created_from_project=project, **kwargs)
Esempio n. 24
0
    def setUp(self):
        """
            Bootstrap test data
        """
        super(TimedVideoCommentTestCase, self).setUp()

        self.project = milkman.deliver(Project)
        self.video = self.create_video(project=self.project)

        self.user1 = milkman.deliver(User, email="*****@*****.**")
        self.user2 = milkman.deliver(User, email="*****@*****.**")
Esempio n. 25
0
    def setUp(self):
        """
            Bootstrap data
        """
        super(TagAPITestCase, self).setUp()

        self.tag1 = milkman.deliver(GlobalTag, name='Han Solo')
        self.tag2 = milkman.deliver(
            GlobalTag, name='Chewbacca', description='Han shot first')
        self.tag3 = milkman.deliver(GlobalTag, name='Luke Skywalker')
        self.tag4 = milkman.deliver(
            GlobalTag, name='Leia', description='Kenobi helps Luke')
Esempio n. 26
0
    def create_test_users(self):
        """
            Override creation of test users
        """
        User = get_user_model()

        # override
        self.admin = milkman.deliver(User,
                                     email="*****@*****.**",
                                     is_superuser=True)
        self.user = milkman.deliver(User, email="*****@*****.**")
        self.user2 = milkman.deliver(User, email="*****@*****.**")
Esempio n. 27
0
    def setUp(self):
        """
            Bootstrap test data
        """
        super(UserDeletionTestCase, self).setUp()
        User = get_user_model()

        # override
        self.admin = milkman.deliver(User,
                                     email="*****@*****.**",
                                     is_superuser=True)
        self.user = milkman.deliver(User, email="*****@*****.**")
Esempio n. 28
0
    def test_force_random(self):
        root1 = milkman.deliver('tests.root')
        self.assertFalse(root1.my_string)

        root2 = milkman.deliver('tests.root', my_string=milkman.random)
        self.assertTrue(root2.my_string)

        sibling = milkman.deliver('tests.sibling')
        self.assertFalse(sibling.root)

        sibling = milkman.deliver('tests.sibling', root=milkman.random)
        self.assertTrue(sibling.root in [root1, root2])
Esempio n. 29
0
    def test_force_random(self):
        root1 = milkman.deliver('tests.root')
        self.assertFalse(root1.my_string)

        root2 = milkman.deliver('tests.root', my_string=milkman.random)
        self.assertTrue(root2.my_string)

        sibling = milkman.deliver('tests.sibling')
        self.assertFalse(sibling.root)

        sibling = milkman.deliver('tests.sibling', root=milkman.random)
        self.assertTrue(sibling.root in [root1, root2])
Esempio n. 30
0
def check_assigns_permissions(perm):
    user = milkman.deliver(User)
    trip = milkman.deliver(Trip)
    trip.fully_authorize(user)

    perm = 'trips.%s_trip' % perm
    try:
        assert user.has_perm(perm, trip), \
            'user has no perm %s' % perm
    finally:
        user.delete()
        trip.delete()
Esempio n. 31
0
def check_assigns_permissions(perm):
    user = milkman.deliver(User)
    ba = milkman.deliver(BalancedAccount)
    ba.fully_authorize(user)

    perm = 'funding.%s_balancedaccount' % perm
    try:
        assert user.has_perm(perm, ba), \
            'user has no perm %s' % perm
    finally:
        user.delete()
        ba.delete()
Esempio n. 32
0
def check_for_user(kind, perm):
    user = milkman.deliver(User)
    ba = milkman.deliver(
        BalancedAccount, kind=kind, name=':'.join([kind, perm])
    )
    ba.fully_authorize(user)

    qs = BalancedAccount.objects.for_user(kind, perm, user)
    try:
        assert ba in qs, '%r not in %r' % (ba, qs)
    finally:
        user.delete()
        ba.delete()
Esempio n. 33
0
 def setUp(self):
     """
         Bootstrap test data
     """
     super(ProjectModelTestCase, self).setUp()
     self.user = milkman.deliver(User, email="*****@*****.**")
     self.admin = milkman.deliver(
         User, email="*****@*****.**", is_superuser=True, is_googler=True)
     self.project_owner = milkman.deliver(User, email="*****@*****.**")
     self.project = milkman.deliver(Project)
     self.project.set_owner(self.project_owner)
     self.project.add_admin(self.admin, pending=False)
     self.project.add_assigned(self.user, pending=False)
Esempio n. 34
0
def check_for_user(perm):
    user = milkman.deliver(User)
    trip = milkman.deliver(
        Trip, name=perm
    )
    trip.fully_authorize(user)

    qs = Trip.objects.for_user(perm, user)
    try:
        assert trip in qs, '%r not in %r' % (trip, qs)
    finally:
        user.delete()
        trip.delete()
Esempio n. 35
0
    def setUp(self):
        """
            Bootstrap test data
        """
        super(VideoTagTestCase, self).setUp()

        self.project = milkman.deliver(Project)
        self.video = self.create_video(project=self.project)
        self.globaltag = milkman.deliver(GlobalTag)
        self.projecttag = ProjectTag.add_root(project=self.project,
                                              global_tag=self.globaltag)
        self.videotag = VideoTag.objects.create(project=self.project,
                                                project_tag=self.projecttag,
                                                video=self.video)
Esempio n. 36
0
    def setUp(self):
        """
            Bootstrap test data
        """
        super(GlobalTagTestCase, self).setUp()

        self.private_tag_project_1 = milkman.deliver(
            Project, privacy_tags=Project.PRIVATE)
        self.private_tag_project_2 = milkman.deliver(
            Project, privacy_tags=Project.PRIVATE)
        self.public_tag_project_1 = milkman.deliver(
            Project, privacy_tags=Project.PUBLIC)
        self.public_tag_project_2 = milkman.deliver(
            Project, privacy_tags=Project.PUBLIC)
Esempio n. 37
0
    def test_empty_search(self):
        """
            Search public tags with no query term
        """
        # create some extra tags to go over the page limit
        for i in range(1, 10):
            milkman.deliver(GlobalTag, name="tag{0}".format(i))

        self._sign_in(self.user)
        response = self.api.search_tags(
            TagSearchEntityContainer.combined_message_class())

        self.assertEqual(0, len(response.project_tags))
        self.assertEqual(10, len(response.global_tags))
Esempio n. 38
0
 def test_required_field(self):
     root = milkman.deliver(Root)
     assert isinstance(root.my_auto, int)
     try:
         assert isinstance(
             root.my_biginteger, type(models.BigIntegerField.MAX_BIGINT))
     except AttributeError:
         pass
     assert isinstance(root.my_boolean, bool)
     assert isinstance(root.my_char, str)
     assert isinstance(root.my_commaseperatedinteger, str)
     assert isinstance(root.my_date, str)
     assert isinstance(root.my_datetime, str)
     assert isinstance(root.my_decimal, str)
     assert isinstance(root.my_email, str)
     assert isinstance(root.my_float, float)
     assert isinstance(root.my_integer, int)
     assert isinstance(root.my_ip, str)
     assert (isinstance(root.my_nullboolean, bool)
             or isinstance(root.my_nullboolean, types.NoneType))
     assert isinstance(root.my_positiveinteger, int)
     assert isinstance(root.my_positivesmallinteger, int)
     assert isinstance(root.my_slug, str)
     assert isinstance(root.my_smallinteger, int)
     assert isinstance(root.my_text, str)
     assert isinstance(root.my_time, str)
Esempio n. 39
0
    def handle(self, *args, **options):
        amount = int(args[0])
        for i in range(amount):
            start_date = random_date(
                datetime.now()+timedelta(days=1),
                datetime.now()+timedelta(days=30))
            end_date = random_date(
                start_date,
                start_date+timedelta(days=30)
            )
            users = []
            for j in range(random.randint(2, 4)):
                user = User.objects.order_by('?')[0]
                if user not in users:
                    users.append(user)
            try:
                country = Country.objects.order_by('?')[0]
            except IndexError:
                country = Country.objects.get_or_create_normalized(
                    name=random.choice(countries))
            trip = milkman.deliver('trip.trip',
                start_date=start_date, end_date=end_date,
                country=country,
                city=random.choice(cities),
                title=u"Поездка_{0}".format(i),
                people=users,
                owner=User.objects.all()[0]
            )
            self.stdout.write("Created trip '{0}'".format(trip))

        self.stdout.write("Successfully created test trips")
Esempio n. 40
0
 def setUp(self):
     "set up trip"
     super(TripDeleteViewTests, self).setUp()
     self.trip = milkman.deliver(Trip)
     self.addCleanup(self.trip.delete)
     self.url = reverse("trips:delete", kwargs={"pk": self.trip.pk})
     self.trip.fully_authorize(self.user)
Esempio n. 41
0
    def test_move_nested_tag_to_root_no_sibling(self):
        """
            Passing parent_tag_id=0 should move the tag to root
        """
        tag_2 = milkman.deliver(GlobalTag, name="tag2")

        nested_project_tag = self.projecttag.add_child(
            global_tag=tag_2, project=self.project
        )

        self._sign_in(self.admin)
        request = MoveProjectTagContainer.combined_message_class(
            project_id=self.project.pk,
            project_tag_id=nested_project_tag.pk,
            parent_tag_id=0
        )

        with self.assertNumQueries(11):
            response = self.api.projecttag_move(request)

        nested_project_tag = self.reload(nested_project_tag)

        self.assertTrue(nested_project_tag.is_root())
        self.assertFalse(nested_project_tag.is_child_of(self.projecttag))

        self.assertEqual(nested_project_tag, ProjectTag.get_last_root_node())
Esempio n. 42
0
    def test_options(self):
        self.assertTrue('OPTIONS' in ArticleResource.allowed_methods)
        uri = self.reverse('author-test-book-article', book=self.book.pk)
        response = self.client.options(uri, data=dict(author=self.author.pk))
        self.assertContains(response, 'OK')

        author = milkman.deliver('main.author')
        response = self.client.options(uri, data=dict(author=author.pk))
        self.assertContains(response, 'OK')
Esempio n. 43
0
    def create_page(self, **kwargs):
        letters = list(string.letters)
        random.shuffle(letters)
        random_name = ''.join(letters[:10])

        page_kwargs = {'name' : random_name}
        page_kwargs.update(kwargs)
        
        return milkman.deliver(Page, **page_kwargs)
Esempio n. 44
0
    def setUp(self):
        settings.TEST = True

        cache.clear()
   #     johnny_cache.disable()

        self.page = milkman.deliver(WebPage, slug='test-page', title="Test page")
        self.user = User.objects.create_user(username='******',
            email='*****@*****.**', password='******')
        self.client.login(username='******', password='******')
Esempio n. 45
0
    def test_simply(self):
        from adrest.utils.serializer import BaseSerializer
        from .models import Task
        user = milkman.deliver('auth.User', username="******")
        data = [milkman.deliver(Task, user=user), milkman.deliver(Task, user=user),
                28, 'string']

        serializer = BaseSerializer(_exclude='fake', _include='username', user=dict(
            _fields='email'))
        self.assertEqual(serializer.options['_exclude'], set(['fake']))

        out = serializer.to_simple(data)
        self.assertEqual(out[0]['fields']['username'], data[0].user.username)

        # Test m2o serialization
        serializer = BaseSerializer(_include="task_set", task_set=dict(
            _fields=[]))
        out = serializer.to_simple(user)

        self.assertEquals(len(out['fields']['task_set']), 2)
        for task in out['fields']['task_set']:
            self.assertEquals(task['fields']['user'], user.pk)
            self.assertTrue('title' in task['fields'].keys())
Esempio n. 46
0
    def test_multiple_sorting(self):

        testuser = milkman.deliver(User)
        testuser.set_password("letmein")
        testuser.save()

        self.create_entries(3, user=testuser)
        self.assertEqual(LogEntry.objects.count(), 6)
        self.assertViewRenders("""
                {% sort objects with "objects" as objects %}
                {% sort others with "others" as others %}
                {{ objects|sorter_tests_pks }}.{{ others|sorter_tests_pks }}
            """, "3.2.1.6.5.4", {"sort_objects": "-id", "sort_others": "-id"},
            objects=LogEntry.objects.exclude(user=testuser),
            others=LogEntry.objects.filter(user=testuser))
Esempio n. 47
0
    def setUp(self):
        """ Create test tree
        """
        root1 = milkman.deliver(Page)
        page11 = milkman.deliver(Page, parent=root1)
        page12 = milkman.deliver(Page, parent=root1)
        page111 = milkman.deliver(Page, parent=page11)
        page1111 = milkman.deliver(Page, parent=page111)
        page1112 = milkman.deliver(Page, parent=page111)

        self.__dict__.update(locals())
Esempio n. 48
0
    def handle(self, *args, **options):
        amount = int(args[0])
        for i in range(amount):
            gender = random.choice((User.GENDERS.male, User.GENDERS.female))
            user = milkman.deliver('users.user',
                email="test_{0}@mail.com".format(i),
                provider="facebook",
                birthday=random_date(
                    datetime.now()-timedelta(days=70*365),
                    datetime.now()-timedelta(days=18*365)
                ),
                gender=gender,
                first_name=str(i),
                last_name="_" + str(gender)
            )
            self.stdout.write("Created user '{0}'".format(user))

        self.stdout.write("Successfully created test users")
Esempio n. 49
0
    def setUp(self):
        self.show = milkman.deliver(Show, title="snowprayers")
        self.show.save()
        self.episodes = []
        for i in range(0, 10):
            episode = milkman.deliver(Episode, show=self.show, title="Episode 1")
            episode.save()
            self.episodes.append(episode)
        self.episode = milkman.deliver(Episode, show=self.show, title="Episode")
        self.episode.save()
        long_title = "".join(["x" for i in range(51)])
        self.long_episode1 = milkman.deliver(Episode, show=self.show, title=long_title)
        self.long_episode1.save()

        self.long_episode2 = milkman.deliver(Episode, show=self.show, title=long_title)
        self.long_episode2.save()

        self.enclosure = milkman.deliver(Enclosure, episode=self.episodes[0])
        self.enclosure.save()
Esempio n. 50
0
 def setUp(self):
     super(ViewTests, self).setUp()
     self.user = milkman.deliver(User)
     self.user.set_password('password')
     self.user.save()
     self.client.login(username=self.user.username, password='******')
Esempio n. 51
0
 def test_m2m_model_self(self):
     child = milkman.deliver(PsychoChild)
     self.assertEquals(child.alter_egos.all().count(), 1)
     self.assertEquals(PsychoChild.objects.all().count(), 2)
Esempio n. 52
0
 def test_m2m_related_explicit_values(self):
     aunt = milkman.deliver(Aunt, uncles__name='foo')
     self.assertEqual(1, len(aunt.uncles.all()))
     self.assertEqual(aunt.uncles.all()[0].name, 'foo')
Esempio n. 53
0
 def setUp(self):
     super(UserRoleTests, self).setUp()
     self.user = milkman.deliver(User)
     set_user_role(self.user, roles.manager)
Esempio n. 54
0
 def setUp(self):
     self.api_page_json = os.path.join(self.get_api_url('page'), '?format=json')
     self.page = milkman.deliver(WebPage, slug='test-page', title='Test page')
Esempio n. 55
0
 def deliver(self, *args, **kwargs):
     obj = milkman.deliver(*args, **kwargs)
     self.addCleanup(obj.delete)
     return obj
Esempio n. 56
0
 def setUp(self):
     self.jacket = milkman.deliver(Item)
     self.trousers = milkman.deliver(Item)
Esempio n. 57
0
 def setUp(self):
     self.jacket = milkman.deliver(Item)
     self.trousers = milkman.deliver(Item)
     self.item_admin = ItemAdmin(Item, site)
     self.notification_inline = NotificationInline(self.item_admin, site)
Esempio n. 58
0
 def setUp(self):
     self.jacket = milkman.deliver(Item, name="jacket")
     self.url = "/lost_found/jacket/"
     self.client = Client()
     self.response = self.client.get(self.url, follow=True)
Esempio n. 59
0
 def setUp(self):
     self.url = "/lost_found/"
     self.client = Client()
     self.jacket = milkman.deliver(Item, lost=date(1, 1, 1))
     self.trousers = milkman.deliver(Item, lost=date(1, 1, 2))
     self.response = self.client.get(self.url, follow=True)
Esempio n. 60
0
 def setUp(self):
     self.hi = milkman.deliver(Notification)
     self.hello = milkman.deliver(Notification)