# -*- coding: utf-8 -*-
# Copyright (c) 2012 The Pycroft Authors. See the AUTHORS file.
# This file is part of the Pycroft project and licensed under the terms of
# the Apache License, Version 2.0. See the LICENSE file for details.

from tests import FixtureDataTestBase, make_fixture
from pycroft.lib import user as UserHelper
from tests.fixtures.user_fixtures import DormitoryData, RoomData, UserData, NetDeviceData, HostData
from pycroft.model import user, dormitory, session

class Test_010_User_Move(FixtureDataTestBase):
    datasets = [DormitoryData, RoomData, UserData, NetDeviceData, HostData]

    def setUp(self):
        super(Test_010_User_Move, self).setUp()
        self.user = user.User.q.get(1)
        self.old_room = dormitory.Room.q.get(1)
        self.new_room_other_dormitory = dormitory.Room.q.get(2)
        self.new_room_same_dormitory = dormitory.Room.q.get(3)

    def test_010_moves_into_same_room(self):
        self.assertRaises(AssertionError, UserHelper.move,
            self.user, self.old_room.dormitory, self.old_room.level,
             self.old_room.number, self.user)

@@ -224,16 +224,39 @@
 details.
+%0A__author__ = 'florian'
 %0A%0Afrom t
@@ -443,16 +443,61 @@
 HostData
+, IpData, VLanData, SubnetData, PatchPortData
 %0Afrom py
@@ -536,15 +536,31 @@
 ry, 
-session
+ports, session, logging
 %0A%0Acl
@@ -678,16 +678,77 @@
 HostData
+,%0A                IpData, VLanData, SubnetData, PatchPortData
 %5D%0A%0A    d
@@ -842,32 +842,82 @@
 r.User.q.get(1)%0A
+        self.processing_user = user.User.q.get(2)%0A
         self.old
@@ -1079,224 +1079,903 @@
 (3)%0A
-%0A    def test_010_moves_into_same_room(self):%0A        self.assertRaises(AssertionError, UserHelper.move,%0A            self.user, self.old_room.dormitory, self.old_room.level,%0A             self.old_room.number, self.user)
+        self.new_patch_port = ports.PatchPort.q.get(2)%0A%0A    def tearDown(self):%0A        #TODO dont delete all log entries but the userlogentries%0A        logging.LogEntry.q.delete()%0A        session.session.commit()%0A        super(Test_010_User_Move, self).tearDown()%0A%0A%0A    def test_010_moves_into_same_room(self):%0A        self.assertRaises(AssertionError, UserHelper.move,%0A            self.user, self.old_room.dormitory, self.old_room.level,%0A            self.old_room.number, self.processing_user)%0A%0A    def test_020_moves_into_other_dormitory(self):%0A        UserHelper.move(self.user, self.new_room_other_dormitory.dormitory,%0A            self.new_room_other_dormitory.level,%0A            self.new_room_other_dormitory.number, self.processing_user)%0A        self.assertEqual(self.user.room, self.new_room_other_dormitory)%0A        self.assertEqual(self.user.hosts%5B0%5D.room, self.new_room_other_dormitory)%0A
 %0A

add a test for moving into another dormitory