import unittest
from conans.test.utils.tools import TestClient, TestServer
from conans.model.ref import ConanFileReference, PackageReference
import os
from conans.test.utils.cpp_test_files import cpp_hello_conan_files
from conans.util.files import load, save
from time import sleep
import time
from conans.paths import CONAN_MANIFEST


class InstallMissingDependency(unittest.TestCase):

    def missing_dep_test(self):
        test_server = TestServer()
        self.servers = {"myremote": test_server}
        self.client = TestClient(servers=self.servers, users={"myremote": [("lasote", "mypass")]})

        # Create deps packages
        dep1_conanfile = """from conans import ConanFile
class Dep1Pkg(ConanFile):
    name = "dep1"
        """

        dep2_conanfile = """from conans import ConanFile
class Dep2Pkg(ConanFile):
    name = "dep2"
    version = "1.0"
    requires = "dep1/1.0@lasote/testing"
        """

        self.client.save({"conanfile.py": dep1_conanfile}, clean_first=True)
        self.client.run("create . dep1/1.0@lasote/testing")
        self.client.run("create . dep1/2.0@lasote/testing")

        self.client.save({"conanfile.py": dep2_conanfile}, clean_first=True)
        self.client.run("create . lasote/testing")

        foo_conanfile = """from conans import ConanFile
class FooPkg(ConanFile):
    name = "foo"
    version = "1.0"
    requires = "dep1/{dep1_version}@lasote/testing", "dep2/1.0@lasote/testing"
        """
        self.client.save({"conanfile.py": foo_conanfile.format(dep1_version="1.0")},
                         clean_first=True)
        error = self.client.run("create . lasote/testing")
        self.assertFalse(error)

        self.client.save({"conanfile.py": foo_conanfile.format(dep1_version="2.0")},
                         clean_first=True)
        error = self.client.run("create . lasote/testing", ignore_error=True)
        self.assertTrue(error)
        self.assertIn("Can't find a 'dep2/1.0@lasote/testing' package", self.client.user_io.out)
        self.assertIn("- Dependencies: dep1/2.0@lasote/testing", self.client.user_io.out)


@@ -425,139 +425,28 @@
     
-test_server = TestServer()%0A        self.servers = %7B%22myremote%22: test_server%7D%0A        self.client = TestClient(servers=self.servers, 
+client = TestClient(
 user
@@ -806,37 +806,32 @@
    %22%22%22%0A%0A        
-self.
 client.save(%7B%22co
@@ -878,37 +878,32 @@
 t=True)%0A        
-self.
 client.run(%22crea
@@ -933,37 +933,32 @@
 sting%22)%0A        
-self.
 client.run(%22crea
@@ -989,37 +989,32 @@
 ting%22)%0A%0A        
-self.
 client.save(%7B%22co
@@ -1065,29 +1065,24 @@
 ue)%0A        
-self.
 client.run(%22
@@ -1100,32 +1100,63 @@
 sote/testing%22)%0A%0A
+        # Create final package%0A
         foo_cona
@@ -1348,37 +1348,32 @@
     %22%22%22%0A        
-self.
 client.save(%7B%22co
@@ -1431,33 +1431,8 @@
 %22)%7D,
-%0A                        
  cle
@@ -1450,37 +1450,24 @@
 ue)%0A        
-error = self.
 client.run(%22
@@ -1492,24 +1492,25 @@
 sting%22)%0A
+%0A
         
 self.ass
@@ -1505,32 +1505,40 @@
     
-self.assertFalse(error)%0A
+# Bump version of one dependency
 %0A   
@@ -1542,21 +1542,16 @@
         
-self.
 client.s
@@ -1617,33 +1617,8 @@
 %22)%7D,
-%0A                        
  cle
@@ -1648,21 +1648,16 @@
 error = 
-self.
 client.r
@@ -1808,21 +1808,16 @@
 ckage%22, 
-self.
 client.u
@@ -1893,21 +1893,16 @@
 sting%22, 
-self.
 client.u

remove server and 'self.' from places where it is not needed