Ejemplo n.º 1
0
class SecretSantaParametersTest(unittest.TestCase):

  def setUp(self):
    self.ssp = SecretSantaParameters()
    self.ssp.guestList = [Guest(name, "*****@*****.**" % name) for name in \
                          ["John", "Jack", "Julia"]]

  def testInitFromFile(self):
    self.ssp.initFromFile(os.path.join(getDataPath(), "sample.yaml"))

  def testInitFromFileWithNoOptionalParameters(self):
    with open(os.path.join(getDataPath(), "sample.yaml"), 'r') as f:
      params = yaml.load(f)
    params.pop("Couples")
    params.pop("No_match")
    with patch('pycret_santa.config.open',
        mock_open(read_data=yaml.dump(params)), create=True) as m:
      self.ssp.initFromFile("dummy")


  def testHandleCouples(self):
    couples = ["Julia %s John" % Separators.COUPLE]
    self.ssp._handleCouples(couples)
    self.assertEquals(self.ssp.guestList[0].unauthorizedMatches, set(["Julia"]))
    self.assertEquals(self.ssp.guestList[1].unauthorizedMatches, set())
    self.assertEquals(self.ssp.guestList[2].unauthorizedMatches, set(["John"]))

  def testHandleNoMatchList(self):
    noMatches = ["Jack %s John" % Separators.NO_MATCH]
    self.ssp._handleNoMatchList(noMatches)
    self.assertEquals(self.ssp.guestList[0].unauthorizedMatches, set())
    self.assertEquals(self.ssp.guestList[1].unauthorizedMatches, set(["John"]))
    self.assertEquals(self.ssp.guestList[2].unauthorizedMatches, set())
Ejemplo n.º 2
0
 def getFromConfigFile(self, filePath):
   params = SecretSantaParameters()
   params.initFromFile(filePath)
   return self._getSecretSanta(params)