Exemplo n.º 1
0
    def test_get_private_registry_config(self, mock_requests):
        registry = {'username': '******', 'password': '******'}
        auth = bytes('{}:{}'.format("test", "test"), 'UTF-8')
        encAuth = base64.b64encode(auth).decode(encoding='UTF-8')
        image = 'test/test'

        docker_config, name, create = App()._get_private_registry_config(
            image, registry)
        dockerConfig = json.loads(docker_config)
        expected = {"https://index.docker.io/v1/": {"auth": encAuth}}
        self.assertEqual(dockerConfig.get('auths'), expected)
        self.assertEqual(name, "private-registry")
        self.assertEqual(create, True)

        image = "quay.io/test/test"
        docker_config, name, create = App()._get_private_registry_config(
            image, registry)
        dockerConfig = json.loads(docker_config)
        expected = {"quay.io": {"auth": encAuth}}
        self.assertEqual(dockerConfig.get('auths'), expected)
        self.assertEqual(name, "private-registry")
        self.assertEqual(create, True)
Exemplo n.º 2
0
def app_list(request):

    if request.method == 'GET':
        groupid = request.GET.get('groupid', None)
        if groupid:
            tasks = App.objects.filter(enable=1).filter(group_id=groupid).all()
        else:
            tasks = App.objects.filter(enable=1).all()
        serializer = AppSerializer(tasks, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        name = request.data.get("name", None)
        app = App.create(name, 1, "OK", "", 1, 2).save()
        serializer = AppSerializer(app, many=False)
        return JsonResponse(serializer.data, safe=False)
Exemplo n.º 3
0
def app_list(request):

    if request.method == 'GET':
        groupid = request.GET.get('groupid', None)
        if groupid:
            tasks = App.objects.filter(enable=1).filter(group_id=groupid).all()
        else:
            tasks = App.objects.filter(enable=1).all()
        serializer = AppSerializer(tasks, many=True)
        return Response(serializer.data)

    elif request.method == 'POST':
        name = request.data.get("name", None)
        app = App.create(name, 1, "OK", "", 1, 2).save()
        serializer = AppSerializer(app, many=False)
        return JsonResponse(serializer.data, safe=False)
Exemplo n.º 4
0
 def test_object_to_json_not_list(self):
     app1 = App.create("name", 1, "OK", "message", 1, 1)
     self.assertTrue('FOO'.isupper())
     self.assertFalse('Foo'.isupper())
Exemplo n.º 5
0
        self.assertEqual('foo'.upper(), 'FOO')

    def test_isupper(self):
        self.assertTrue('FOO'.isupper())
        self.assertFalse('Foo'.isupper())

    def test_split(self):
        s = 'hello world'
        self.assertEqual(s.split(), ['hello', 'world'])


class TestUtilsMethods(unittest.TestCase):
    def test_verification_string_is_json(self):
        json_str = '{"name":"xiaomin"}'
        not_json_str = '{"name":"xiaomin"dd}'
        self.assertTrue(verification_string_is_json(json_str))
        self.assertFalse(verification_string_is_json(not_json_str))
        self.assertFalse(verification_string_is_json(""))

    def test_object_to_json_not_list(self):
        app1 = App.create("name", 1, "OK", "message", 1, 1)
        self.assertTrue('FOO'.isupper())
        self.assertFalse('Foo'.isupper())

    def test_object_to_json_is_list(self):
        s = 'hello world'
        self.assertEqual(s.split(), ['hello', 'world'])


app1 = App.create("name", 1, "OK", "message", 1, 1)
Exemplo n.º 6
0
 def _init_App(self):
     App.create("unique_name0", 1, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name1", 2, MonitoringStatus.CRITICAL, "", 1,
                1).save()
     App.create("unique_name2", 3, MonitoringStatus.WARN, "", 1, 1).save()
     App.create("unique_name3", 1, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name4", 3, MonitoringStatus.CRITICAL, "", 1,
                1).save()
     App.create("unique_name5", 2, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name6", 1, MonitoringStatus.CRITICAL, "", 1,
                1).save()
     App.create("unique_name7", 2, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name8", 3, MonitoringStatus.CRITICAL, "", 1,
                1).save()
     App.create("unique_name9", 1, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name10", 2, MonitoringStatus.WARN, "", 1, 1).save()
     App.create("unique_name11", 1, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name12", 3, MonitoringStatus.WARN, "", 1, 1).save()
     App.create("unique_name13", 1, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name14", 2, MonitoringStatus.WARN, "", 0, 1).save()
     App.create("unique_name15", 1, MonitoringStatus.OK, "", 0, 1).save()
Exemplo n.º 7
0
 def _init_App(self):
     App.create("unique_name0", 1, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name1", 2, MonitoringStatus.CRITICAL, "", 1, 1).save()
     App.create("unique_name2", 3, MonitoringStatus.WARN, "", 1, 1).save()
     App.create("unique_name3", 1, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name4", 3, MonitoringStatus.CRITICAL, "", 1, 1).save()
     App.create("unique_name5", 2, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name6", 1, MonitoringStatus.CRITICAL, "", 1, 1).save()
     App.create("unique_name7", 2, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name8", 3, MonitoringStatus.CRITICAL, "", 1, 1).save()
     App.create("unique_name9", 1, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name10", 2, MonitoringStatus.WARN, "", 1, 1).save()
     App.create("unique_name11", 1, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name12", 3, MonitoringStatus.WARN, "", 1, 1).save()
     App.create("unique_name13", 1, MonitoringStatus.OK, "", 1, 1).save()
     App.create("unique_name14", 2, MonitoringStatus.WARN, "", 0, 1).save()
     App.create("unique_name15", 1, MonitoringStatus.OK, "", 0, 1).save()