def setUp(self): u = User.objects.create_user("testuser", "info@localhost", "******") u.is_active = False #u.save() # adresa a = Address() a.company = "xxx" a.residency_name = "xxx" a.residency_street = "xxx" a.residency_city = "xxx" a.residency_city_num = "56301" a.residency_ic = "1234" a.residency_dic = "CZ1234" a.residency_email = "info@localhost" a.residency_phone = "+420123456789" #a.save() # machine m = Machine() m.ipv6 = "::1" m.ipv4 = "127.0.0.1" m.domain = "localhost" m.name = "Localhost" #m.save() # parms p = Parms() p.home = "/home/testuser" p.note = "" p.uid = 1000 p.gid = 1000 p.discount = 0 p.address = a p.web_machine = m p.mail_machine = m p.mysql_machine = m p.pgsql_machine = m p.user = u #p.save() self.user = u self.parms = p self.machine = m self.address = a self.factory = RequestFactory() self.basic_request = self.factory.get("/") self.basic_request.user = self.user self.basic_request.session = {}
def handle(self, *args, **options): address_json = os.path.join(settings.ROOT, "..", "migration", "address.json") with open(address_json) as f: data = json.load(f) for user in User.objects.all(): for address in data: address = address["fields"] if address.get("email") == user.email and address.get("config") == 1: print "%s %s" % (address.get("first_name"), address.get("last_name")) new_address = Address() new_address.default = True if Address.objects.filter(user=user).count() > 0: new_address.default = False new_address.company = address.get("company") new_address.first_name = address.get("first_name") new_address.last_name = address.get("last_name") new_address.street = address.get("street") new_address.city = address.get("city") new_address.zip = address.get("zip") new_address.phone = address.get("phone") new_address.email = address.get("email") new_address.company_number = address.get("company_number") new_address.vat_number = address.get("vat_number") new_address.user = user new_address.save() break