Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Feb 1, 2024
1 parent 376dfe7 commit 0c9978d
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 60 deletions.
10 changes: 5 additions & 5 deletions tests/integration_tests/strategy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def reset_tag(self, tag):
"load_unicode_dashboard_with_slice", "load_birth_names_dashboard_with_slices"
)
def test_dashboard_tags_strategy(self):
tag1 = get_tag("tag1", db.session, TagType.custom)
tag1 = get_tag("tag1", db.session, TagType.CUSTOM)
# delete first to make test idempotent
self.reset_tag(tag1)

Expand All @@ -103,19 +103,19 @@ def test_dashboard_tags_strategy(self):
self.assertEqual(result, expected)

# tag dashboard 'births' with `tag1`
tag1 = get_tag("tag1", db.session, TagType.custom)
tag1 = get_tag("tag1", db.session, TagType.CUSTOM)
dash = self.get_dash_by_slug("births")
tag1_urls = [{"chart_id": chart.id} for chart in dash.slices]
tagged_object = TaggedObject(
tag_id=tag1.id, object_id=dash.id, object_type=ObjectType.dashboard
tag_id=tag1.id, object_id=dash.id, object_type=ObjectType.DASHBOARD
)
db.session.add(tagged_object)
db.session.commit()

self.assertCountEqual(strategy.get_payloads(), tag1_urls)

strategy = DashboardTagsStrategy(["tag2"])
tag2 = get_tag("tag2", db.session, TagType.custom)
tag2 = get_tag("tag2", db.session, TagType.CUSTOM)
self.reset_tag(tag2)

result = strategy.get_payloads()
Expand All @@ -128,7 +128,7 @@ def test_dashboard_tags_strategy(self):
tag2_urls = [{"chart_id": chart.id}]
object_id = chart.id
tagged_object = TaggedObject(
tag_id=tag2.id, object_id=object_id, object_type=ObjectType.chart
tag_id=tag2.id, object_id=object_id, object_type=ObjectType.CHART
)
db.session.add(tagged_object)
db.session.commit()
Expand Down
16 changes: 8 additions & 8 deletions tests/integration_tests/tagging_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_dataset_tagging(self):
# Test to make sure that a dataset tag was added to the tagged_object table
tags = self.query_tagged_object_table()
self.assertEqual(1, len(tags))
self.assertEqual("ObjectType.dataset", str(tags[0].object_type))
self.assertEqual("ObjectType.DATASET", str(tags[0].object_type))
self.assertEqual(test_dataset.id, tags[0].object_id)

# Cleanup the db
Expand Down Expand Up @@ -108,7 +108,7 @@ def test_chart_tagging(self):
# Test to make sure that a chart tag was added to the tagged_object table
tags = self.query_tagged_object_table()
self.assertEqual(1, len(tags))
self.assertEqual("ObjectType.chart", str(tags[0].object_type))
self.assertEqual("ObjectType.CHART", str(tags[0].object_type))
self.assertEqual(test_chart.id, tags[0].object_id)

# Cleanup the db
Expand Down Expand Up @@ -144,7 +144,7 @@ def test_dashboard_tagging(self):
# Test to make sure that a dashboard tag was added to the tagged_object table
tags = self.query_tagged_object_table()
self.assertEqual(1, len(tags))
self.assertEqual("ObjectType.dashboard", str(tags[0].object_type))
self.assertEqual("ObjectType.DASHBOARD", str(tags[0].object_type))
self.assertEqual(test_dashboard.id, tags[0].object_id)

# Cleanup the db
Expand Down Expand Up @@ -178,14 +178,14 @@ def test_saved_query_tagging(self):

self.assertEqual(2, len(tags))

self.assertEqual("ObjectType.query", str(tags[0].object_type))
self.assertEqual("ObjectType.QUERY", str(tags[0].object_type))
self.assertEqual("owner:None", str(tags[0].tag.name))
self.assertEqual("TagType.owner", str(tags[0].tag.type))
self.assertEqual("TagType.OWNER", str(tags[0].tag.type))
self.assertEqual(test_saved_query.id, tags[0].object_id)

self.assertEqual("ObjectType.query", str(tags[1].object_type))
self.assertEqual("ObjectType.QUERY", str(tags[1].object_type))
self.assertEqual("type:query", str(tags[1].tag.name))
self.assertEqual("TagType.type", str(tags[1].tag.type))
self.assertEqual("TagType.TYPE", str(tags[1].tag.type))
self.assertEqual(test_saved_query.id, tags[1].object_id)

# Cleanup the db
Expand Down Expand Up @@ -217,7 +217,7 @@ def test_favorite_tagging(self):
# Test to make sure that a favorited object tag was added to the tagged_object table
tags = self.query_tagged_object_table()
self.assertEqual(1, len(tags))
self.assertEqual("ObjectType.chart", str(tags[0].object_type))
self.assertEqual("ObjectType.CHART", str(tags[0].object_type))
self.assertEqual(test_saved_query.obj_id, tags[0].object_id)

# Cleanup the db
Expand Down
22 changes: 11 additions & 11 deletions tests/integration_tests/tags/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def test_get_tag(self):
"created_by": None,
"id": tag.id,
"name": "test get tag",
"type": TagType.custom.value,
"type": TagType.CUSTOM.value,
}
data = json.loads(rv.data.decode("utf-8"))
for key, value in expected_result.items():
Expand Down Expand Up @@ -241,7 +241,7 @@ def test_add_tagged_objects(self):
.first()
)
dashboard_id = dashboard.id
dashboard_type = ObjectType.dashboard.value
dashboard_type = ObjectType.DASHBOARD.value
uri = f"api/v1/tag/{dashboard_type}/{dashboard_id}/"
example_tag_names = ["example_tag_1", "example_tag_2"]
data = {"properties": {"tags": example_tag_names}}
Expand All @@ -256,7 +256,7 @@ def test_add_tagged_objects(self):
tagged_objects = db.session.query(TaggedObject).filter(
TaggedObject.tag_id.in_(tag_ids),
TaggedObject.object_id == dashboard_id,
TaggedObject.object_type == ObjectType.dashboard,
TaggedObject.object_type == ObjectType.DASHBOARD,
)
assert tagged_objects.count() == 2
# clean up tags and tagged objects
Expand All @@ -274,7 +274,7 @@ def test_add_tagged_objects(self):
def test_delete_tagged_objects(self):
self.login(username="admin")
dashboard_id = 1
dashboard_type = ObjectType.dashboard
dashboard_type = ObjectType.DASHBOARD
tag_names = ["example_tag_1", "example_tag_2"]
tags = db.session.query(Tag).filter(Tag.name.in_(tag_names))
assert tags.count() == 2
Expand Down Expand Up @@ -344,7 +344,7 @@ def test_get_objects_by_tag(self):
.first()
)
dashboard_id = dashboard.id
dashboard_type = ObjectType.dashboard
dashboard_type = ObjectType.DASHBOARD
tag_names = ["example_tag_1", "example_tag_2"]
tags = db.session.query(Tag).filter(Tag.name.in_(tag_names))
for tag in tags:
Expand Down Expand Up @@ -380,7 +380,7 @@ def test_get_all_objects(self):
.first()
)
dashboard_id = dashboard.id
dashboard_type = ObjectType.dashboard
dashboard_type = ObjectType.DASHBOARD
tag_names = ["example_tag_1", "example_tag_2"]
tags = db.session.query(Tag).filter(Tag.name.in_(tag_names))
for tag in tags:
Expand Down Expand Up @@ -529,7 +529,7 @@ def test_post_tag(self):
user_id = self.get_user(username="admin").get_id()
tag = (
db.session.query(Tag)
.filter(Tag.name == "my_tag", Tag.type == TagType.custom)
.filter(Tag.name == "my_tag", Tag.type == TagType.CUSTOM)
.one_or_none()
)
assert tag is not None
Expand Down Expand Up @@ -628,8 +628,8 @@ def test_post_bulk_tag(self):
.join(Tag)
.filter(
TaggedObject.object_id == dashboard.id,
TaggedObject.object_type == ObjectType.dashboard,
Tag.type == TagType.custom,
TaggedObject.object_type == ObjectType.DASHBOARD,
Tag.type == TagType.CUSTOM,
)
)
assert tagged_objects.count() == 2
Expand All @@ -639,8 +639,8 @@ def test_post_bulk_tag(self):
.join(Tag)
.filter(
TaggedObject.object_id == chart.id,
TaggedObject.object_type == ObjectType.chart,
Tag.type == TagType.custom,
TaggedObject.object_type == ObjectType.CHART,
Tag.type == TagType.CUSTOM,
)
)
assert tagged_objects.count() == 2
Expand Down
22 changes: 11 additions & 11 deletions tests/integration_tests/tags/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ def test_create_custom_tag_command(self):
example_dashboard = (
db.session.query(Dashboard).filter_by(slug="world_health").one()
)
example_tags = {"create custom tag example 1", "create custom tag example 2"}
example_tags = ["create custom tag example 1", "create custom tag example 2"]
command = CreateCustomTagCommand(
ObjectType.dashboard.value, example_dashboard.id, example_tags
ObjectType.DASHBOARD.value, example_dashboard.id, example_tags
)
command.run()

Expand All @@ -74,7 +74,7 @@ def test_create_custom_tag_command(self):
.join(TaggedObject)
.filter(
TaggedObject.object_id == example_dashboard.id,
Tag.type == TagType.custom,
Tag.type == TagType.CUSTOM,
)
.all()
)
Expand All @@ -99,9 +99,9 @@ def test_delete_tags_command(self):
.filter_by(dashboard_title="World Bank's Data")
.one()
)
example_tags = {"create custom tag example 1", "create custom tag example 2"}
example_tags = ["create custom tag example 1", "create custom tag example 2"]
command = CreateCustomTagCommand(
ObjectType.dashboard.value, example_dashboard.id, example_tags
ObjectType.DASHBOARD.value, example_dashboard.id, example_tags
)
command.run()

Expand All @@ -110,7 +110,7 @@ def test_delete_tags_command(self):
.join(TaggedObject)
.filter(
TaggedObject.object_id == example_dashboard.id,
Tag.type == TagType.custom,
Tag.type == TagType.CUSTOM,
)
.order_by(Tag.name)
.all()
Expand All @@ -132,9 +132,9 @@ def test_delete_tags_command(self):
example_dashboard = (
db.session.query(Dashboard).filter_by(slug="world_health").one()
)
example_tags = {"create custom tag example 1", "create custom tag example 2"}
example_tags = ["create custom tag example 1", "create custom tag example 2"]
command = CreateCustomTagCommand(
ObjectType.dashboard.value, example_dashboard.id, example_tags
ObjectType.DASHBOARD.value, example_dashboard.id, example_tags
)
command.run()

Expand All @@ -143,14 +143,14 @@ def test_delete_tags_command(self):
.join(Tag)
.filter(
TaggedObject.object_id == example_dashboard.id,
TaggedObject.object_type == ObjectType.dashboard.name,
TaggedObject.object_type == ObjectType.DASHBOARD.name,
Tag.name.in_(example_tags),
)
)
assert tagged_objects.count() == 2
# delete one of the tagged objects
command = DeleteTaggedObjectCommand(
object_type=ObjectType.dashboard.value,
object_type=ObjectType.DASHBOARD.value,
object_id=example_dashboard.id,
tag=list(example_tags)[0],
)
Expand All @@ -160,7 +160,7 @@ def test_delete_tags_command(self):
.join(Tag)
.filter(
TaggedObject.object_id == example_dashboard.id,
TaggedObject.object_type == ObjectType.dashboard.name,
TaggedObject.object_type == ObjectType.DASHBOARD.name,
Tag.name.in_(example_tags),
)
)
Expand Down
24 changes: 12 additions & 12 deletions tests/integration_tests/tags/dao_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def create_tagged_objects(self):
tagged_objects.append(
self.insert_tagged_object(
object_id=dashboard_id,
object_type=ObjectType.dashboard,
object_type=ObjectType.DASHBOARD,
tag_id=tag.id,
)
)
Expand All @@ -126,21 +126,21 @@ def create_tagged_objects(self):
def test_create_tagged_objects(self):
# test that a tag can be added if it has ':' in it
TagDAO.create_custom_tagged_objects(
object_type=ObjectType.dashboard.name,
object_type=ObjectType.DASHBOARD,
object_id=1,
tag_names=["valid:example tag 1"],
)

# test that a tag can be added if it has ',' in it
TagDAO.create_custom_tagged_objects(
object_type=ObjectType.dashboard.name,
object_type=ObjectType.DASHBOARD,
object_id=1,
tag_names=["example,tag,1"],
)

# test that a tag can be added if it has a valid name
TagDAO.create_custom_tagged_objects(
object_type=ObjectType.dashboard.name,
object_type=ObjectType.DASHBOARD,
object_id=1,
tag_names=["example tag 1"],
)
Expand All @@ -161,7 +161,7 @@ def test_get_objects_from_tag(self):
dashboard_id = dashboard.id
tag = db.session.query(Tag).filter_by(name="example_tag_1").one()
self.insert_tagged_object(
object_id=dashboard_id, object_type=ObjectType.dashboard, tag_id=tag.id
object_id=dashboard_id, object_type=ObjectType.DASHBOARD, tag_id=tag.id
)
# get objects
tagged_objects = TagDAO.get_tagged_objects_for_tags(
Expand All @@ -185,7 +185,7 @@ def test_get_objects_from_tag(self):
TaggedObject,
and_(
TaggedObject.object_id == Slice.id,
TaggedObject.object_type == ObjectType.chart,
TaggedObject.object_type == ObjectType.CHART,
),
)
.distinct(Slice.id)
Expand All @@ -197,7 +197,7 @@ def test_get_objects_from_tag(self):
TaggedObject,
and_(
TaggedObject.object_id == Dashboard.id,
TaggedObject.object_type == ObjectType.dashboard,
TaggedObject.object_type == ObjectType.DASHBOARD,
),
)
.distinct(Dashboard.id)
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_get_objects_from_tag_with_id(self):
tag_2 = db.session.query(Tag).filter_by(name="example_tag_2").one()
tag_ids = [tag_1.id, tag_2.id]
self.insert_tagged_object(
object_id=dashboard_id, object_type=ObjectType.dashboard, tag_id=tag_1.id
object_id=dashboard_id, object_type=ObjectType.DASHBOARD, tag_id=tag_1.id
)
# get objects
tagged_objects = TagDAO.get_tagged_objects_by_tag_id(tag_ids)
Expand All @@ -252,7 +252,7 @@ def test_get_objects_from_tag_with_id(self):
def test_find_tagged_object(self):
tag = db.session.query(Tag).filter(Tag.name == "example_tag_1").first()
tagged_object = TagDAO.find_tagged_object(
object_id=1, object_type=ObjectType.dashboard.name, tag_id=tag.id
object_id=1, object_type=ObjectType.DASHBOARD, tag_id=tag.id
)
assert tagged_object is not None

Expand Down Expand Up @@ -308,20 +308,20 @@ def test_delete_tagged_object(self):
.filter(
TaggedObject.tag_id == tag.id,
TaggedObject.object_id == 1,
TaggedObject.object_type == ObjectType.dashboard.name,
TaggedObject.object_type == ObjectType.DASHBOARD.name,
)
.first()
)
assert tagged_object is not None
TagDAO.delete_tagged_object(
object_type=ObjectType.dashboard.name, object_id=1, tag_name=tag.name
object_type=ObjectType.DASHBOARD, object_id=1, tag_name=tag.name
)
tagged_object = (
db.session.query(TaggedObject)
.filter(
TaggedObject.tag_id == tag.id,
TaggedObject.object_id == 1,
TaggedObject.object_type == ObjectType.dashboard.name,
TaggedObject.object_type == ObjectType.DASHBOARD.name,
)
.first()
)
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/dao/tag_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ def test_create_tag_relationship(mocker):

# Define a list of objects to tag
objects_to_tag = [
(ObjectType.query, 1),
(ObjectType.chart, 2),
(ObjectType.dashboard, 3),
(ObjectType.QUERY, 1),
(ObjectType.CHART, 2),
(ObjectType.DASHBOARD, 3),
]

# Call the function
Expand Down
Loading

0 comments on commit 0c9978d

Please sign in to comment.