Exemplo n.º 1
0
    def test_post(self):
        post = Post()
        
        user = User.objects.create_user('Testy McTest', '*****@*****.**', 'testpassword')
        user.save()
        
        group = Group()
        group.name = "Test Group"
        group.save()
        
        membership = Membership()
        membership.user = User.objects.get(id = user.id)
        membership.group = Group.objects.get(id = group.id)
        membership.save()
        
        post.author = Membership.objects.get(id = membership.id)
        post.message = "Testing321"

        post.save()
    
        test_post = Post.objects.get(id = post.id)
        
        self.assertEquals(test_post, post)
        self.assertEquals(test_post.author, Membership.objects.get(id = membership.id))
        self.assertEquals(test_post.message, "Testing321")
   
        post.delete()
        membership.delete()
        group.delete()
        user.delete()
Exemplo n.º 2
0
def combine(requester, post, signup, num_slots_to_combine):

    timeblock_list = signup.myblocks.all()
    new_post = Post(author=requester, content=post.content)
    new_post.save()
    new_sign = SignUp(post=new_post,
                      name=signup.name,
                      location=signup.location,
                      max_slots=signup.max_slots,
                      max_duration=signup.max_duration,
                      min_duration=signup.min_duration)
    new_sign.save()

    for block in timeblock_list:
        new_block = TimeBlock(sheet=new_sign,
                              start_time=block.start_time,
                              end_time=block.end_time)
        new_block.save()
        slot_list = block.myslots.all()

        i = 0
        j = i + num_slots_to_combine

        while j <= len(slot_list):
            new_owner = None
            for index in range(i, j):
                if (slot_list[index].owner == None) or (slot_list[index].owner
                                                        == requester):
                    print 'Available slot'
                else:
                    print 'Slot taken by: ' + slot_list[index].owner.username
                    new_owner = slot_list[index].owner

            new_slot = SignUpSlot(owner=new_owner,
                                  block=new_block,
                                  start_time=slot_list[i].start_time,
                                  end_time=slot_list[j - 1].end_time)
            if new_owner == None:
                new_slot.save()
            i = i + 1
            j = j + 1

    data = SignUpSheetSerializer(new_sign,
                                 context={
                                     'is_owner': False,
                                     'requester': requester.username
                                 })

    print data.data
    new_sign.delete()
    new_post.delete()
    return data.data
Exemplo n.º 3
0
def markdown_post():
    post = Post(
        title='My Post',
        content_markdown=inspect.cleandoc("""
        Heading
        =======

        Body text
        """)
    )
    post.save()
    yield post
    post.delete()
Exemplo n.º 4
0
class TestPostLikeModel(TestCase):
    def setUp(self):
        self.testuser = User(username="******", email="*****@*****.**")
        self.testuser.save()
        self.testpost = Post(user=self.testuser,
                             url="www.example.com/testimage1.jpeg",
                             likes=0)
        self.testpost.save()
        self.testlike = PhotoLikes(postid=self.testpost.id,
                                   liker=self.testuser.username)
        self.testlike.save()

    def test_is_instance(self):
        self.assertIsInstance(self.testpost, Post)

    def test_str_post_method(self):
        self.assertEqual(self.testpost.__str__(), self.testpost.url)

    def test_str_like_method(self):
        self.assertEqual(self.testlike.__str__(),
                         'liker:{}'.format(self.testlike.liker))

    def test_save_delete(self):
        self.testpost2 = Post(user=self.testuser,
                              url="www.example.com/testimage2.jpeg",
                              likes=0)
        self.assertNotIn(self.testpost2, Post.objects.all())
        self.testpost2.save_pic()
        self.assertIn(self.testpost2, Post.objects.all())
        self.testpost2.delete()
        self.assertNotIn(self.testpost2, Post.objects.all())

    def test_like_is_instance(self):
        self.assertIsInstance(self.testlike, PhotoLikes)

    def test_like(self):
        self.assertIn(self.testlike, PhotoLikes.objects.all())

    def test_get_like_user(self):
        self.assertEqual(self.testuser, self.testlike.get_user())

    def test_getnumber_of_likes(self):
        self.likes = PhotoLikes.objects.filter(postid=self.testpost.id).count()
        self.assertEqual(self.likes, self.testpost.get_number_of_likes())

    def tearDown(self):
        self.testpost.delete()
        self.testuser.delete()
        self.testlike.delete()
Exemplo n.º 5
0
def combine(requester, post, signup, num_slots_to_combine):

    timeblock_list = signup.myblocks.all()
    new_post = Post(author = requester, content = post.content)
    new_post.save()
    new_sign = SignUp(post = new_post, name = signup.name, location = signup.location,
                      max_slots = signup.max_slots, max_duration = signup.max_duration,
                      min_duration = signup.min_duration)
    new_sign.save()

    for block in timeblock_list:
        new_block = TimeBlock(sheet = new_sign, start_time= block.start_time, end_time = block.end_time)
        new_block.save()
        slot_list = block.myslots.all()

        i = 0
        j = i + num_slots_to_combine

        while j <= len(slot_list):
            new_owner = None
            for index in range(i,j):
                if (slot_list[index].owner == None) or (slot_list[index].owner == requester):
                    print 'Available slot'
                else:
                    print 'Slot taken by: ' + slot_list[index].owner.username
                    new_owner = slot_list[index].owner

            new_slot = SignUpSlot(owner = new_owner, block = new_block,
                                  start_time = slot_list[i].start_time, end_time = slot_list[j - 1].end_time)
            if new_owner == None:
                new_slot.save()
            i = i + 1
            j = j + 1


    data = SignUpSheetSerializer(new_sign, context={'is_owner': False, 'requester': requester.username})

    print data.data
    new_sign.delete()
    new_post.delete()
    return data.data
Exemplo n.º 6
0
def posts():
    post0 = Post(title='My Post')
    post0.save()
    post1 = Post(title='My Post')
    post1.save()
    post2 = Post(title='My Post')
    post2.save()
    yield post0, post1, post2
    post2.delete()
    post1.delete()
    post0.delete()
Exemplo n.º 7
0
def get_post():
    post = Post(title='My Post')
    post.save()
    yield post
    post.delete()
Exemplo n.º 8
0
def delete_view (request, post_id):
  post = Post (pk=post_id)
  post.delete()
  return HttpResponseRedirect ('/posts')