def get_domains():
    """
    Coroutine - Get all domains from db `DomainExpiration`
    """
    for domain in db.domains.find():
        domain = DomainExpiration(**domain)
        yield from domain.run()
Example #2
0
    async def _post_(self, request):
        data = await request.post()
        domain = data.get('domain', "")
        domain_expiration = DomainExpiration(domain=domain)

        if not domain_expiration.name:
            response = {"response": "KO", "message": self.EMPTY_DOMAIN}
        elif not domain_expiration.allowed:
            response = {"response": "KO", "message": self.ALLOWED}

        elif self.db.domains.find_one({"name": domain_expiration.name}):
            response = {"response": "KO", "message": self.EXISTS}

        else:
            domain_expiration.save()
            response = {"response": "OK"}

        return web.json_response(response)
Example #3
0
 def test_whois_me(self):
     domain_expiration = DomainExpiration(domain='albertpalenzuela.com')
     with asynctest.mock.patch('asyncio.subprocess.create_subprocess_exec') as sub_proc:
         sub_proc.return_value = self.P(mock_comunicate, 0)
         resp = asyncio.get_event_loop().run_until_complete(
            domain_expiration.whois_me())
         self.assertEqual(resp, valid_resp.decode())
         self.assertEqual(domain_expiration.available, False)
         # Return code 1
         sub_proc.return_value = self.P(mock_comunicate, 1)
         resp = asyncio.get_event_loop().run_until_complete(
            domain_expiration.whois_me())
         self.assertEqual(resp, valid_resp.decode())
         self.assertEqual(domain_expiration.available, True)
         # Different return code
         from functools import partial
         sub_proc.return_value = self.P(partial(mock_comunicate, ''), choice(range(2, 10)))
         with self.assertRaises(Exception) as e:
             asyncio.get_event_loop().run_until_complete(
             domain_expiration.whois_me())
             self.assertEqual('', e)
Example #4
0
 def test_domain_to_dict(self):
     # Without name
     domain_expiration = DomainExpiration(domain='albertpalenzuela.com')
     self.assertTrue('name' not in domain_expiration.to_dict())
     # With name
     self.assertTrue('name' in domain_expiration.to_dict(name=True))