Example #1
0
    def test_get_not_found(self):
        """
        Test that getting a non-existent domain raises a StrongarmHttpError.

        """

        name = 'non-existent.example.com'
        msg = 'The domain does not exist.'

        responses.add(responses.GET, strongarm.host + Domain.endpoint + name + '/',
                      status=404, content_type='application/json',
                      body=json.dumps({'detail': msg}))

        with self.assertRaises(strongarm.StrongarmHttpError) as exp:
            Domain.get(name)

        self.assertEqual(len(responses.calls), 1)

        self.assertEqual(exp.exception.status_code, 404)
        self.assertEqual(exp.exception.detail, msg)
Example #2
0
    def test_delete_not_found(self):
        """
        Test that deleting a non-existent domain raises StrongarmHttpError.

        """

        name = 'non-existent.example.com'

        responses.add(responses.DELETE, strongarm.host + Domain.endpoint + name + '/',
                      status=404)

        # Create the Domain instance manually.
        domain = Domain({'name': name})

        # Now delete the domain.
        with self.assertRaises(strongarm.StrongarmHttpError) as exp:
            domain.delete()

        self.assertEqual(len(responses.calls), 1)
        self.assertEqual(exp.exception.status_code, 404)
Example #3
0
    def test_list(self):
        """
        Test that getting all domains returns a PaginatedResourceList with the
        right elements.

        """

        responses.add(responses.GET, strongarm.host + Domain.endpoint,
                      body=json.dumps(self.list_response),
                      content_type='application/json')

        domains = Domain.all()

        self.assertEqual(len(responses.calls), 1)

        self.assertEqual(len(domains), self.list_response['count'])
        self.assertIsInstance(domains[0], Domain)
        self.assertEqual(domains[0].name, self.list_response['results'][0]['name'])
Example #4
0
    def test_get_exists(self):
        """
        Test that getting an existing blackholed domain returns an instance of
        Domain with the right attributes.

        """

        name = self.get_response['name']

        responses.add(responses.GET, strongarm.host + Domain.endpoint + name + '/',
                      body=json.dumps(self.get_response),
                      content_type='application/json/')

        domain = Domain.get(name)

        self.assertEqual(len(responses.calls), 1)

        self.assertIsInstance(domain, Domain)
        self.assertEqual(domain.name, name)
Example #5
0
    def test_create(self):
        """
        Test that creating a new blackholed domain returns an instance of
        Domain with the right attributes.

        """

        name = self.get_response['name']

        responses.add(responses.POST, strongarm.host + Domain.endpoint,
                      body=json.dumps(self.get_response),
                      content_type='application/json')

        domain = Domain.create(name=name)

        self.assertEqual(len(responses.calls), 1)

        self.assertIsInstance(domain, Domain)
        self.assertEqual(domain.name, name)
Example #6
0
    def test_delete_success(self):
        """
        Test that deleting a domain succeeds silently.

        """

        name = self.get_response['name']

        responses.add(responses.GET, strongarm.host + Domain.endpoint + name + '/',
                      body=json.dumps(self.get_response),
                      content_type='application/json/')
        responses.add(responses.DELETE, strongarm.host + Domain.endpoint + name + '/',
                      status=204)

        # First get the domain to be deleted
        domain = Domain.get(name)

        self.assertEqual(len(responses.calls), 1)

        # Now delete the domain.
        result = domain.delete()

        self.assertEqual(len(responses.calls), 2)
        self.assertIsNone(result)