This repository has been archived by the owner on Feb 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jaroslav Sevcik
committed
Jul 12, 2021
1 parent
0add7ca
commit 034f65f
Showing
12 changed files
with
309 additions
and
78 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import pytest | ||
|
||
import zoo.repos.tasks as uut | ||
from zoo.entities.models import Entity | ||
from zoo.libraries.models import Library | ||
from zoo.services.models import Service | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
def test_create_base_component(mocker, repository_factory): | ||
repository = repository_factory( | ||
id=1, | ||
remote_id=11, | ||
name="test_proj1", | ||
owner="john_doe1", | ||
url="https://github.co m/john_doe1/test_proj1", | ||
provider="github", | ||
) | ||
repository_dict = {"id": repository.remote_id, "provider": repository.provider} | ||
|
||
base_component = """ | ||
- apiVersion: v1alpha1 | ||
kind_: component | ||
metadata: | ||
name: base | ||
owner: platform | ||
group: | ||
product_owner: john | ||
project_owner: doe | ||
maintainers: [] | ||
description: This is my fancy component | ||
tags: [] | ||
links: | ||
- name: Datadog | ||
url: https://dashboard.datadog.com | ||
icon: poop | ||
- name: Sentry | ||
url: https://sentry.skypicker.com | ||
spec: | ||
type_: database | ||
""" | ||
|
||
mocker.patch("zoo.repos.tasks.get_entity_file_content", return_value=base_component) | ||
uut.update_project_from_entity_file(proj=repository_dict) | ||
component_entity = Entity.objects.first() | ||
assert Entity.objects.all().count() == 1 | ||
assert component_entity.kind == "component" | ||
assert component_entity.name == "base" | ||
assert component_entity.owner == "platform" | ||
assert component_entity.service is None | ||
assert component_entity.library is None | ||
assert component_entity.type == "database" | ||
assert component_entity.links.all().count() == 2 | ||
assert component_entity.group | ||
|
||
|
||
def test_create_base_component_and_service(mocker, repository_factory): | ||
repository = repository_factory( | ||
id=1, | ||
remote_id=11, | ||
name="test_proj1", | ||
owner="john_doe1", | ||
url="https://github.co m/john_doe1/test_proj1", | ||
provider="github", | ||
) | ||
repository_dict = {"id": repository.remote_id, "provider": repository.provider} | ||
|
||
service_component = """ | ||
- apiVersion: v1alpha1 | ||
kind_: component | ||
metadata: | ||
name: base | ||
owner: platform | ||
group: | ||
product_owner: john | ||
project_owner: doe | ||
maintainers: [] | ||
description: This is my fancy component | ||
tags: [] | ||
links: | ||
- name: Datadog | ||
url: https://dashboard.datadog.com | ||
icon: poop | ||
- name: Sentry | ||
url: https://sentry.skypicker.com | ||
spec: | ||
type_: service | ||
environments: | ||
- name: production | ||
dashboard_url: https://dashboard.datadog.com | ||
health_check_url: https://dashboard.datadog.com | ||
service_urls: | ||
- https://service.prod.com | ||
- name: sandbox | ||
dashboard_url: https://dashboard.datadog.sandbox.com | ||
health_check_url: https://dashboard.datadog.sandbox.com | ||
service_urls: | ||
- https://service.sandbox.com | ||
impact: profit | ||
integrations: | ||
pagerduty_service: pagerduty_service1234 | ||
sentry_project: sentry project 15234 | ||
lifecycle: production | ||
""" | ||
|
||
mocker.patch( | ||
"zoo.repos.tasks.get_entity_file_content", return_value=service_component | ||
) | ||
uut.update_project_from_entity_file(proj=repository_dict) | ||
component_entity = Entity.objects.first() | ||
assert Entity.objects.all().count() == 1 | ||
assert Service.objects.all().count() == 1 | ||
assert component_entity.kind == "component" | ||
assert component_entity.name == "base" | ||
assert component_entity.owner == "platform" | ||
assert component_entity.library is None | ||
assert component_entity.type == "service" | ||
assert component_entity.links.all().count() == 2 | ||
assert component_entity.group | ||
assert component_entity.service is not None | ||
assert component_entity.service.environments.all().count() == 2 | ||
|
||
|
||
def test_create_base_component_and_library(mocker, repository_factory): | ||
repository = repository_factory( | ||
id=1, | ||
remote_id=11, | ||
name="test_proj1", | ||
owner="john_doe1", | ||
url="https://github.co m/john_doe1/test_proj1", | ||
provider="github", | ||
) | ||
repository_dict = {"id": repository.remote_id, "provider": repository.provider} | ||
|
||
library_component = """ | ||
- apiVersion: v1alpha1 | ||
kind_: component | ||
metadata: | ||
name: base_lib | ||
owner: platform | ||
group: | ||
product_owner: john | ||
project_owner: doe | ||
maintainers: [] | ||
description: This is my fancy component | ||
tags: [] | ||
links: | ||
- name: Datadog | ||
url: https://dashboard.datadog.com | ||
icon: poop | ||
- name: Sentry | ||
url: https://sentry.skypicker.com | ||
spec: | ||
type_: library | ||
impact: profit | ||
integrations: | ||
sonarqube_project: sonarqube | ||
lifecycle: production | ||
""" | ||
|
||
mocker.patch( | ||
"zoo.repos.tasks.get_entity_file_content", return_value=library_component | ||
) | ||
uut.update_project_from_entity_file(proj=repository_dict) | ||
component_entity = Entity.objects.first() | ||
assert Entity.objects.all().count() == 1 | ||
assert Library.objects.all().count() == 1 | ||
assert component_entity.kind == "component" | ||
assert component_entity.name == "base_lib" | ||
assert component_entity.owner == "platform" | ||
assert component_entity.type == "library" | ||
assert component_entity.links.all().count() == 2 | ||
assert component_entity.group | ||
assert component_entity.service is None | ||
assert component_entity.library is not None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 2.2.19 on 2021-07-08 11:54 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("entities", "0002_auto_20210706_1033"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="link", | ||
name="entity", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="links", | ||
related_query_name="link", | ||
to="entities.Entity", | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.